List of usage examples for java.awt.event KeyAdapter KeyAdapter
KeyAdapter
From source file:com.petersoft.advancedswing.enhancedtextarea.EnhancedTextArea.java
private void initGUI() { try {/* w w w . j a v a 2 s.com*/ BorderLayout thisLayout = new BorderLayout(); this.setLayout(thisLayout); this.setPreferredSize(new java.awt.Dimension(725, 290)); { jToolBar = new JToolBar(); this.add(jToolBar, BorderLayout.NORTH); { jSaveButton = new JButton(); jToolBar.add(jSaveButton); jSaveButton.setText("Save"); jSaveButton.setIcon(new ImageIcon(getClass().getClassLoader() .getResource("com/petersoft/advancedswing/enhancedtextarea/disk.png"))); jSaveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jSaveButtonActionPerformed(evt); } }); } { jLineWrapButton = new JToggleButton(); jToolBar.add(jLineWrapButton); jLineWrapButton.setText("Wrap"); jLineWrapButton.setIcon(new ImageIcon(getClass().getClassLoader() .getResource("com/petersoft/advancedswing/enhancedtextarea/linewrap.png"))); jLineWrapButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jLineWrapButtonActionPerformed(evt); } }); } { jFontBiggerButton = new JButton(); jToolBar.add(jFontBiggerButton); jFontBiggerButton.setIcon(new ImageIcon(getClass().getClassLoader() .getResource("com/petersoft/advancedswing/enhancedtextarea/font_add.png"))); jFontBiggerButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jFontBiggerButtonActionPerformed(evt); } }); } { jFontSmallerButton = new JButton(); jToolBar.add(jFontSmallerButton); jFontSmallerButton.setIcon(new ImageIcon(getClass().getClassLoader() .getResource("com/petersoft/advancedswing/enhancedtextarea/font_delete.png"))); jFontSmallerButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jFontSmallerButtonActionPerformed(evt); } }); } { jLabel1 = new JLabel(); jToolBar.add(jLabel1); jLabel1.setText(" "); } { jSearchTextField = new JSearchTextField(); jToolBar.add(jSearchTextField); jSearchTextField.setMaximumSize(new java.awt.Dimension(100, 22)); jSearchTextField.setPreferredSize(new java.awt.Dimension(100, 22)); jSearchTextField.setSize(new java.awt.Dimension(100, 22)); jSearchTextField.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent evt) { jSearchTextFieldKeyReleased(evt); } }); } { jSeparatorLabel = new JLabel(); jToolBar.add(jSeparatorLabel); jSeparatorLabel.setText(" "); } { GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fonts = e.getAllFonts(); String fontNames[] = new String[fonts.length]; int x = 0; for (Font f : fonts) { fontNames[x++] = f.getFontName(); } ComboBoxModel jFontComboBoxModel = new DefaultComboBoxModel(fontNames); jFontComboBox = new JComboBox(); jToolBar.add(jFontComboBox); jFontComboBox.setModel(jFontComboBoxModel); jFontComboBox.setMaximumSize(new java.awt.Dimension(180, 22)); jFontComboBox.setPreferredSize(new java.awt.Dimension(180, 22)); jFontComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jFontComboBoxActionPerformed(evt); } }); } { pager = new Pager(); jToolBar.add(pager); pager.setVisible(false); } } { jScrollPane1 = new JScrollPane(); this.add(jScrollPane1, BorderLayout.CENTER); { jTextArea = new JTextArea(); jTextArea.getDocument().addDocumentListener(this); lines = new JTextArea(" 1 "); lines.setBackground(new Color(200, 230, 245)); lines.setEditable(false); jScrollPane1.setRowHeaderView(lines); jTextArea.getDocument().addDocumentListener(new DocumentListener() { public String getText() { int caretPosition = jTextArea.getDocument().getLength(); Element root = jTextArea.getDocument().getDefaultRootElement(); int base = 0; if (separateByLine == false) { if (str != null) { base = StringUtils.countMatches( str.substring(0, (pager.getPage() - 1) * pageSize), System.getProperty("line.separator")); if (base == 1) { base = 0; } } } else { base = (pager.getPage() - 1) * pageSize; } base += lineNoBase; String text = " " + (base + 1) + " " + System.getProperty("line.separator"); for (int i = 2; i < root.getElementIndex(caretPosition) + 2; i++) { text += " " + (base + i) + " " + System.getProperty("line.separator"); } return text; } @Override public void changedUpdate(DocumentEvent de) { lines.setText(getText()); } @Override public void insertUpdate(DocumentEvent de) { lines.setText(getText()); } @Override public void removeUpdate(DocumentEvent de) { lines.setText(getText()); } }); jScrollPane1.setViewportView(jTextArea); } } { jStatusPanel = new JPanel(); FlowLayout jStatusPanelLayout = new FlowLayout(); jStatusPanelLayout.setAlignment(FlowLayout.LEFT); jStatusPanel.setLayout(jStatusPanelLayout); this.add(jStatusPanel, BorderLayout.SOUTH); { jStatusLabel = new JLabel(); jStatusPanel.add(jStatusLabel); } { jSearchLabel = new JLabel(); jStatusPanel.add(jSearchLabel); } } this.jFontComboBox.setSelectedItem(jTextArea.getFont().getFamily() + ".plain"); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.tbuchloh.kiskis.gui.widgets.PasswordElement.java
private void init() { this.setLayout(new BorderLayout()); final JPanel main = new JPanel(new BorderLayout()); main.add(_pwdField, BorderLayout.CENTER); main.add(_progressBar, BorderLayout.SOUTH); this.add(main, BorderLayout.CENTER); _buttonPanel = new JPanel(new GridLayout(2, 1)); _buttonPanel.add(_pwdButton);//w w w. j ava2 s . c o m _buttonPanel.add(_testButton); this.add(_buttonPanel, BorderLayout.EAST); _pwdField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { notifyListeners(); } }); _pwdField.setColumns(50); updatePwdButton(HIDDEN); updatePwdField(); }
From source file:burp.BurpExtender.java
private JPanel createMainPanel() { JPanel main = new JPanel(); main.setLayout(new GridBagLayout()); // Create Settings Panel JPanel settings = new JPanel(new GridBagLayout()); createTitle("Settings", settings); KeyListener projectEnter = new KeyAdapter() { @Override//from w w w.j a va2 s.c om public void keyPressed(KeyEvent k) { if (k.getKeyCode() == KeyEvent.VK_ENTER) updateProjects(); } }; serverUrl = labelTextField("Server URL: ", settings, callbacks.loadExtensionSetting(BurpExtender.SERVER_KEY)); serverUrl.addKeyListener(projectEnter); serverUrl.addFocusListener(new JTextFieldSettingFocusListener(BurpExtender.SERVER_KEY, callbacks)); apiKey = labelTextField("API Key: ", settings, callbacks.loadExtensionSetting(BurpExtender.API_KEY)); apiKey.addKeyListener(projectEnter); apiKey.addFocusListener(new JTextFieldSettingFocusListener(BurpExtender.API_KEY, callbacks)); JButton targetRefresh = new JButton(); targetRefresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateTargets(); } }); targetUrl = createComboBox("Target URL: ", settings, 3, targetRefresh); projectRefresh = new JButton(); projectRefresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Thread updateThread = new Thread() { public void run() { NameValuePair selected = getProject(); if (selected != null) callbacks.saveExtensionSetting(BurpExtender.PROJECT_KEY, selected.getValue()); updateProjects(); } }; updateThread.start(); } }); projectBox = createComboBox("Projects: ", settings, 4, projectRefresh); GridBagConstraints setGBC = new GridBagConstraints(); setGBC.gridy = 3; setGBC.anchor = GridBagConstraints.NORTHWEST; main.add(settings, setGBC); // Separator Insets ins = new Insets(10, 10, 2, 10); JSeparator sep = new JSeparator(JSeparator.HORIZONTAL); callbacks.customizeUiComponent(sep); GridBagConstraints sepGBC = new GridBagConstraints(); sepGBC.gridwidth = 3; sepGBC.gridx = 0; sepGBC.fill = GridBagConstraints.HORIZONTAL; sepGBC.insets = ins; main.add(sep, sepGBC); // Create Export Button JButton exportBtn = new JButton(); exportBtn.setText("Send to Code Dx"); exportBtn.addActionListener(new ExportActionListener(this, callbacks)); callbacks.customizeUiComponent(exportBtn); GridBagConstraints btnGBC = new GridBagConstraints(); btnGBC.gridx = 0; btnGBC.weightx = 1.0; btnGBC.weighty = 1.0; btnGBC.insets = ins; btnGBC.anchor = GridBagConstraints.NORTHWEST; main.add(exportBtn, btnGBC); updateTargets(); return main; }
From source file:net.sf.vfsjfilechooser.accessories.connection.ConnectionDialog.java
private void initListeners() { this.portTextField.addKeyListener(new KeyAdapter() { @Override/*from ww w . j av a 2s. c o m*/ public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))) { getToolkit().beep(); e.consume(); } else { setPortTextFieldDirty(true); } } }); this.portTextField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { JFormattedTextField f = (JFormattedTextField) e.getSource(); String text = f.getText(); if (text.length() == 0) { f.setValue(null); } try { f.commitEdit(); } catch (ParseException exc) { } } }); this.cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (currentWorker != null) { if (currentWorker.isAlive()) { currentWorker.interrupt(); setCursor(Cursor.getDefaultCursor()); } } setVisible(false); } }); this.connectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { currentWorker = new Thread() { @Override public void run() { StringBuilder error = new StringBuilder(); FileObject fo = null; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { String m_username = usernameTextField.getText(); String m_defaultRemotePath = defaultRemotePathTextField.getText(); char[] m_password = passwordTextField.getPassword(); String m_hostname = hostnameTextField.getText(); String m_protocol = protocolList.getSelectedItem().toString(); int m_port = -1; if (portTextField.isEditValid() && (portTextField.getValue() != null)) { String s = portTextField.getValue().toString(); m_port = Integer.valueOf(s); } Builder credentialsBuilder = Credentials.newBuilder(m_hostname) .defaultRemotePath(m_defaultRemotePath).username(m_username) .password(m_password).protocol(m_protocol).port(m_port); Credentials credentials = credentialsBuilder.build(); String uri = credentials.toFileObjectURL(); if (isInterrupted()) { setPortTextFieldDirty(false); return; } fo = VFSUtils.resolveFileObject(uri); if ((fo != null) && !fo.exists()) { fo = null; } } catch (Exception err) { error.append(err.getMessage()); setCursor(Cursor.getDefaultCursor()); } if ((error.length() > 0) || (fo == null)) { error.delete(0, error.length()); error.append("Failed to connect!"); error.append("\n"); error.append("Please check parameters and try again."); JOptionPane.showMessageDialog(ConnectionDialog.this, error, "Error", JOptionPane.ERROR_MESSAGE); setCursor(Cursor.getDefaultCursor()); return; } if (isInterrupted()) { return; } fileChooser.setCurrentDirectory(fo); setCursor(Cursor.getDefaultCursor()); resetFields(); if (bookmarksDialog != null) { String bTitle = fo.getName().getBaseName(); if (bTitle.trim().equals("")) { bTitle = fo.getName().toString(); } String bURL = fo.getName().getURI(); bookmarksDialog.getBookmarks().add(new TitledURLEntry(bTitle, bURL)); bookmarksDialog.getBookmarks().save(); } setVisible(false); } }; currentWorker.setPriority(Thread.MIN_PRIORITY); currentWorker.start(); } }); // add the usual right click popup menu(copy, paste, etc.) PopupHandler.installDefaultMouseListener(hostnameTextField); PopupHandler.installDefaultMouseListener(portTextField); PopupHandler.installDefaultMouseListener(usernameTextField); PopupHandler.installDefaultMouseListener(passwordTextField); PopupHandler.installDefaultMouseListener(defaultRemotePathTextField); this.protocolList.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { selectPortNumber(); } } }); this.protocolList.setSelectedItem(Protocol.FTP); }
From source file:com.googlecode.vfsjfilechooser2.accessories.connection.ConnectionDialog.java
private void initListeners() { this.portTextField.addKeyListener(new KeyAdapter() { @Override/* w w w . j av a 2 s . co m*/ public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))) { getToolkit().beep(); e.consume(); } else { setPortTextFieldDirty(true); } } }); this.portTextField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { JFormattedTextField f = (JFormattedTextField) e.getSource(); String text = f.getText(); if (text.length() == 0) { f.setValue(null); } try { f.commitEdit(); } catch (ParseException exc) { } } }); this.cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (currentWorker != null) { if (currentWorker.isAlive()) { currentWorker.interrupt(); setCursor(Cursor.getDefaultCursor()); } } setVisible(false); } }); this.connectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { currentWorker = new Thread() { @Override public void run() { StringBuilder error = new StringBuilder(); FileObject fo = null; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { String m_username = usernameTextField.getText(); String m_defaultRemotePath = defaultRemotePathTextField.getText(); char[] m_password = passwordTextField.getPassword(); String m_hostname = hostnameTextField.getText(); String m_protocol = protocolList.getSelectedItem().toString(); int m_port = -1; if (portTextField.isEditValid() && (portTextField.getValue() != null)) { String s = portTextField.getValue().toString(); m_port = Integer.valueOf(s); } Builder credentialsBuilder = Credentials.newBuilder(m_hostname) .defaultRemotePath(m_defaultRemotePath).username(m_username) .password(m_password).protocol(m_protocol).port(m_port); Credentials credentials = credentialsBuilder.build(); String uri = credentials.toFileObjectURL(); if (isInterrupted()) { setPortTextFieldDirty(false); return; } fo = VFSUtils.resolveFileObject(uri); if ((fo != null) && !fo.exists()) { fo = null; } } catch (Exception err) { error.append(err.getMessage()); setCursor(Cursor.getDefaultCursor()); } if ((error.length() > 0) || (fo == null)) { error.delete(0, error.length()); error.append("Failed to connect!"); error.append("\n"); error.append("Please check parameters and try again."); JOptionPane.showMessageDialog(ConnectionDialog.this, error, "Error", JOptionPane.ERROR_MESSAGE); setCursor(Cursor.getDefaultCursor()); return; } if (isInterrupted()) { return; } fileChooser.setCurrentDirectoryObject(fo); setCursor(Cursor.getDefaultCursor()); resetFields(); if (bookmarksDialog != null) { String bTitle = fo.getName().getBaseName(); if (bTitle.trim().equals("")) { bTitle = fo.getName().toString(); } String bURL = fo.getName().getURI(); bookmarksDialog.getBookmarks().add(new TitledURLEntry(bTitle, bURL)); bookmarksDialog.getBookmarks().save(); } setVisible(false); } }; currentWorker.setPriority(Thread.MIN_PRIORITY); currentWorker.start(); } }); // add the usual right click popup menu(copy, paste, etc.) PopupHandler.installDefaultMouseListener(hostnameTextField); PopupHandler.installDefaultMouseListener(portTextField); PopupHandler.installDefaultMouseListener(usernameTextField); PopupHandler.installDefaultMouseListener(passwordTextField); PopupHandler.installDefaultMouseListener(defaultRemotePathTextField); this.protocolList.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { selectPortNumber(); } } }); this.protocolList.setSelectedItem(Protocol.FTP); }
From source file:de.wusel.partyplayer.gui.PartyPlayer.java
private JComponent createMainComponent() { JPanel mainPanel = new JPanel(new MigLayout("fill", "[][50%][][50%]", "[] [] [] [] [grow]")); mainPanel.add(new JLabel(getText("layout.current.title"))); mainPanel.add(new JSeparator(), "growx"); mainPanel.add(new JLabel(getText("layout.next.title"))); mainPanel.add(new JSeparator(), "growx, wrap"); mainPanel.add(createPlayerPanel(), "grow, span 2"); mainPanel.add(createPlayListPanel(), "grow, hmax 100, span 2, wrap"); mainPanel.add(new JLabel(getText("layout.available.title"))); mainPanel.add(new JSeparator(), "growx, span, wrap"); final JTextField searchField = new JTextField(); searchField.addKeyListener(new KeyAdapter() { @Override/*from ww w . j a v a2 s. c o m*/ public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { searchField.setText(null); table.setRowFilter(null); } try { table.setRowFilter( RowFilter.regexFilter("(?i)" + Pattern.quote(searchField.getText()), 0, 1, 3)); } catch (PatternSyntaxException ex) { table.setRowFilter(null); //do nothing } } }); mainPanel.add(new JLabel(getText("layout.search.label"))); mainPanel.add(searchField, "span, growx, wrap"); mainPanel.add(createSongPanel(), "span, grow"); return mainPanel; }
From source file:org.ut.biolab.medsavant.client.ontology.OntologyWizard.java
private AbstractWizardPage getSourcePage() { return new DefaultWizardPage(PAGENAME_SOURCE) { {//from w w w . jav a 2s . c o m KeyListener listener = new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (StringUtils.isNotEmpty(oboField.getText()) && StringUtils.isNotEmpty(mappingField.getText())) { fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } else { fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT); } } }; addText("URL for the OBO file containing the ontology data:"); addComponent(oboField); oboField.addKeyListener(listener); addText("URL for the file definining the mapping between genes\nand ontology terms:"); addComponent(mappingField); mappingField.addKeyListener(listener); } @Override public void setupWizardButtons() { fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH); fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.NEXT); fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } }; }
From source file:net.pms.encoders.AviSynthMEncoder.java
@Override public JComponent config() { FormLayout layout = new FormLayout("left:pref, 0:grow", "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 12dlu, p, 3dlu, 0:grow"); PanelBuilder builder = new PanelBuilder(layout); builder.border(Borders.EMPTY);//from w w w .j a v a2 s . c o m builder.opaque(false); CellConstraints cc = new CellConstraints(); JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), cc.xyw(2, 1, 1)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); multithreading = new JCheckBox(Messages.getString("MEncoderVideo.35"), configuration.getAvisynthMultiThreading()); multithreading.setContentAreaFilled(false); multithreading.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setAvisynthMultiThreading((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(GuiUtil.getPreferredSizeComponent(multithreading), cc.xy(2, 3)); interframe = new JCheckBox(Messages.getString("AviSynthMEncoder.13"), configuration.getAvisynthInterFrame()); interframe.setContentAreaFilled(false); interframe.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { configuration.setAvisynthInterFrame(interframe.isSelected()); if (configuration.getAvisynthInterFrame()) { JOptionPane.showMessageDialog( SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), Messages.getString("AviSynthMEncoder.16"), Messages.getString("Dialog.Information"), JOptionPane.INFORMATION_MESSAGE); } } }); builder.add(GuiUtil.getPreferredSizeComponent(interframe), cc.xy(2, 5)); interframegpu = new JCheckBox(Messages.getString("AviSynthMEncoder.15"), configuration.getAvisynthInterFrameGPU()); interframegpu.setContentAreaFilled(false); interframegpu.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setAvisynthInterFrameGPU((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(GuiUtil.getPreferredSizeComponent(interframegpu), cc.xy(2, 7)); convertfps = new JCheckBox(Messages.getString("AviSynthMEncoder.3"), configuration.getAvisynthConvertFps()); convertfps.setContentAreaFilled(false); convertfps.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setAvisynthConvertFps((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(GuiUtil.getPreferredSizeComponent(convertfps), cc.xy(2, 9)); String aviSynthScriptInstructions = Messages.getString("AviSynthMEncoder.4") + Messages.getString("AviSynthMEncoder.5") + Messages.getString("AviSynthMEncoder.6") + Messages.getString("AviSynthMEncoder.7") + Messages.getString("AviSynthMEncoder.8"); JTextArea aviSynthScriptInstructionsContainer = new JTextArea(aviSynthScriptInstructions); aviSynthScriptInstructionsContainer.setEditable(false); aviSynthScriptInstructionsContainer.setBorder(BorderFactory.createEtchedBorder()); aviSynthScriptInstructionsContainer.setBackground(new Color(255, 255, 192)); aviSynthScriptInstructionsContainer.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(new Color(130, 135, 144)), BorderFactory.createEmptyBorder(3, 5, 3, 5))); builder.add(aviSynthScriptInstructionsContainer, cc.xy(2, 11)); String clip = configuration.getAvisynthScript(); if (clip == null) { clip = ""; } StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(clip, PMS.AVS_SEPARATOR); int i = 0; while (st.hasMoreTokens()) { if (i > 0) { sb.append("\n"); } sb.append(st.nextToken()); i++; } textArea = new JTextArea(sb.toString()); textArea.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(textArea.getText(), "\n"); int i = 0; while (st.hasMoreTokens()) { if (i > 0) { sb.append(PMS.AVS_SEPARATOR); } sb.append(st.nextToken()); i++; } configuration.setAvisynthScript(sb.toString()); } }); JScrollPane pane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); pane.setPreferredSize(new Dimension(500, 350)); builder.add(pane, cc.xy(2, 13)); configuration.addConfigurationListener(new ConfigurationListener() { @Override public void configurationChanged(ConfigurationEvent event) { if (event.getPropertyName() == null) { return; } if ((!event.isBeforeUpdate()) && event.getPropertyName().equals(PmsConfiguration.KEY_GPU_ACCELERATION)) { interframegpu.setEnabled(configuration.isGPUAcceleration()); } } }); return builder.getPanel(); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopSuggestionField.java
public DesktopSuggestionField() { composition = new JPanel(); composition.setLayout(new BorderLayout()); composition.setFocusable(false);//from w w w .j ava 2 s. c om comboBox = new SearchComboBox() { @Override public void setPopupVisible(boolean v) { if (!items.isEmpty()) { super.setPopupVisible(v); } else if (!v) { super.setPopupVisible(false); } } @Override public void actionPerformed(ActionEvent e) { if (SearchAutoCompleteSupport.SEARCH_ENTER_COMMAND.equals(e.getActionCommand())) { enterHandling = true; } super.actionPerformed(e); } }; comboBox.addActionListener(e -> { if (settingValue || disableActionListener) { return; } if ("comboBoxEdited".equals(e.getActionCommand())) { Object selectedItem = comboBox.getSelectedItem(); if (popupItemSelectionHandling) { if (selectedItem instanceof ValueWrapper) { Object selectedValue = ((ValueWrapper) selectedItem).getValue(); setValue(selectedValue); } } else if (enterHandling) { if (selectedItem instanceof String) { boolean found = false; String newFilter = (String) selectedItem; if (prevValue != null) { if (Objects.equals(getDisplayString(prevValue), newFilter)) { found = true; } } final boolean searchStringEqualsToCurrentValue = found; // we need to do it later // unable to change current text from ActionListener SwingUtilities.invokeLater(() -> { updateComponent(prevValue); if (!searchStringEqualsToCurrentValue) { handleOnEnterAction(((String) selectedItem)); } }); } else if (currentSearchComponentText != null) { // Disable variants after select final String enterActionString = currentSearchComponentText; SwingUtilities.invokeLater(() -> { updateComponent(prevValue); handleOnEnterAction(enterActionString); }); currentSearchComponentText = null; } } clearSearchVariants(); popupItemSelectionHandling = false; enterHandling = false; } SwingUtilities.invokeLater(this::updateEditState); }); Component editorComponent = comboBox.getEditor().getEditorComponent(); editorComponent.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { SwingUtilities.invokeLater(() -> { updateEditState(); if (e.getKeyChar() != '\n') { handleSearchInput(); } }); } @Override public void keyPressed(KeyEvent e) { SwingUtilities.invokeLater(() -> { if (e.getKeyCode() == KeyEvent.VK_DOWN && arrowDownActionHandler != null && !comboBox.isPopupVisible()) { arrowDownActionHandler.onArrowDownKeyPressed(getComboBoxEditorField().getText()); } }); } }); comboBox.setEditable(true); comboBox.setPrototypeDisplayValue("AAAAAAAAAAAA"); autoComplete = SearchAutoCompleteSupport.install(comboBox, items); autoComplete.setFilterEnabled(false); for (int i = 0; i < comboBox.getComponentCount(); i++) { Component component = comboBox.getComponent(i); component.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { clearSearchVariants(); // Reset invalid value checkSelectedValue(); } }); } final JTextField searchEditorComponent = getComboBoxEditorField(); searchEditorComponent.addActionListener(e -> currentSearchComponentText = searchEditorComponent.getText()); // set value only on PopupMenu closing to avoid firing listeners on keyboard navigation comboBox.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { comboBox.updatePopupWidth(); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { if (!autoComplete.isEditableState()) { popupItemSelectionHandling = comboBox.getSelectedIndex() >= 0; // Only if really item changed if (!enterHandling) { Object selectedItem = comboBox.getSelectedItem(); if (selectedItem instanceof ValueWrapper) { Object selectedValue = ((ValueWrapper) selectedItem).getValue(); setValue(selectedValue); clearSearchVariants(); } } updateMissingValueState(); } } @Override public void popupMenuCanceled(PopupMenuEvent e) { clearSearchVariants(); } }); textField = new JTextField(); textField.setEditable(false); UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); valueFormatter = new DefaultValueFormatter(sessionSource.getLocale()); composition.add(comboBox, BorderLayout.CENTER); impl = comboBox; DesktopComponentsHelper.adjustSize(comboBox); Configuration configuration = AppBeans.get(Configuration.NAME); asyncSearchDelayMs = configuration.getConfig(ClientConfig.class).getSuggestionFieldAsyncSearchDelayMs(); }
From source file:com.mirth.connect.client.ui.browsers.event.EventBrowser.java
public void initComponentsManual() { this.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { if (evt.isPopupTrigger()) { parent.eventPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); }/*from w ww . java 2 s . c o m*/ } public void mouseReleased(java.awt.event.MouseEvent evt) { if (evt.isPopupTrigger()) { parent.eventPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }); pageSizeField.setDocument(new MirthFieldConstraints(3, false, false, true)); pageNumberField.setDocument(new MirthFieldConstraints(7, false, false, true)); LineBorder lineBorder = new LineBorder(new Color(0, 0, 0)); TitledBorder titledBorder = new TitledBorder("Current Search"); titledBorder.setBorder(lineBorder); lastSearchCriteriaPane.setBorder(titledBorder); lastSearchCriteriaPane.setBackground(Color.white); lastSearchCriteria.setBackground(Color.white); startDatePicker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent arg0) { allDayCheckBox.setEnabled(startDatePicker.getDate() != null || endDatePicker.getDate() != null); startTimePicker.setEnabled(startDatePicker.getDate() != null && !allDayCheckBox.isSelected()); } }); endDatePicker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent arg0) { allDayCheckBox.setEnabled(startDatePicker.getDate() != null || endDatePicker.getDate() != null); endTimePicker.setEnabled(endDatePicker.getDate() != null && !allDayCheckBox.isSelected()); } }); pageNumberField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_ENTER && pageGoButton.isEnabled()) { jumpToPageNumber(); } } }); updateCachedUserMap(); advancedSearchPopup = new EventBrowserAdvancedFilter(parent, "Advanced Search Filter", true, userMapById); advancedSearchPopup.setVisible(false); eventSplitPane.setDividerLocation(0.8); this.addAncestorListener(new AncestorListener() { @Override public void ancestorAdded(AncestorEvent event) { } @Override public void ancestorMoved(AncestorEvent event) { } @Override public void ancestorRemoved(AncestorEvent event) { // Stop waiting for event browser requests when the event browser // is no longer being displayed parent.mirthClient.getServerConnection().abort(getAbortOperations()); // Clear the event cache when leaving the event browser. parent.eventBrowser.clearCache(); } }); }