import javax.swing.event.InternalFrameEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
-import javax.swing.text.JTextComponent;
/**
* This class provides the swing GUI layout for FTS Panel and implements most of
if (tabs != null
&& tabs.getSelectedComponent() == ftsPanel)
{
- txt_search.requestFocusInWindow();
+ txt_search.getComponent().requestFocusInWindow();
}
}
});
"label.separate_multiple_query_values", new Object[]
{ getCmbSearchTarget().getSelectedItem().toString() });
}
- txt_search.setToolTipText(
+ txt_search.getComponent().setToolTipText(
JvSwingUtils.wrapTooltip(true, tooltipText));
searchAction(true);
}
}
});
- txt_search.setFont(new java.awt.Font("Verdana", 0, 12));
+ txt_search.getComponent().setFont(new java.awt.Font("Verdana", 0, 12));
- txt_search.getEditor().getEditorComponent()
- .addKeyListener(new KeyAdapter()
+ txt_search.addKeyListener(new KeyAdapter()
{
@Override
public void keyPressed(KeyEvent e)
}
}
}, false);
- ((JTextComponent) txt_search.getEditor().getEditorComponent())
- .getDocument().addDocumentListener(listener);
+ txt_search.addDocumentListener(listener);
txt_search.addFocusListener(new FocusListener()
{
btn_ok.setEnabled(false);
btn_next_page.setEnabled(false);
btn_prev_page.setEnabled(false);
- txt_search.setEnabled(false);
+ txt_search.getComponent().setEnabled(false);
cmb_searchTarget.setEnabled(false);
previousWantedFields = getFTSRestClient()
.getAllDefaultDisplayedFTSDataColumns()
btn_back.setEnabled(true);
btn_cancel.setEnabled(true);
refreshPaginatorState();
- txt_search.setEnabled(true);
+ txt_search.getComponent().setEnabled(true);
cmb_searchTarget.setEnabled(true);
if (wantedFieldsUpdated())
{
pnl_results.add(tabbedPane);
pnl_inputs.add(cmb_searchTarget);
- pnl_inputs.add(txt_search);
+ pnl_inputs.add(txt_search.getComponent());
pnl_inputs.add(btn_autosearch);
pnl_inputs.add(lbl_loading);
pnl_inputs.add(lbl_warning);
return cmb_searchTarget;
}
- public JComboBox<String> getTxtSearch()
- {
- return txt_search;
- }
-
public JInternalFrame getMainFrame()
{
return mainFrame;
MessageManager.getString("label.search_filter")));
searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX");
- searchBox.setToolTipText(
+ searchBox.getComponent().setToolTipText(
MessageManager.getString("info.enter_search_text_here"));
- searchBox.getEditor().getEditorComponent()
- .addKeyListener(new java.awt.event.KeyAdapter()
+ searchBox.addKeyListener(new java.awt.event.KeyAdapter()
{
@Override
public void keyPressed(KeyEvent e)
}
}
});
- searchBox.getEditor().getEditorComponent()
- .addFocusListener(new FocusAdapter()
+ searchBox.addFocusListener(new FocusAdapter()
{
@Override
public void focusLost(FocusEvent e)
});
syncState();
- this.add(searchBox);
+ this.add(searchBox.getComponent());
this.add(displayName);
this.add(description);
}
Desktop.addInternalFrame(frame, MessageManager.getString("label.find"),
MY_WIDTH, MY_HEIGHT);
frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
- searchBox.requestFocus();
+ searchBox.getComponent().requestFocus();
}
/**
List<SequenceI> seqs = new ArrayList<SequenceI>();
List<SequenceFeature> features = new ArrayList<SequenceFeature>();
- String searchString = searchBox.getEditor().getItem().toString().trim();
+ String searchString = searchBox.getUserInput();
String desc = "Search Results";
/*
{
createFeatures.setEnabled(false);
- String searchString = searchBox.getUserInput().trim();
+ String searchString = searchBox.getUserInput();
if (isInvalidSearchString(searchString))
{
seqIndex = 0;
JvOptionPane.showInternalMessageDialog(this,
MessageManager.getString("label.finished_searching"), null,
- JvOptionPane.INFORMATION_MESSAGE);
+ JvOptionPane.PLAIN_MESSAGE);
}
else
{
resIndex = -1;
seqIndex = 0;
JvOptionPane.showInternalMessageDialog(this, message, null,
- JvOptionPane.INFORMATION_MESSAGE);
+ JvOptionPane.PLAIN_MESSAGE);
}
}
}
package jalview.io.cache;
import jalview.bin.Cache;
+import jalview.bin.Jalview;
import jalview.util.MessageManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.FocusListener;
+import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Set;
import javax.swing.JComboBox;
+import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
+import javax.swing.JTextField;
import javax.swing.SwingUtilities;
+import javax.swing.event.CaretListener;
+import javax.swing.event.DocumentListener;
+import javax.swing.text.JTextComponent;
-public class JvCacheableInputBox<E> extends JComboBox<String>
+/**
+ * A class that provides an editable combobox with a memory of previous entries
+ * that may be persisted
+ *
+ * @author tcofoegbu
+ *
+ * @param <E>
+ */
+/*
+ * (temporary?) patches to wrap a JTextField instead when running as Javascript
+ */
+public class JvCacheableInputBox<E>
{
+ private JComboBox<String> comboBox; // used for Jalview
- private static final long serialVersionUID = 5774610435079326695L;
+ private JTextField textField; // used for JalviewJS
- private static final int LEFT_BOARDER_WIDTH = 16;
+ private static final long serialVersionUID = 5774610435079326695L;
private String cacheKey;
return enterWasPressed;
}
+ /**
+ * Constructor
+ *
+ * @param newCacheKey
+ */
public JvCacheableInputBox(String newCacheKey)
{
super();
- this.cacheKey = newCacheKey;
- setEditable(true);
- addKeyListener(new KeyListener()
+ if (Jalview.isJS())
{
+ textField = new JTextField();
+ return;
+ }
+ this.cacheKey = newCacheKey;
+ comboBox = new JComboBox<String>();
+ comboBox.setEditable(true);
+ comboBox.addKeyListener(new KeyAdapter()
+ {
@Override
public void keyTyped(KeyEvent e)
{
}
// let event bubble up
}
-
- @Override
- public void keyReleased(KeyEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void keyPressed(KeyEvent e)
- {
- // TODO Auto-generated method stub
-
- }
});
- setPrototypeDisplayValue(
+ comboBox.setPrototypeDisplayValue(
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
appCache = AppCache.getInstance();
initCachePopupMenu();
});
popup.add(menuItemClearCache);
- setComponentPopupMenu(popup);
- add(popup);
+ comboBox.setComponentPopupMenu(popup);
+ comboBox.add(popup);
}
/**
*/
public void updateCache()
{
+ if (Jalview.isJS())
+ {
+ return;
+ }
SwingUtilities.invokeLater(new Runnable()
{
@Override
}
String lastSearch = userInput;
- if (getItemCount() > 0)
+ if (comboBox.getItemCount() > 0)
{
- removeAllItems();
+ comboBox.removeAllItems();
}
Set<String> cacheItems = appCache.getAllCachedItemsFor(cacheKey);
List<String> reversedCacheItems = new ArrayList<>();
Collections.reverse(reversedCacheItems);
if (lastSearch.isEmpty())
{
- addItem("");
+ comboBox.addItem("");
}
if (reversedCacheItems != null && !reversedCacheItems.isEmpty())
}
else
{
- addItem(cacheItem);
+ comboBox.addItem(cacheItem);
}
}
else
{
- addItem(cacheItem);
+ comboBox.addItem(cacheItem);
}
}
appCache.putCache(cacheKey, foundCache);
*/
public void persistCache()
{
- appCache.persistCache(cacheKey);
+ if (!Jalview.isJS())
+ {
+ appCache.persistCache(cacheKey);
+ }
}
/**
- * Method to obtain input text from the cache box
+ * Returns the trimmed text in the input field
*
* @return
*/
public String getUserInput()
{
- return getEditor().getItem() == null ? ""
- : getEditor().getItem().toString().trim();
+ if (Jalview.isJS())
+ {
+ return textField.getText().trim();
+ }
+ Object item = comboBox.getEditor().getItem();
+ return item == null ? "" : item.toString().trim();
+ }
+
+ public JComponent getComponent()
+ {
+ return Jalview.isJS() ? textField : comboBox;
+ }
+
+ public void addActionListener(ActionListener actionListener)
+ {
+ if (!Jalview.isJS())
+ {
+ comboBox.addActionListener(actionListener);
+ }
+ }
+
+ public void addDocumentListener(DocumentListener listener)
+ {
+ if (!Jalview.isJS())
+ {
+ ((JTextComponent) comboBox.getEditor().getEditorComponent())
+ .getDocument().addDocumentListener(listener);
+ }
+ }
+
+ public void addFocusListener(FocusListener focusListener)
+ {
+ if (!Jalview.isJS())
+ {
+ comboBox.addFocusListener(focusListener);
+ }
+ }
+
+ public void addKeyListener(KeyListener kl)
+ {
+ if (!Jalview.isJS())
+ {
+ comboBox.getEditor().getEditorComponent().addKeyListener(kl);
+ }
+ }
+
+ public void setEditable(boolean b)
+ {
+ if (!Jalview.isJS())
+ {
+ comboBox.setEditable(b);
+ }
+ }
+
+ public void setPrototypeDisplayValue(String string)
+ {
+ if (!Jalview.isJS())
+ {
+ comboBox.setPrototypeDisplayValue(string);
+ }
+ }
+
+ public void setSelectedItem(String userInput)
+ {
+ if (!Jalview.isJS())
+ {
+ comboBox.setSelectedItem(userInput);
+ }
+ }
+
+ public boolean isPopupVisible()
+ {
+ if (!Jalview.isJS())
+ {
+ return comboBox.isPopupVisible();
+ }
+ return false;
+ }
+
+ public void addCaretListener(CaretListener caretListener)
+ {
+ if (!Jalview.isJS())
+ {
+ ((JTextComponent) comboBox.getEditor().getEditorComponent())
+ .addCaretListener(caretListener);
+ }
}
}
import javax.swing.SwingUtilities;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
-import javax.swing.text.JTextComponent;
public class GFinder extends JPanel
{
createFeatures_actionPerformed();
}
});
- searchBox.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));
- ((JTextComponent) searchBox.getEditor().getEditorComponent())
- .addCaretListener(new CaretListener()
+ searchBox.getComponent()
+ .setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));
+ searchBox.addCaretListener(new CaretListener()
{
@Override
public void caretUpdate(CaretEvent e)
textfield_caretUpdate(e);
}
});
- searchBox.getEditor().getEditorComponent()
- .addKeyListener(new java.awt.event.KeyAdapter()
+ searchBox.addKeyListener(new java.awt.event.KeyAdapter()
{
@Override
public void keyPressed(KeyEvent e)
actionsPanel.add(createFeatures, null);
this.add(jLabelFind, java.awt.BorderLayout.WEST);
this.add(actionsPanel, java.awt.BorderLayout.EAST);
- this.add(jPanel2, java.awt.BorderLayout.SOUTH);
+ // this.add(jPanel2, java.awt.BorderLayout.SOUTH);
this.add(jPanel3, java.awt.BorderLayout.NORTH);
this.add(jPanel4, java.awt.BorderLayout.CENTER);
- jPanel4.add(searchBox, java.awt.BorderLayout.NORTH);
+ jPanel4.add(searchBox.getComponent(), java.awt.BorderLayout.NORTH);
JPanel optionsPanel = new JPanel();