List of usage examples for java.awt.event KeyAdapter KeyAdapter
KeyAdapter
From source file:uom.research.thalassemia.ui.PatientUI.java
/** * Patient search listener.//from w w w . ja v a 2s . c om */ void setPatientSearchListener() { textField = (JTextField) cmbSearch.getEditor().getEditorComponent(); textField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent evt) { try { String s = textField.getText(); //List<ODocument> rst = DatabaseAccess.selectData("select from Patient where firstName like '" + s + "%' and isActive=true"); FillData.fillCombo(cmbSearch, "select from Patient where firstName like '" + s + "%' and isActive=true", "firstName"); int rw = cmbSearch.getMaximumRowCount(); if (rw > 5) { cmbSearch.setMaximumRowCount(5); } else { cmbSearch.setMaximumRowCount(rw); } if (s.isEmpty() || evt.getKeyCode() == KeyEvent.VK_ENTER) { cmbSearch.hidePopup(); } else { cmbSearch.showPopup(); } cmbSearch.setSelectedItem(s); } catch (Exception e) { } } }); }
From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java
/** Creates new TreePanel */ public Hl7V2MessageTree(Controller theController) { addKeyListener(new KeyAdapter() { @Override/*from www . j ava2 s .c o m*/ public void keyPressed(KeyEvent e) { handleKeyPress(e); } }); setFont(new Font("LUCIDA", Font.PLAIN, 9)); myController = theController; myPipeParser = new PipeParser(); myPipeParser.setValidationContext(new ValidationContextImpl()); setRenderDataProvider(new TreeRenderDataProvider()); setShowGrid(true); setGridColor(new Color(0.9f, 0.9f, 0.9f)); setRowHeight(16); setRowSelectionAllowed(true); setSelectionModel(new MySelectionModel()); ValueCellEditor valueCellEditor = new ValueCellEditor(getFont()); setDefaultEditor(String.class, valueCellEditor); valueCellEditor.addCellEditorListener(new CellEditorListener() { public void editingCanceled(ChangeEvent theE) { ourLog.info("No longer editing"); myCurrentlyEditing = false; } public void editingStopped(ChangeEvent theE) { ourLog.info("No longer editing"); myCurrentlyEditing = false; } }); myHighlitedPathListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent theEvt) { if (myController.isMessageEditorInFollowMode()) { if (Hl7V2MessageTree.this.hasFocus() == false) { synchronizeTreeWithHighlitedPath(); } } } }; myParsedMessagesListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent theEvt) { myUpdaterThread.scheduleUpdate(); } }; myValidationContextListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent theEvt) { myUpdaterThread.scheduleUpdate(); } }; myMessageEncodingListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent theEvt) { myUpdaterThread.scheduleUpdate(); } }; getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myUpdaterThread = new UpdaterThread(); myUpdaterThread.start(); }
From source file:net.sf.jabref.gui.search.SearchBar.java
/** * Initializes the search text field//from w ww . jav a 2 s .c om */ private void initSearchField() { searchField.setColumns(30); searchField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getExtendedKeyCode() == KeyEvent.VK_ESCAPE) { endSearch(); } } }); // Add autocompleter autoCompleteSupport = new AutoCompleteSupport<>(searchField); autoCompleteSupport.install(); // Add the global focus listener, so a menu item can see if this field was focused when an action was called. searchField.addFocusListener(Globals.getFocusListener()); // Search if user press enter searchField.addActionListener(e -> performSearch()); // Subscribe to changes to the text in the search field in order to "live search" JTextFieldChangeListenerUtil.addChangeListener(searchField, e -> performSearch()); }
From source file:savant.view.swing.NavigationBar.java
NavigationBar() { this.setOpaque(false); this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); String buttonStyle = "segmentedCapsule"; String shortcutMod = MiscUtils.MAC ? "Cmd" : "Ctrl"; add(getRigidPadding());/*from ww w . ja va 2 s. c o m*/ JButton loadGenomeButton = (JButton) add(new JButton("")); loadGenomeButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.GENOME)); loadGenomeButton.setToolTipText("Load or change genome"); loadGenomeButton.setFocusable(false); loadGenomeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Savant.getInstance().showOpenGenomeDialog(); } }); loadGenomeButton.putClientProperty("JButton.buttonType", buttonStyle); loadGenomeButton.putClientProperty("JButton.segmentPosition", "first"); loadGenomeButton.setPreferredSize(ICON_SIZE); loadGenomeButton.setMinimumSize(ICON_SIZE); loadGenomeButton.setMaximumSize(ICON_SIZE); JButton loadTrackButton = (JButton) add(new JButton("")); loadTrackButton.setFocusable(false); loadTrackButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.TRACK)); loadTrackButton.setToolTipText("Load a track"); loadTrackButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Savant.getInstance().openTrack(); } }); loadTrackButton.putClientProperty("JButton.buttonType", buttonStyle); loadTrackButton.putClientProperty("JButton.segmentPosition", "last"); loadTrackButton.setPreferredSize(ICON_SIZE); loadTrackButton.setMinimumSize(ICON_SIZE); loadTrackButton.setMaximumSize(ICON_SIZE); if (!Savant.getInstance().isStandalone()) { add(loadGenomeButton); add(loadTrackButton); add(getRigidPadding()); add(getRigidPadding()); } else { loadGenomeButton.setVisible(false); loadTrackButton.setVisible(false); } JLabel rangeText = new JLabel("Location "); add(rangeText); String[] a = { " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }; locationField = new JComboBox(a); locationField.setEditable(true); locationField.setRenderer(new ReferenceListRenderer()); // When the item is chosen from the menu, navigate to the given feature/reference. locationField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (!currentlyPopulating) { if (ae.getActionCommand().equals("comboBoxChanged")) { // Assumes that combo-box items created by populateCombo() are of the form "GENE (chrX:1-1000)". String itemText = locationField.getSelectedItem().toString(); int lastBracketPos = itemText.lastIndexOf('('); if (lastBracketPos > 0) { itemText = itemText.substring(lastBracketPos + 1, itemText.length() - 1); } setRangeFromText(itemText); } } } }); // When the combo-box is popped open, we may want to repopulate the menu. locationField.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent pme) { String text = (String) locationField.getEditor().getItem(); if (!text.equals(lastPoppedUp)) { try { // Building the menu could take a while. setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); populateCombo(); } finally { setCursor(Cursor.getDefaultCursor()); } } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent pme) { } @Override public void popupMenuCanceled(PopupMenuEvent pme) { } }); // Add our special keystroke-handling to the JComboBox' text-field. // We have to turn off default tab-handling so that tab can pop up our list. Component textField = locationField.getEditor().getEditorComponent(); textField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_TAB) { locationField.showPopup(); } else if (evt.getModifiers() == KeyEvent.SHIFT_MASK) { switch (evt.getKeyCode()) { case KeyEvent.VK_LEFT: locationController.shiftRangeLeft(); evt.consume(); break; case KeyEvent.VK_RIGHT: locationController.shiftRangeRight(); evt.consume(); break; case KeyEvent.VK_UP: locationController.zoomIn(); evt.consume(); break; case KeyEvent.VK_DOWN: locationController.zoomOut(); evt.consume(); break; case KeyEvent.VK_HOME: locationController.shiftRangeFarLeft(); evt.consume(); break; case KeyEvent.VK_END: locationController.shiftRangeFarRight(); evt.consume(); break; } } } }); add(locationField); locationField.setToolTipText("Current display range"); locationField.setPreferredSize(LOCATION_SIZE); locationField.setMaximumSize(LOCATION_SIZE); locationField.setMinimumSize(LOCATION_SIZE); add(getRigidPadding()); JButton goButton = (JButton) add(new JButton(" Go ")); goButton.putClientProperty("JButton.buttonType", buttonStyle); goButton.putClientProperty("JButton.segmentPosition", "only"); goButton.setToolTipText("Go to specified range (Enter)"); goButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setRangeFromText(locationField.getEditor().getItem().toString()); } }); add(getRigidPadding()); JLabel l = new JLabel("Length: "); add(l); lengthLabel = (JLabel) add(new JLabel()); lengthLabel.setToolTipText("Length of the current range"); lengthLabel.setPreferredSize(LENGTH_SIZE); lengthLabel.setMaximumSize(LENGTH_SIZE); lengthLabel.setMinimumSize(LENGTH_SIZE); add(Box.createGlue()); double screenwidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); JButton afterGo = null; //if (screenwidth > 800) { final JButton undoButton = (JButton) add(new JButton("")); afterGo = undoButton; undoButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.UNDO)); undoButton.setToolTipText("Undo range change (" + shortcutMod + "+Z)"); undoButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.undoLocationChange(); } }); undoButton.putClientProperty("JButton.buttonType", buttonStyle); undoButton.putClientProperty("JButton.segmentPosition", "first"); undoButton.setPreferredSize(ICON_SIZE); undoButton.setMinimumSize(ICON_SIZE); undoButton.setMaximumSize(ICON_SIZE); final JButton redo = (JButton) add(new JButton("")); redo.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.REDO)); redo.setToolTipText("Redo range change (" + shortcutMod + "+Y)"); redo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.redoLocationChange(); } }); redo.putClientProperty("JButton.buttonType", buttonStyle); redo.putClientProperty("JButton.segmentPosition", "last"); redo.setPreferredSize(ICON_SIZE); redo.setMinimumSize(ICON_SIZE); redo.setMaximumSize(ICON_SIZE); //} add(getRigidPadding()); add(getRigidPadding()); final JButton zoomInButton = (JButton) add(new JButton()); if (afterGo == null) { afterGo = zoomInButton; } zoomInButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.ZOOMIN)); zoomInButton.putClientProperty("JButton.buttonType", buttonStyle); zoomInButton.putClientProperty("JButton.segmentPosition", "first"); zoomInButton.setPreferredSize(ICON_SIZE); zoomInButton.setMinimumSize(ICON_SIZE); zoomInButton.setMaximumSize(ICON_SIZE); zoomInButton.setToolTipText("Zoom in (Shift+Up)"); zoomInButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.zoomIn(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "zoomed"), new NameValuePair("navigation-direction", "in"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton zoomOut = (JButton) add(new JButton("")); zoomOut.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.ZOOMOUT)); zoomOut.setToolTipText("Zoom out (Shift+Down)"); zoomOut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.zoomOut(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "zoomed"), new NameValuePair("navigation-direction", "out"), new NameValuePair("navigation-modality", "navbar") }); } }); zoomOut.putClientProperty("JButton.buttonType", buttonStyle); zoomOut.putClientProperty("JButton.segmentPosition", "last"); zoomOut.setPreferredSize(ICON_SIZE); zoomOut.setMinimumSize(ICON_SIZE); zoomOut.setMaximumSize(ICON_SIZE); add(getRigidPadding()); add(getRigidPadding()); final JButton shiftFarLeft = (JButton) add(new JButton()); shiftFarLeft.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_FARLEFT)); shiftFarLeft.putClientProperty("JButton.buttonType", buttonStyle); shiftFarLeft.putClientProperty("JButton.segmentPosition", "first"); shiftFarLeft.setToolTipText("Move to the beginning of the genome (Shift+Home)"); shiftFarLeft.setPreferredSize(ICON_SIZE); shiftFarLeft.setMinimumSize(ICON_SIZE); shiftFarLeft.setMaximumSize(ICON_SIZE); shiftFarLeft.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeFarLeft(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "left"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton shiftLeft = (JButton) add(new JButton()); shiftLeft.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_LEFT)); shiftLeft.putClientProperty("JButton.buttonType", buttonStyle); shiftLeft.putClientProperty("JButton.segmentPosition", "middle"); shiftLeft.setToolTipText("Move left (Shift+Left)"); shiftLeft.setPreferredSize(ICON_SIZE); shiftLeft.setMinimumSize(ICON_SIZE); shiftLeft.setMaximumSize(ICON_SIZE); shiftLeft.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeLeft(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "left"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton shiftRight = (JButton) add(new JButton()); shiftRight.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_RIGHT)); shiftRight.putClientProperty("JButton.buttonType", buttonStyle); shiftRight.putClientProperty("JButton.segmentPosition", "middle"); shiftRight.setToolTipText("Move right (Shift+Right)"); shiftRight.setPreferredSize(ICON_SIZE); shiftRight.setMinimumSize(ICON_SIZE); shiftRight.setMaximumSize(ICON_SIZE); shiftRight.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeRight(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "right"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton shiftFarRight = (JButton) add(new JButton()); shiftFarRight .setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_FARRIGHT)); shiftFarRight.putClientProperty("JButton.buttonType", buttonStyle); shiftFarRight.putClientProperty("JButton.segmentPosition", "last"); shiftFarRight.setToolTipText("Move to the end of the genome (Shift+End)"); shiftFarRight.setPreferredSize(ICON_SIZE); shiftFarRight.setMinimumSize(ICON_SIZE); shiftFarRight.setMaximumSize(ICON_SIZE); shiftFarRight.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeFarRight(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "right"), new NameValuePair("navigation-modality", "navbar") }); } }); add(getRigidPadding()); locationController.addListener(new Listener<LocationChangedEvent>() { @Override public void handleEvent(LocationChangedEvent event) { updateLocation(event.getReference(), (Range) event.getRange()); } }); // When the genome changes, we may need to invalidate our menu. GenomeController.getInstance().addListener(new Listener<GenomeChangedEvent>() { @Override public void handleEvent(GenomeChangedEvent event) { lastPoppedUp = "INVALID"; } }); this.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent ce) { int width = ce.getComponent().getWidth(); undoButton.setVisible(true); redo.setVisible(true); zoomInButton.setVisible(true); zoomOut.setVisible(true); shiftFarLeft.setVisible(true); shiftLeft.setVisible(true); shiftRight.setVisible(true); shiftFarRight.setVisible(true); // hide some components if the window isn't wide enough if (width < 1200) { undoButton.setVisible(false); redo.setVisible(false); } if (width < 1000) { shiftFarLeft.setVisible(false); shiftFarRight.setVisible(false); shiftRight.putClientProperty("JButton.segmentPosition", "last"); shiftLeft.putClientProperty("JButton.segmentPosition", "first"); } else { shiftRight.putClientProperty("JButton.segmentPosition", "middle"); shiftLeft.putClientProperty("JButton.segmentPosition", "middle"); } } public void componentMoved(ComponentEvent ce) { } @Override public void componentShown(ComponentEvent ce) { } @Override public void componentHidden(ComponentEvent ce) { } }); }
From source file:org.pentaho.ui.xul.swing.tags.SwingTextbox.java
public void setOninput(final String method) { if (textComp != null) { textComp.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { invoke(method);/*from w w w. ja v a 2 s.c o m*/ } }); } else { // Not instantiated, save for later onInput = method; } }
From source file:edu.ku.brc.af.ui.db.JEditComboBox.java
protected KeyAdapter createKeyAdapter() { return new KeyAdapter() { @Override//ww w . j ava 2 s. c o m public void keyReleased(KeyEvent ev) { char key = ev.getKeyChar(); if (ev.getKeyCode() == clearKeyStroke.getKeyCode()) { int selectedIndex = getSelectedIndex(); if (selectedIndex > -1 && dbAdapter != null && textField != null && textField.getText().length() == 0 && !dbAdapter.isReadOnly()) { // delete item PickListItem item = (PickListItem) getSelectedItem(); dbAdapter.getList().remove(item); } } else if (!(Character.isLetterOrDigit(key) || Character.isSpaceChar(key))) { if (ev.getKeyCode() == KeyEvent.VK_ENTER) { addNewItemFromTextField(); } } else { if (textField != null) { if (getSelectedIndex() > -1) { int pos = textField.getCaretPosition(); String currentText = textField.getText(); setSelectedIndex(-1); textField.setText(currentText); textField.moveCaretPosition(pos); textField.setSelectionStart(pos); textField.setSelectionEnd(pos); } } else { setSelectedIndex(-1); } } } }; }
From source file:plugin.notes.gui.JIcon.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor./*ww w.j a va 2 s . c o m*/ */ private void initComponents() { contextMenu = new JPopupMenu(); JMenuItem launchMI = new JMenuItem(); JMenuItem deleteMI = new JMenuItem(); button = new JButton(); label = new JLabel(); launchMI.setText("Launch File (enter)"); launchMI.addActionListener(this::launchMIActionPerformed); contextMenu.add(launchMI); deleteMI.setText("Delete File (del)"); deleteMI.addActionListener(this::deleteMIActionPerformed); contextMenu.add(deleteMI); setLayout(new BorderLayout()); setBackground((Color) UIManager.getDefaults().get("Panel.background")); setBorder(new LineBorder(new Color(0, 0, 0))); button.setBackground((Color) UIManager.getDefaults().get("Button.background")); button.setBorder(null); button.addActionListener(this::buttonActionPerformed); button.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent evt) { buttonFocusGained(evt); } @Override public void focusLost(FocusEvent evt) { buttonFocusLost(evt); } }); button.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent evt) { buttonKeyReleased(evt); } }); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { buttonMouseClicked(evt); } @Override public void mouseReleased(MouseEvent evt) { buttonMouseReleased(evt); } }); add(button, BorderLayout.NORTH); label.setBackground(new Color(204, 204, 204)); add(label, BorderLayout.CENTER); }
From source file:org.docx4all.swing.ExternalHyperlinkDialog.java
private JPanel createContentPanel(String sourceFileVFSUrlPath, HyperlinkML hyperlinkML) { JPanel thePanel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); fillRow1(thePanel, c);//from ww w . jav a2 s . c om fillRow2(thePanel, c); fillRow3(thePanel, c); fillRow4(thePanel, c); fillRow5(thePanel, c); //Display Text Field if (hyperlinkML.getDisplayText() != null) { this.displayTextField.setText(hyperlinkML.getDisplayText()); } this.displayTextFieldAutoUpdate = (this.displayTextField.getText().length() == 0); //Set DisplayTextFieldAutoUpdate flag this.displayTextField.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { JTextField field = (JTextField) e.getSource(); if (field.getText().length() == 0) { ExternalHyperlinkDialog.this.displayTextFieldAutoUpdate = true; } else { ExternalHyperlinkDialog.this.displayTextFieldAutoUpdate = false; } } }); //Tooltip Field if (hyperlinkML.getTooltip() != null) { this.tooltipField.setText(hyperlinkML.getTooltip()); } //Target Field is split into documentNameField and directoryPathField. //These two fields are in friendly format; ie: no user credentials String target = HyperlinkML.encodeTarget(hyperlinkML, getSourceFileObject(), true); if (target != null) { int idx = target.lastIndexOf("/"); this.documentNameField.setText(target.substring(idx + 1)); if (target.startsWith(FILE_PREFIX)) { target = target.substring(FILE_PREFIX.length(), idx); } else { target = target.substring(0, idx); } this.directoryPathField.setText(target); } else { //A brand new HyperlinkML may be ? target = VFSUtils.getFriendlyName(this.sourceFileVFSUrlPath); int idx = target.lastIndexOf("/"); //Leave this.documentNameField blank this.directoryPathField.setText(target.substring(0, idx)); } //Install DocumentNameFieldListener so that Display Text Field //can be automatically updated. this.documentNameField.getDocument().addDocumentListener(new DocumentNameFieldListener()); //We also need to keep a reference to target in complete VFS url format; //ie: include user credentials in the reference. target = HyperlinkML.encodeTarget(hyperlinkML, getSourceFileObject(), false); if (target != null) { int idx = target.lastIndexOf("/"); this.directoryUrlPath = target.substring(0, idx); } else { //A brand new HyperlinkML may be ? int idx = this.sourceFileVFSUrlPath.lastIndexOf("/"); this.directoryUrlPath = this.sourceFileVFSUrlPath.substring(0, idx); } return thePanel; }
From source file:tvbrowser.ui.filter.dlgs.EditFilterDlg.java
public EditFilterDlg(JFrame parent, FilterList filterList, UserFilter filter) { super(parent, true); UiUtilities.registerForClosing(this); mFilterList = filterList;/*from w w w. j a va 2 s. c o m*/ mParent = parent; mFilter = filter; JPanel contentPane = (JPanel) getContentPane(); contentPane.setLayout(new BorderLayout(7, 7)); contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); if (filter == null) { setTitle(mLocalizer.msg("titleNew", "Create filter")); } else { setTitle(mLocalizer.msg("titleEdit", "Edit filter {0}", filter.toString())); mFilterName = filter.toString(); } JPanel northPanel = new JPanel(); northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS)); mFilterNameTF = new JTextField(new PlainDocument() { public void insertString(int offset, String str, AttributeSet a) throws BadLocationException { str = str.replaceAll("[\\p{Punct}&&[^_]]", "_"); super.insertString(offset, str, a); } }, "", 30); mFilterNameTF.getDocument().addDocumentListener(this); JPanel panel = new JPanel(new BorderLayout(7, 7)); panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0)); panel.add(new JLabel(mLocalizer.msg("filterName", "Filter name:")), BorderLayout.WEST); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(mFilterNameTF, BorderLayout.WEST); panel.add(panel1, BorderLayout.CENTER); northPanel.add(panel); mFilterRuleTF = new JTextField(); mFilterRuleTF.getDocument().addDocumentListener(this); mFilterRuleTF.addCaretListener(this); panel = new JPanel(new BorderLayout(7, 7)); panel1 = new JPanel(new BorderLayout()); panel.add(new JLabel(mLocalizer.msg("ruleString", "Filter rule:")), BorderLayout.WEST); JLabel exampleLb = new JLabel( mLocalizer.msg("ruleExample", "example: component1 or (component2 and not component3)")); Font f = exampleLb.getFont(); exampleLb.setFont(new Font(f.getName(), Font.ITALIC | Font.PLAIN, f.getSize())); panel1.add(exampleLb, BorderLayout.WEST); panel.add(panel1, BorderLayout.CENTER); northPanel.add(panel); northPanel.add(mFilterRuleTF); mFilterRuleErrorLb = new JLabel(); mFilterRuleErrorLb.setForeground(Color.red); panel = new JPanel(new BorderLayout(7, 7)); panel.add(mFilterRuleErrorLb, BorderLayout.WEST); mColLb = new JLabel("0"); panel.add(mColLb, BorderLayout.EAST); northPanel.add(panel); JPanel filterComponentsPanel = new JPanel(new BorderLayout(7, 7)); filterComponentsPanel.add(DefaultComponentFactory.getInstance().createSeparator( mLocalizer.msg("componentsTitle", "Available filter components:")), BorderLayout.NORTH); JPanel btnPanel = new JPanel(new BorderLayout()); panel1 = new JPanel(new GridLayout(0, 1, 0, 7)); mNewBtn = new JButton(mLocalizer.msg("newButton", "new")); mEditBtn = new JButton(Localizer.getLocalization(Localizer.I18N_EDIT)); mRemoveBtn = new JButton(Localizer.getLocalization(Localizer.I18N_DELETE)); mNewBtn.addActionListener(this); mEditBtn.addActionListener(this); mRemoveBtn.addActionListener(this); panel1.add(mNewBtn); panel1.add(mEditBtn); panel1.add(mRemoveBtn); btnPanel.add(panel1, BorderLayout.NORTH); mComponentTableModel = new FilterTableModel(); mRuleTableBox = new JTable(mComponentTableModel); mRuleTableBox.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { updateBtns(); } }); mRuleTableBox.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() >= 2) { int row = mRuleTableBox.rowAtPoint(e.getPoint()); if (mRuleTableBox.getSelectedRow() == row && mEditBtn.isEnabled()) { actionPerformed(new ActionEvent(mEditBtn, ActionEvent.ACTION_PERFORMED, mEditBtn.getActionCommand())); } } } }); mRuleTableBox.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); mRuleTableBox.setShowGrid(false); mRuleTableBox.setShowVerticalLines(true); mRuleTableBox.getColumnModel().getColumn(0).setPreferredWidth(125); mRuleTableBox.getColumnModel().getColumn(1).setPreferredWidth(320); // mRuleTableBox.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // Dispatchs the KeyEvent to the RootPane for Closing the Dialog. // Needed for Java 1.4. mRuleTableBox.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { mRuleTableBox.getRootPane().dispatchEvent(e); } } }); JPanel ruleListBoxPanel = new JPanel(new BorderLayout()); ruleListBoxPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0)); ruleListBoxPanel.add(new JScrollPane(mRuleTableBox), BorderLayout.CENTER); filterComponentsPanel.add(btnPanel, BorderLayout.EAST); filterComponentsPanel.add(ruleListBoxPanel, BorderLayout.CENTER); ButtonBarBuilder2 bottomBar = Utilities.createFilterButtonBar(); mOkBtn = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); mOkBtn.addActionListener(this); getRootPane().setDefaultButton(mOkBtn); mCancelBtn = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL)); mCancelBtn.addActionListener(this); bottomBar.addButton(new JButton[] { mOkBtn, mCancelBtn }); contentPane.add(northPanel, BorderLayout.NORTH); contentPane.add(filterComponentsPanel, BorderLayout.CENTER); contentPane.add(bottomBar.getPanel(), BorderLayout.SOUTH); if (mFilter != null) { mFilterNameTF.setText(mFilter.toString()); mFilterRuleTF.setText(mFilter.getRule()); } FilterComponent[] fc = FilterComponentList.getInstance().getAvailableFilterComponents(); Arrays.sort(fc, new FilterComponent.NameComparator()); for (FilterComponent element : fc) { mComponentTableModel.addElement(element); } updateBtns(); Settings.layoutWindow("editFilterDlg", this, new Dimension(600, 300)); setVisible(true); }
From source file:org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { private JTextField nom; private DeviseField debit; private DeviseField credit; private JDate date; private ElementComboBox journal; public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); this.nom = new JTextField(); this.debit = new DeviseField(); this.credit = new DeviseField(); this.date = new JDate(); this.journal = new ElementComboBox(); // Mouvement /*/* ww w. j a v a 2 s . c o m*/ * JLabel labelMouvement = new JLabel("Mouvement"); this.add(labelMouvement, c); * * c.gridx ++; c.weightx = 1; this.add(idMouvement, c); */ // Journal JLabel labelJournal = new JLabel("Journal"); c.gridx = 0; this.add(labelJournal, c); c.gridx++; c.weightx = 1; this.add(this.journal, c); // Date JLabel labelDate = new JLabel("Date"); c.gridx++; this.add(labelDate, c); c.gridx++; c.weightx = 1; this.add(this.date, c); // libell JLabel labelNom = new JLabel("Libell"); c.gridy++; c.gridx = 0; this.add(labelNom, c); c.gridx++; c.weightx = 1; c.gridwidth = GridBagConstraints.REMAINDER; this.add(this.nom, c); // debit c.gridwidth = 1; JLabel labelDebit = new JLabel("Debit"); c.gridy++; c.gridx = 0; this.add(labelDebit, c); c.gridx++; c.weightx = 1; this.add(this.debit, c); this.debit.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if ((credit.getText().trim().length() != 0) && (debit.getText().trim().length() != 0)) { credit.setText(""); } } }); // Credit JLabel labelCredit = new JLabel("Credit"); c.gridx++; this.add(labelCredit, c); c.gridx++; c.weightx = 1; this.add(this.credit, c); this.credit.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if ((debit.getText().trim().length() != 0) && (credit.getText().trim().length() != 0)) { debit.setText(""); } } }); this.addSQLObject(this.nom, "NOM"); this.addSQLObject(this.debit, "DEBIT"); this.addSQLObject(this.credit, "CREDIT"); this.addRequiredSQLObject(this.date, "DATE"); this.addRequiredSQLObject(this.journal, "ID_JOURNAL"); } @Override public void select(SQLRowAccessor r) { super.select(r); if (r != null && r.getBoolean("VALIDE")) { this.nom.setEnabled(false); this.debit.setEnabled(false); this.credit.setEnabled(false); this.date.setEnabled(false); this.date.setEditable(false); this.journal.setEnabled(false); } } public void update() { SQLRow row = EcritureSQLElement.this.getTable().getRow(getSelectedID()); if (row.getBoolean("VALIDE")) { System.out.println("Impossible de modifier une ecriture valide"); } else { super.update(); } } }; }