List of usage examples for java.awt.event FocusAdapter FocusAdapter
FocusAdapter
From source file:edu.ku.brc.specify.datamodel.busrules.AttachmentBusRules.java
@Override public void initialize(Viewable viewableArg) { super.initialize(viewableArg); if (formViewObj != null) { //morphbankPanel = formViewObj.getCompById("morphbankpanel"); imageAttributeMultiView = formViewObj.getKids() != null && formViewObj.getKids().size() > 0 ? formViewObj.getKids().get(0) : null;//from w w w . ja va 2 s .c o m if (imageAttributeMultiView != null) { morphbankPanel = imageAttributeMultiView.getCurrentViewAsFormViewObj() .getCompById("morphbankpanel"); } origComp = formViewObj.getCompById("origFilename"); final Component titleComp = formViewObj.getCompById("title"); if (origComp instanceof EditViewCompSwitcherPanel) { EditViewCompSwitcherPanel evcsp = (EditViewCompSwitcherPanel) origComp; browser = (ValBrowseBtnPanel) evcsp.getComp(true); String dir = AppPreferences.getLocalPrefs().get(BROWSE_DIR_PREF, null); if (dir != null) { browser.setCurrentDir(dir); } } if (browser != null) { if (titleComp instanceof ValTextField) { final ValTextField titleTF = (ValTextField) titleComp; final ValTextField browserTF = browser.getValTextField(); browserTF.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { if (formViewObj.getDataObj() != null && ((DataModelObjBase) formViewObj.getDataObj()).getId() == null) { String filePath = browserTF.getText(); if (!filePath.isEmpty()) { titleTF.setText(FilenameUtils.getBaseName(browserTF.getText())); addImageAttributeIfNecessary(); } else { if (!titleTF.getText().isEmpty()) { titleTF.setText(null); } } } } }); browserTF.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { super.focusLost(e); if (formViewObj.getDataObj() != null && ((DataModelObjBase) formViewObj.getDataObj()).getId() == null) { String filePath = browserTF.getText(); if (titleTF.getText().isEmpty() && !filePath.isEmpty()) { titleTF.setText(FilenameUtils.getBaseName(filePath)); } } } }); } if (formViewObj.getRsController() != null && formViewObj.getRsController().getNewRecBtn() != null) { formViewObj.getRsController().getNewRecBtn().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { browser.getBrowseBtn().doClick(); } }); } }); } } } }
From source file:es.uvigo.ei.sing.adops.views.TextFileViewer.java
public TextFileViewer(final File file) { super(new BorderLayout()); this.file = file; // TEXT AREA/*from w ww. j ava 2 s. c om*/ this.textArea = new JTextArea(TextFileViewer.loadFile(file)); this.textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, this.textArea.getFont().getSize())); this.textArea.setLineWrap(true); this.textArea.setWrapStyleWord(true); this.textArea.setEditable(false); this.highlightPatiner = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW); // OPTIONS PANEL final JPanel panelOptions = new JPanel(new BorderLayout()); final JPanel panelOptionsEast = new JPanel(new FlowLayout()); final JPanel panelOptionsWest = new JPanel(new FlowLayout()); final JCheckBox chkLineWrap = new JCheckBox("Line wrap", true); final JButton btnChangeFont = new JButton("Change Font"); final JLabel lblSearch = new JLabel("Search"); this.txtSearch = new JTextField(); this.chkRegularExpression = new JCheckBox("Reg. exp.", true); final JButton btnSearch = new JButton("Search"); final JButton btnClear = new JButton("Clear"); this.txtSearch.setColumns(12); // this.txtSearch.setOpaque(true); panelOptionsEast.add(btnChangeFont); panelOptionsEast.add(chkLineWrap); panelOptionsWest.add(lblSearch); panelOptionsWest.add(this.txtSearch); panelOptionsWest.add(this.chkRegularExpression); panelOptionsWest.add(btnSearch); panelOptionsWest.add(btnClear); if (FastaUtils.isFasta(file)) { panelOptionsWest.add(new JSeparator()); final JButton btnExport = new JButton("Export..."); panelOptionsWest.add(btnExport); btnExport.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { new ExportDialog(file).setVisible(true); } catch (Exception e1) { JOptionPane.showMessageDialog(Workbench.getInstance().getMainFrame(), "Error reading fasta file: " + e1.getMessage(), "Export Error", JOptionPane.ERROR_MESSAGE); } } }); } panelOptions.add(panelOptionsWest, BorderLayout.WEST); panelOptions.add(panelOptionsEast, BorderLayout.EAST); this.fontChooser = new JFontChooser(); this.add(new JScrollPane(this.textArea), BorderLayout.CENTER); this.add(panelOptions, BorderLayout.NORTH); chkLineWrap.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { textArea.setLineWrap(chkLineWrap.isSelected()); } }); btnChangeFont.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changeFont(); } }); this.textArea.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { TextFileViewer.this.wasModified = true; } @Override public void insertUpdate(DocumentEvent e) { TextFileViewer.this.wasModified = true; } @Override public void changedUpdate(DocumentEvent e) { TextFileViewer.this.wasModified = true; } }); this.textArea.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (TextFileViewer.this.wasModified) { try { FileUtils.write(TextFileViewer.this.file, TextFileViewer.this.textArea.getText()); TextFileViewer.this.wasModified = false; } catch (IOException e1) { e1.printStackTrace(); } } } }); final ActionListener alSearch = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateSearch(); } }; txtSearch.addActionListener(alSearch); btnSearch.addActionListener(alSearch); btnClear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { clearSearch(); } }); }
From source file:se.trixon.toolbox.dbtext.DbTextTopComponent.java
private void initSourceChooser() { sourceChooserPanel.setPath(mOptions.getSourcePaths()); sourceChooserPanel.setDropMode(FileChooserPanel.DropMode.MULTI); sourceChooserPanel.setMode(JFileChooser.FILES_AND_DIRECTORIES); sourceChooserPanel.getFileChooser().setMultiSelectionEnabled(true); sourceChooserPanel.setButtonListener(this); sourceChooserPanel.getTextField().addFocusListener(new FocusAdapter() { @Override//from w w w . j a v a 2s. c o m public void focusLost(java.awt.event.FocusEvent evt) { saveSourcePath(); } }); sourceChooserPanel.getTextField().getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { saveSourcePath(); } @Override public void insertUpdate(DocumentEvent e) { saveSourcePath(); } @Override public void removeUpdate(DocumentEvent e) { saveSourcePath(); } }); }
From source file:com.mirth.connect.client.ui.EditMessageDialog.java
private void initSourceMapTable(Map<String, Object> sourceMap) { Object[][] data = new Object[sourceMap.size()][2]; int i = 0;/*from ww w . j a v a 2 s . c o m*/ for (Entry<String, Object> entry : sourceMap.entrySet()) { data[i][0] = entry.getKey(); data[i][1] = entry.getValue(); i++; } sourceMapTable = new MirthTable(); sourceMapTable.setModel(new RefreshTableModel(data, new Object[] { "Variable", "Value" }) { @Override public boolean isCellEditable(int row, int column) { return true; } }); sourceMapTable.setDragEnabled(false); sourceMapTable.setRowSelectionAllowed(true); sourceMapTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); sourceMapTable.setRowHeight(UIConstants.ROW_HEIGHT); sourceMapTable.setFocusable(false); sourceMapTable.setOpaque(true); sourceMapTable.getTableHeader().setResizingAllowed(false); sourceMapTable.getTableHeader().setReorderingAllowed(false); sourceMapTable.setSortable(true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { sourceMapTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } sourceMapTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { deleteButton.setEnabled(sourceMapTable.getSelectedRow() > -1); } } }); class SourceMapTableCellEditor extends AbstractCellEditor implements TableCellEditor { private JTable table; private int column; private JTextField textField; private Object originalValue; private String newValue; public SourceMapTableCellEditor(JTable table, int column) { super(); this.table = table; this.column = column; textField = new JTextField(); textField.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { textField.setCaretPosition(textField.getText().length()); } }); } @Override public boolean isCellEditable(EventObject evt) { if (evt == null) { return false; } if (evt instanceof MouseEvent) { return ((MouseEvent) evt).getClickCount() >= 2; } return true; } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { originalValue = value; newValue = null; textField.setText(String.valueOf(value)); return textField; } @Override public Object getCellEditorValue() { if (newValue != null) { return newValue; } else { return originalValue; } } @Override public boolean stopCellEditing() { if (!valueChanged()) { super.cancelCellEditing(); } else { newValue = textField.getText(); } return super.stopCellEditing(); } private boolean valueChanged() { String value = textField.getText(); if (StringUtils.isBlank(value)) { return false; } for (int i = 0; i < table.getRowCount(); i++) { Object tableValue = table.getValueAt(i, column); if (tableValue != null && String.valueOf(tableValue).equals(value)) { return false; } } return true; } } sourceMapTable.getColumnModel().getColumn(0).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 0)); sourceMapTable.getColumnModel().getColumn(1).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 1)); sourceMapScrollPane.setViewportView(sourceMapTable); deleteButton.setEnabled(false); }
From source file:op.care.med.inventory.DlgTX.java
/** * This method is called from within the constructor to * initialize the form.// w ww . j a v a 2 s.com * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the PrinterForm Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { lblText = new JLabel(); txtText = new JTextField(); txtValue = new JTextField(); lblValue = new JLabel(); lblUnit = new JLabel(); lblWeightControl = new JLabel(); txtWeightControlled = new JTextField(); lblUnit2 = new JLabel(); panel1 = new JPanel(); btnCancel = new JButton(); btnBuchung = new JButton(); //======== this ======== Container contentPane = getContentPane(); contentPane.setLayout( new FormLayout("default, $lcgap, default, $ugap, 141dlu:grow, $rgap, default, $lcgap, default", "2*(default, $lgap), fill:default, $lgap, default, $lgap, fill:default")); //---- lblText ---- lblText.setText("Buchungstext"); lblText.setFont(new Font("Arial", Font.PLAIN, 14)); contentPane.add(lblText, CC.xy(3, 3, CC.DEFAULT, CC.TOP)); //---- txtText ---- txtText.setColumns(100); txtText.addActionListener(e -> txtTextActionPerformed(e)); contentPane.add(txtText, CC.xywh(5, 3, 3, 1)); //---- txtValue ---- txtValue.setHorizontalAlignment(SwingConstants.RIGHT); txtValue.setText("jTextField1"); txtValue.setFont(new Font("Arial", Font.PLAIN, 14)); txtValue.addCaretListener(e -> txtMengeCaretUpdate(e)); txtValue.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { txtMengeFocusGained(e); } }); txtValue.addActionListener(e -> txtValueActionPerformed(e)); contentPane.add(txtValue, CC.xy(5, 5)); //---- lblValue ---- lblValue.setText("Menge"); lblValue.setFont(new Font("Arial", Font.PLAIN, 14)); contentPane.add(lblValue, CC.xy(3, 5)); //---- lblUnit ---- lblUnit.setHorizontalAlignment(SwingConstants.TRAILING); lblUnit.setText("jLabel4"); lblUnit.setFont(new Font("Arial", Font.PLAIN, 14)); contentPane.add(lblUnit, CC.xy(7, 5)); //---- lblWeightControl ---- lblWeightControl.setText("Menge"); lblWeightControl.setFont(new Font("Arial", Font.PLAIN, 14)); contentPane.add(lblWeightControl, CC.xy(3, 7)); //---- txtWeightControlled ---- txtWeightControlled.setHorizontalAlignment(SwingConstants.RIGHT); txtWeightControlled.setText("jTextField1"); txtWeightControlled.setFont(new Font("Arial", Font.PLAIN, 14)); txtWeightControlled.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { txtWeightControlledFocusGained(e); } }); txtWeightControlled.addCaretListener(e -> txtWeightControlledCaretUpdate(e)); contentPane.add(txtWeightControlled, CC.xy(5, 7)); //---- lblUnit2 ---- lblUnit2.setHorizontalAlignment(SwingConstants.TRAILING); lblUnit2.setText("g"); lblUnit2.setFont(new Font("Arial", Font.PLAIN, 14)); contentPane.add(lblUnit2, CC.xy(7, 7, CC.LEFT, CC.DEFAULT)); //======== panel1 ======== { panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS)); //---- btnCancel ---- btnCancel.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/cancel.png"))); btnCancel.addActionListener(e -> btnCancelActionPerformed(e)); panel1.add(btnCancel); //---- btnBuchung ---- btnBuchung.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/apply.png"))); btnBuchung.addActionListener(e -> btnBuchungActionPerformed(e)); panel1.add(btnBuchung); } contentPane.add(panel1, CC.xywh(5, 9, 3, 1, CC.RIGHT, CC.DEFAULT)); setSize(600, 165); setLocationRelativeTo(getOwner()); }
From source file:pipeline.parameter_cell_views.FloatRangeSlider.java
public FloatRangeSlider() { super();/* w ww .j a va2 s . com*/ addMouseWheelListener(e -> { int rotation = e.getWheelRotation(); float[] float_values = (float[]) (currentParameter.getValue()); currentValue0 = float_values[0]; currentValue1 = float_values[1]; minimum = float_values[2]; maximum = float_values[3]; float change = (currentValue1 - currentValue0 + 1) * rotation * Utils.getMouseWheelClickFactor(); currentValue0 += change; currentValue1 += change; if (!((e.getModifiers() & java.awt.event.InputEvent.ALT_MASK) > 0)) { if (currentValue1 > maximum) { float difference = currentValue1 - currentValue0; currentValue1 = maximum; currentValue0 = currentValue1 - difference; } if (currentValue0 < minimum) { float difference = currentValue1 - currentValue0; currentValue0 = minimum; currentValue1 = currentValue0 + difference; } } currentParameter.setValue(new float[] { currentValue0, currentValue1, minimum, maximum }); readInValuesFromParameter(); updateDisplays(); currentParameter.fireValueChanged(false, false, true); }); nf.setGroupingUsed(true); nf.setMaximumFractionDigits(5); nf.setMaximumIntegerDigits(10); setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridy = 0; c.weighty = 1.0; c.weightx = 1.0; c.gridwidth = 4; cForHistogram = (GridBagConstraints) c.clone(); panelForHistogram = new JPanel(); panelForHistogram.setPreferredSize(new Dimension(200, 150)); panelForHistogram.setLayout(new BorderLayout()); c.gridx = 0; c.gridy = 1;// 1 c.weighty = 0.0; c.weightx = 0.0; c.gridwidth = 4; add(Box.createRigidArea(new Dimension(0, 5)), c); slider = new RangeSlider(0, 20); slider.addChangeListener(new sliderListener()); c.gridx = 0; c.gridy = 2; c.weighty = 0.0; c.weightx = 0.0; c.gridwidth = 4; add(slider, c); c.gridx = 0; c.gridy = 3; c.weighty = 0.0; c.weightx = 1.0; c.gridwidth = 4; Component comp = Box.createRigidArea(new Dimension(0, 10)); ((JComponent) comp).setOpaque(true); add(comp, c); c.gridwidth = 1; final textBoxListener minMaxListener = new textBoxListener(); currentTextValue0 = new JTextField(""); currentTextValue1 = new JTextField(""); currentTextValue0.addActionListener(new textBoxListenerTriggersUpdate()); currentTextValue1.addActionListener(new textBoxListenerTriggersUpdate()); Font smallerFont = new Font(currentTextValue0.getFont().getName(), currentTextValue0.getFont().getStyle(), currentTextValue0.getFont().getSize() - 2); textMinimum = new JTextField("0"); textMinimum.setFont(smallerFont); textMinimum.addActionListener(minMaxListener); textMaximum = new JTextField("50"); textMaximum.setFont(smallerFont); textMaximum.addActionListener(minMaxListener); textMaximum.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { minMaxListener.actionPerformed(new ActionEvent(textMaximum, 0, "")); } }); textMinimum.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { minMaxListener.actionPerformed(new ActionEvent(textMinimum, 0, "")); } }); textValueFrame = new JPanel(); textValueFrame.setBackground(getBackground()); textValueFrame.setLayout(new GridBagLayout()); c.gridx = 0; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.1; textValueFrame.add(textMinimum, c); c.gridx = 1; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.3; textValueFrame.add(currentTextValue0, c); c.gridx = 2; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.3; textValueFrame.add(currentTextValue1, c); c.gridx = 3; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.1; textValueFrame.add(textMaximum, c); c.gridx = 0; c.gridy = 4; c.weighty = 0.0; c.weightx = 0.3; c.gridwidth = 4; add(textValueFrame, c); c.gridwidth = 1; parameterName = new JLabel("parameter"); c.gridx = 0; c.gridy = 5; c.weighty = 0.0; c.weightx = 0.01; c.gridwidth = 1; add(parameterName, c); resetMin = new JButton("Min"); resetMin.setActionCommand("Reset Min"); resetMin.addActionListener(new buttonListener()); resetMax = new JButton("Max"); resetMax.setActionCommand("Reset Max"); resetMax.addActionListener(new buttonListener()); resetRange = new JButton("MinMax"); resetRange.setActionCommand("Reset Range"); resetRange.addActionListener(new buttonListener()); c.gridx = 1; c.gridy = 5; c.weighty = 0.0; c.weightx = 0.2; c.gridwidth = 1; add(resetMin, c); c.gridx = 2; c.gridy = 5; c.weighty = 0.0; c.weightx = 0.2; c.gridwidth = 1; add(resetMax, c); c.gridx = 3; c.gridy = 5; c.weighty = 0.0; c.weightx = 0.2; c.gridwidth = 1; add(resetRange, c); // ,resetMax,resetRange; }
From source file:op.controlling.DlgQMSPlan.java
/** * This method is called from within the constructor to * initialize the form.//ww w . ja va2 s . c om * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the PrinterForm Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { pnlLeft = new JPanel(); lblTitle = new JLabel(); txtTitle = new JTextField(); lblNotify = new JideLabel(); cmbNotify = new JComboBox(); jScrollPane3 = new JScrollPane(); txtDescription = new JTextArea(); lblDescription = new JideLabel(); scrollPane1 = new JScrollPane(); lstNotify = new JList(); lblTags = new JLabel(); panel1 = new JPanel(); btnCancel = new JButton(); btnSave = new JButton(); //======== this ======== setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Container contentPane = getContentPane(); contentPane.setLayout(new FormLayout("14dlu, $lcgap, pref:grow, $ugap, pref", "fill:14dlu, $lgap, fill:default:grow, $rgap, pref, $lgap, 14dlu")); //======== pnlLeft ======== { pnlLeft.setLayout(new FormLayout("pref, $lcgap, default:grow, $lcgap, pref, $lcgap, default:grow", "default, $lgap, fill:default, $rgap, fill:default:grow, $lgap, 40dlu, $rgap, default")); //---- lblTitle ---- lblTitle.setFont(new Font("Arial", Font.PLAIN, 18)); lblTitle.setText("Stichwort"); lblTitle.setHorizontalAlignment(SwingConstants.CENTER); pnlLeft.add(lblTitle, CC.xy(3, 1)); //---- txtTitle ---- txtTitle.setFont(new Font("Arial", Font.PLAIN, 20)); txtTitle.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { txtTitleFocusGained(e); } }); pnlLeft.add(txtTitle, CC.xy(3, 3)); //---- lblNotify ---- lblNotify.setText("text"); lblNotify.setOrientation(1); lblNotify.setFont(new Font("Arial", Font.PLAIN, 18)); lblNotify.setHorizontalAlignment(SwingConstants.CENTER); lblNotify.setClockwise(false); pnlLeft.add(lblNotify, CC.xywh(5, 3, 1, 3)); //---- cmbNotify ---- cmbNotify.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { cmbNotifyItemStateChanged(e); } }); pnlLeft.add(cmbNotify, CC.xy(7, 3)); //======== jScrollPane3 ======== { //---- txtDescription ---- txtDescription.setColumns(20); txtDescription.setLineWrap(true); txtDescription.setRows(5); txtDescription.setWrapStyleWord(true); txtDescription.setFont(new Font("Arial", Font.PLAIN, 14)); txtDescription.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { txtDescriptionFocusGained(e); } }); jScrollPane3.setViewportView(txtDescription); } pnlLeft.add(jScrollPane3, CC.xy(3, 5)); //---- lblDescription ---- lblDescription.setFont(new Font("Arial", Font.PLAIN, 18)); lblDescription.setText("Situation"); lblDescription.setOrientation(1); lblDescription.setClockwise(false); pnlLeft.add(lblDescription, CC.xy(1, 5, CC.DEFAULT, CC.CENTER)); //======== scrollPane1 ======== { //---- lstNotify ---- lstNotify.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); lstNotify.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { lstNotifyValueChanged(e); } }); scrollPane1.setViewportView(lstNotify); } pnlLeft.add(scrollPane1, CC.xy(7, 5)); //---- lblTags ---- lblTags.setFont(new Font("Arial", Font.PLAIN, 18)); lblTags.setText("Markierung"); lblTags.setHorizontalAlignment(SwingConstants.CENTER); pnlLeft.add(lblTags, CC.xywh(3, 9, 5, 1)); } contentPane.add(pnlLeft, CC.xy(3, 3)); //======== panel1 ======== { panel1.setLayout(new HorizontalLayout(5)); //---- btnCancel ---- btnCancel.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/cancel.png"))); btnCancel.setText(null); btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { btnCancelActionPerformed(e); } }); panel1.add(btnCancel); //---- btnSave ---- btnSave.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/apply.png"))); btnSave.setText(null); btnSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { btnSaveActionPerformed(e); } }); panel1.add(btnSave); } contentPane.add(panel1, CC.xy(3, 5, CC.RIGHT, CC.DEFAULT)); setSize(710, 495); setLocationRelativeTo(getOwner()); }
From source file:de.mprengemann.intellij.plugin.androidicons.dialogs.VectorImporter.java
private void initSearch() { final List<ImageAsset> imageAssets = new ArrayList<ImageAsset>(); imageAssets.addAll(materialIconsController.getAssets(materialIconsController.getCategories())); for (ImageAsset imageAsset : imageAssets) { searchField.addItem(imageAsset); }/* ww w. ja v a2s . c om*/ searchField.setRenderer(new AssetSpinnerRenderer()); comboboxSpeedSearch = new ComboboxSpeedSearch(searchField) { @Override protected String getElementText(Object element) { return element instanceof ImageAsset ? ((ImageAsset) element).getName() : ""; } }; searchField.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { comboboxSpeedSearch.showPopup(); } }); searchField.addItemListener(searchFieldListener); }
From source file:org.nuclos.client.wizard.util.NuclosWizardUtils.java
public static FocusAdapter createWizardFocusAdapter() { return new FocusAdapter() { @Override//from ww w . ja v a2 s. c om public void focusGained(FocusEvent e) { if (e.getSource() instanceof JTextComponent) { JTextComponent tf = (JTextComponent) e.getSource(); tf.setSelectionStart(0); tf.setSelectionEnd(tf.getText().length()); } } }; }
From source file:net.sf.vfsjfilechooser.accessories.connection.ConnectionDialog.java
private void initListeners() { this.portTextField.addKeyListener(new KeyAdapter() { @Override//ww w. j a va 2 s . c om 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); }