List of usage examples for java.awt.event KeyEvent consume
public void consume()
From source file:net.sf.jabref.gui.AutoCompleteListener.java
/** * Start a new completion attempt/*w w w . j ava 2s . c o m*/ * (instead of treating a continuation of an existing word or an interrupt of the current word) */ private void startCompletion(StringBuffer currentword, KeyEvent e) { JTextComponent comp = (JTextComponent) e.getSource(); String[] completed = findCompletions(currentword.toString(), comp); String prefix = completer.getPrefix(); String cWord = (prefix != null) && (!prefix.isEmpty()) ? currentword.toString().substring(prefix.length()) : currentword.toString(); LOGGER.debug("StartCompletion currentword: >" + currentword + "'<' prefix: >" + prefix + "'<' cword: >" + cWord + '<'); int no = 0; // We use the first word in the array of completions. if ((completed != null) && (completed.length > 0)) { lastShownCompletion = 0; lastCompletions = completed; String sno = completed[no]; // these two lines obey the user's input //toSetIn = Character.toString(ch); //toSetIn = toSetIn.concat(sno.substring(cWord.length())); // BUT we obey the completion toSetIn = sno.substring(cWord.length() - 1); LOGGER.debug("toSetIn: >" + toSetIn + '<'); StringBuilder alltext = new StringBuilder(comp.getText()); int cp = comp.getCaretPosition(); alltext.insert(cp, toSetIn); comp.setText(alltext.toString()); comp.setCaretPosition(cp); comp.select(cp + 1, (cp + 1 + sno.length()) - cWord.length()); e.consume(); lastCaretPosition = comp.getCaretPosition(); char ch = e.getKeyChar(); LOGGER.debug("Appending >" + ch + '<'); if (cWord.length() <= 1) { lastBeginning = Character.toString(ch); } else { lastBeginning = cWord.substring(0, cWord.length() - 1).concat(Character.toString(ch)); } } }
From source file:ch.zhaw.iamp.rct.ui.GrammarWindow.java
private void removeTabIfPossilbe(KeyEvent event, JTextComponent component) { try {/*from w w w .j a v a2 s .c o m*/ Document doc = component.getDocument(); int caretPostion = component.getCaretPosition(); int lineStartIndex = doc.getText(0, caretPostion).lastIndexOf('\n') + 1; lineStartIndex = lineStartIndex < 0 ? 0 : lineStartIndex; lineStartIndex = lineStartIndex >= doc.getLength() ? doc.getLength() - 1 : lineStartIndex; int scanEndIndex = lineStartIndex + 4 <= doc.getLength() ? lineStartIndex + 4 : doc.getLength(); for (int i = 0; i < 4 && i + lineStartIndex < scanEndIndex; i++) { if (doc.getText(lineStartIndex, 1).matches(" ")) { doc.remove(lineStartIndex, 1); } else if (doc.getText(lineStartIndex, 1).matches("\t")) { doc.remove(lineStartIndex, 1); break; } else { break; } } event.consume(); } catch (BadLocationException ex) { System.out.println("Could not insert a tab: " + ex.getMessage()); } }
From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java
private void initGuiComponents() { fileListModel = new FileListTableModel(); fileList = new FileListTable(fileListModel); fileList.addKeyListener(new KeyAdapter() { @Override/*from w ww . ja va2 s . c o m*/ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { openSelectedFile(); e.consume(); } } }); fileList.setAutoCreateColumnsFromModel(true); fileList.setDropMode(DropMode.ON_OR_INSERT_ROWS); fileList.setFillsViewportHeight(true); fileList.setGridColor(new Color(-1)); fileListScrollPane = new JScrollPane(fileList); fileListScrollPane.setAutoscrolls(false); fileListScrollPane.setBackground(UIManager.getColor("TableHeader.background")); fileListScrollPane.setPreferredSize(new Dimension(100, 128)); fileListScrollPane.setEnabled(false); // // toolbar // final JToolBar toolBar1 = new JToolBar(); toolBar1.setBorderPainted(false); toolBar1.setFloatable(false); toolBar1.setRollover(true); toolBar1.putClientProperty("JToolBar.isRollover", Boolean.TRUE); homeDirectoryButton = new JButton(); homeDirectoryButton.setHorizontalAlignment(2); homeDirectoryButton.setIcon(GUIHelper.HOME_ICON); homeDirectoryButton.setMargin(new Insets(3, 3, 3, 3)); homeDirectoryButton.setText(""); homeDirectoryButton.setToolTipText("Go to home directory"); homeDirectoryButton.setEnabled(false); toolBar1.add(homeDirectoryButton); refreshButton = new JButton(); refreshButton.setHorizontalAlignment(2); refreshButton.setIcon(new ImageIcon(getClass().getResource("/images/refresh.gif"))); refreshButton.setMargin(new Insets(3, 3, 3, 3)); refreshButton.setText(""); refreshButton.setToolTipText("Refresh current directory listing"); refreshButton.setEnabled(false); toolBar1.add(refreshButton); upDirectoryButton = new JButton(); upDirectoryButton.setHideActionText(false); upDirectoryButton.setHorizontalAlignment(2); upDirectoryButton.setIcon(GUIHelper.UP_DIR_ICON); upDirectoryButton.setMargin(new Insets(3, 3, 3, 3)); upDirectoryButton.setToolTipText("Up"); upDirectoryButton.setEnabled(false); toolBar1.add(upDirectoryButton); browseDirectoryButton = new JButton(); browseDirectoryButton.setHideActionText(false); browseDirectoryButton.setHorizontalAlignment(2); browseDirectoryButton.setIcon(GUIHelper.DIRECTORY_ICON); browseDirectoryButton.setMargin(new Insets(3, 3, 3, 3)); browseDirectoryButton.setToolTipText(BROWSE_LFS_TEXT); browseDirectoryButton.setEnabled(false); toolBar1.add(browseDirectoryButton); profileModel = new ProfileComboBoxModel(); profileSelectionCombo = new JComboBox(profileModel); profileSelectionCombo.setEnabled(false); profileSelectionCombo.setToolTipText("Select a namespace profile"); profileSelectionCombo.setPrototypeDisplayValue("#"); pathCombo = new JComboBox(); pathCombo.setEditable(false); pathCombo.setEnabled(false); pathCombo.setToolTipText("Current directory path"); pathCombo.setPrototypeDisplayValue("#"); sslButton = new JButton(); sslButton.setAlignmentY(0.0f); sslButton.setBorderPainted(false); sslButton.setHorizontalAlignment(2); sslButton.setHorizontalTextPosition(11); sslButton.setIcon(new ImageIcon(getClass().getResource("/images/lockedstate.gif"))); sslButton.setMargin(new Insets(0, 0, 0, 0)); sslButton.setMaximumSize(new Dimension(20, 20)); sslButton.setMinimumSize(new Dimension(20, 20)); sslButton.setPreferredSize(new Dimension(20, 20)); sslButton.setText(""); sslButton.setToolTipText("View certificate"); sslButton.setEnabled(false); // // profile and toolbar buttons // JPanel profileAndToolbarPanel = new FixedHeightPanel(); profileAndToolbarPanel.setLayout(new BoxLayout(profileAndToolbarPanel, BoxLayout.X_AXIS)); profileAndToolbarPanel.add(profileSelectionCombo); profileAndToolbarPanel.add(Box.createHorizontalStrut(25)); profileAndToolbarPanel.add(toolBar1); // // Path & SSLCert button // JPanel pathPanel = new FixedHeightPanel(); pathPanel.setLayout(new BoxLayout(pathPanel, BoxLayout.X_AXIS)); pathCombo.setAlignmentY(CENTER_ALIGNMENT); pathPanel.add(pathCombo); pathPanel.add(Box.createHorizontalStrut(5)); sslButton.setAlignmentY(CENTER_ALIGNMENT); pathPanel.add(sslButton); // // Put it all together // setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(profileAndToolbarPanel); add(Box.createVerticalStrut(5)); add(pathPanel); add(Box.createVerticalStrut(5)); add(fileListScrollPane); setBorder(new EmptyBorder(12, 12, 12, 12)); }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
public MindMapPanel(final MindMapPanelController controller) { super(null);// ww w . j a v a 2 s . c o m this.textEditorPanel.setLayout(new BorderLayout(0, 0)); this.controller = controller; this.config = new MindMapPanelConfig(controller.provideConfigForMindMapPanel(this), false); this.textEditor.setMargin(new Insets(5, 5, 5, 5)); this.textEditor.setBorder(BorderFactory.createEtchedBorder()); this.textEditor.setTabSize(4); this.textEditor.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_ENTER: { e.consume(); } break; case KeyEvent.VK_TAB: { if ((e.getModifiers() & ALL_SUPPORTED_MODIFIERS) == 0) { e.consume(); final Topic edited = elementUnderEdit.getModel(); final int[] topicPosition = edited.getPositionPath(); endEdit(true); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final Topic theTopic = model.findForPositionPath(topicPosition); if (theTopic != null) { makeNewChildAndStartEdit(theTopic, null); } } }); } } break; default: break; } } @Override public void keyTyped(final KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_ENTER) { if ((e.getModifiers() & ALL_SUPPORTED_MODIFIERS) == 0) { e.consume(); endEdit(true); } else { e.consume(); textEditor.insert("\n", textEditor.getCaretPosition()); //NOI18N } } } @Override public void keyReleased(final KeyEvent e) { if (config.isKeyEvent(MindMapPanelConfig.KEY_CANCEL_EDIT, e)) { e.consume(); final Topic edited = elementUnderEdit == null ? null : elementUnderEdit.getModel(); endEdit(false); if (edited != null && edited.canBeLost()) { deleteTopics(edited); if (pathToPrevTopicBeforeEdit != null) { final int[] path = pathToPrevTopicBeforeEdit; pathToPrevTopicBeforeEdit = null; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final Topic topic = model.findForPositionPath(path); if (topic != null) { select(topic, false); } } }); } } } } }); this.textEditor.getDocument().addDocumentListener(new DocumentListener() { private void updateEditorPanelSize(final Dimension newSize) { final Dimension editorPanelMinSize = textEditorPanel.getMinimumSize(); final Dimension newDimension = new Dimension(Math.max(editorPanelMinSize.width, newSize.width), Math.max(editorPanelMinSize.height, newSize.height)); textEditorPanel.setSize(newDimension); textEditorPanel.repaint(); } @Override public void insertUpdate(DocumentEvent e) { updateEditorPanelSize(textEditor.getPreferredSize()); } @Override public void removeUpdate(DocumentEvent e) { updateEditorPanelSize(textEditor.getPreferredSize()); } @Override public void changedUpdate(DocumentEvent e) { updateEditorPanelSize(textEditor.getPreferredSize()); } }); this.textEditorPanel.add(this.textEditor, BorderLayout.CENTER); super.setOpaque(true); final KeyAdapter keyAdapter = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { if (config.isKeyEvent(MindMapPanelConfig.KEY_ADD_CHILD_AND_START_EDIT, e)) { if (!selectedTopics.isEmpty()) { makeNewChildAndStartEdit(selectedTopics.get(0), null); } } else if (config.isKeyEvent(MindMapPanelConfig.KEY_ADD_SIBLING_AND_START_EDIT, e)) { if (!hasActiveEditor() && hasOnlyTopicSelected()) { final Topic baseTopic = selectedTopics.get(0); makeNewChildAndStartEdit(baseTopic.getParent() == null ? baseTopic : baseTopic.getParent(), baseTopic); } } else if (config.isKeyEvent(MindMapPanelConfig.KEY_FOCUS_ROOT_OR_START_EDIT, e)) { if (!hasSelectedTopics()) { select(getModel().getRoot(), false); } else if (hasOnlyTopicSelected()) { startEdit((AbstractElement) selectedTopics.get(0).getPayload()); } } } @Override public void keyReleased(final KeyEvent e) { if (config.isKeyEvent(MindMapPanelConfig.KEY_DELETE_TOPIC, e)) { e.consume(); deleteSelectedTopics(); } else if (config.isKeyEventDetected(e, MindMapPanelConfig.KEY_FOCUS_MOVE_LEFT, MindMapPanelConfig.KEY_FOCUS_MOVE_RIGHT, MindMapPanelConfig.KEY_FOCUS_MOVE_UP, MindMapPanelConfig.KEY_FOCUS_MOVE_DOWN)) { e.consume(); processMoveFocusByKey(e); } } }; this.setFocusTraversalKeysEnabled(false); final MindMapPanel theInstance = this; final MouseAdapter adapter = new MouseAdapter() { @Override public void mouseEntered(final MouseEvent e) { setCursor(Cursor.getDefaultCursor()); } @Override public void mouseMoved(final MouseEvent e) { if (!controller.isMouseMoveProcessingAllowed(theInstance)) { return; } final AbstractElement element = findTopicUnderPoint(e.getPoint()); if (element == null) { setCursor(Cursor.getDefaultCursor()); setToolTipText(null); } else { final ElementPart part = element.findPartForPoint(e.getPoint()); setCursor(part == ElementPart.ICONS || part == ElementPart.COLLAPSATOR ? Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) : Cursor.getDefaultCursor()); if (part == ElementPart.ICONS) { final Extra<?> extra = element.getIconBlock().findExtraForPoint( e.getPoint().getX() - element.getBounds().getX(), e.getPoint().getY() - element.getBounds().getY()); if (extra != null) { setToolTipText(makeHtmlTooltipForExtra(extra)); } else { setToolTipText(null); } } else { setToolTipText(null); } } } @Override public void mousePressed(final MouseEvent e) { if (!controller.isMouseClickProcessingAllowed(theInstance)) { return; } try { if (e.isPopupTrigger()) { mouseDragSelection = null; MindMap theMap = model; AbstractElement element = null; if (theMap != null) { element = findTopicUnderPoint(e.getPoint()); } processPopUp(e.getPoint(), element); e.consume(); } else { endEdit(elementUnderEdit != null); mouseDragSelection = null; } } catch (Exception ex) { LOGGER.error("Error during mousePressed()", ex); } } @Override public void mouseReleased(final MouseEvent e) { if (!controller.isMouseClickProcessingAllowed(theInstance)) { return; } try { if (draggedElement != null) { draggedElement.updatePosition(e.getPoint()); if (endDragOfElement(draggedElement, destinationElement)) { updateView(true); } } else if (mouseDragSelection != null) { final List<Topic> covered = mouseDragSelection.getAllSelectedElements(model); if (e.isShiftDown()) { for (final Topic m : covered) { select(m, false); } } else if (e.isControlDown()) { for (final Topic m : covered) { select(m, true); } } else { removeAllSelection(); for (final Topic m : covered) { select(m, false); } } } else if (e.isPopupTrigger()) { mouseDragSelection = null; MindMap theMap = model; AbstractElement element = null; if (theMap != null) { element = findTopicUnderPoint(e.getPoint()); } processPopUp(e.getPoint(), element); e.consume(); } } catch (Exception ex) { LOGGER.error("Error during mouseReleased()", ex); } finally { mouseDragSelection = null; draggedElement = null; destinationElement = null; repaint(); } } @Override public void mouseDragged(final MouseEvent e) { if (!controller.isMouseMoveProcessingAllowed(theInstance)) { return; } scrollRectToVisible(new Rectangle(e.getX(), e.getY(), 1, 1)); if (!popupMenuActive) { if (draggedElement == null && mouseDragSelection == null) { final AbstractElement elementUnderMouse = findTopicUnderPoint(e.getPoint()); if (elementUnderMouse == null) { MindMap theMap = model; if (theMap != null) { final AbstractElement element = findTopicUnderPoint(e.getPoint()); if (controller.isSelectionAllowed(theInstance) && element == null) { mouseDragSelection = new MouseSelectedArea(e.getPoint()); } } } else if (controller.isElementDragAllowed(theInstance)) { if (elementUnderMouse.isMoveable()) { selectedTopics.clear(); final Point mouseOffset = new Point( (int) Math .round(e.getPoint().getX() - elementUnderMouse.getBounds().getX()), (int) Math .round(e.getPoint().getY() - elementUnderMouse.getBounds().getY())); draggedElement = new DraggedElement(elementUnderMouse, config, mouseOffset, e.isControlDown() || e.isMetaDown() ? DraggedElement.Modifier.MAKE_JUMP : DraggedElement.Modifier.NONE); draggedElement.updatePosition(e.getPoint()); findDestinationElementForDragged(); } else { draggedElement = null; } repaint(); } } else if (mouseDragSelection != null) { if (controller.isSelectionAllowed(theInstance)) { mouseDragSelection.update(e); } else { mouseDragSelection = null; } repaint(); } else if (draggedElement != null) { if (controller.isElementDragAllowed(theInstance)) { draggedElement.updatePosition(e.getPoint()); findDestinationElementForDragged(); } else { draggedElement = null; } repaint(); } } else { mouseDragSelection = null; } } @Override public void mouseWheelMoved(final MouseWheelEvent e) { if (controller.isMouseWheelProcessingAllowed(theInstance)) { mouseDragSelection = null; draggedElement = null; final MindMapPanelConfig theConfig = config; if (!e.isConsumed() && (theConfig != null && ((e.getModifiers() & theConfig.getScaleModifiers()) == theConfig .getScaleModifiers()))) { endEdit(elementUnderEdit != null); setScale( Math.max(0.3d, Math.min(getScale() + (SCALE_STEP * -e.getWheelRotation()), 10.0d))); updateView(false); e.consume(); } else { sendToParent(e); } } } @Override public void mouseClicked(final MouseEvent e) { if (!controller.isMouseClickProcessingAllowed(theInstance)) { return; } mouseDragSelection = null; draggedElement = null; MindMap theMap = model; AbstractElement element = null; if (theMap != null) { element = findTopicUnderPoint(e.getPoint()); } if (element != null) { final ElementPart part = element.findPartForPoint(e.getPoint()); if (part == ElementPart.COLLAPSATOR) { removeAllSelection(); if (element.isCollapsed()) { ((AbstractCollapsableElement) element).setCollapse(false); if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) { ((AbstractCollapsableElement) element).collapseAllFirstLevelChildren(); } } else { ((AbstractCollapsableElement) element).setCollapse(true); } invalidate(); fireNotificationMindMapChanged(); repaint(); } else if (part != ElementPart.ICONS && e.getClickCount() > 1) { startEdit(element); } else if (part == ElementPart.ICONS) { final Extra<?> extra = element.getIconBlock().findExtraForPoint( e.getPoint().getX() - element.getBounds().getX(), e.getPoint().getY() - element.getBounds().getY()); if (extra != null) { fireNotificationClickOnExtra(element.getModel(), e.getClickCount(), extra); } } else { if (!e.isControlDown()) { // only removeAllSelection(); select(element.getModel(), false); } else // group if (selectedTopics.isEmpty()) { select(element.getModel(), false); } else { select(element.getModel(), true); } } } } }; addMouseWheelListener(adapter); addMouseListener(adapter); addMouseMotionListener(adapter); addKeyListener(keyAdapter); this.textEditorPanel.setVisible(false); this.add(this.textEditorPanel); }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java
/** * When CTRL+Z is pressed invokes the <code>ChatWritePanel.undo()</code> * method, when CTRL+R is pressed invokes the * <code>ChatWritePanel.redo()</code> method. * * @param e the <tt>KeyEvent</tt> that notified us *//*from ww w. j a v a2s . co m*/ public void keyPressed(KeyEvent e) { if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK && (e.getKeyCode() == KeyEvent.VK_Z) // And not ALT(right ALT gives CTRL + ALT). && (e.getModifiers() & KeyEvent.ALT_MASK) != KeyEvent.ALT_MASK) { if (undo.canUndo()) undo(); } else if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK && (e.getKeyCode() == KeyEvent.VK_R) // And not ALT(right ALT gives CTRL + ALT). && (e.getModifiers() & KeyEvent.ALT_MASK) != KeyEvent.ALT_MASK) { if (undo.canRedo()) redo(); } else if (e.getKeyCode() == KeyEvent.VK_TAB) { if (!(chatPanel.getChatSession() instanceof ConferenceChatSession)) return; e.consume(); int index = ((JEditorPane) e.getSource()).getCaretPosition(); StringBuffer message = new StringBuffer(chatPanel.getMessage()); int position = index - 1; while (position > 0 && (message.charAt(position) != ' ')) { position--; } if (position != 0) position++; String sequence = message.substring(position, index); if (sequence.length() <= 0) { // Do not look for matching contacts if the matching pattern is // 0 chars long, since all contacts will match. return; } Iterator<ChatContact<?>> iter = chatPanel.getChatSession().getParticipants(); ArrayList<String> contacts = new ArrayList<String>(); while (iter.hasNext()) { ChatContact<?> c = iter.next(); if (c.getName().length() >= (index - position) && c.getName().substring(0, index - position).equals(sequence)) { message.replace(position, index, c.getName().substring(0, index - position)); contacts.add(c.getName()); } } if (contacts.size() > 1) { char key = contacts.get(0).charAt(index - position - 1); int pos = index - position - 1; boolean flag = true; while (flag) { try { for (String name : contacts) { if (key != name.charAt(pos)) { flag = false; } } if (flag) { pos++; key = contacts.get(0).charAt(pos); } } catch (IndexOutOfBoundsException exp) { flag = false; } } message.replace(position, index, contacts.get(0).substring(0, pos)); Iterator<String> contactIter = contacts.iterator(); String contactList = "<DIV align='left'><h5>"; while (contactIter.hasNext()) { contactList += contactIter.next() + " "; } contactList += "</h5></DIV>"; chatPanel.getChatConversationPanel().appendMessageToEnd(contactList, ChatHtmlUtils.HTML_CONTENT_TYPE); } else if (contacts.size() == 1) { String limiter = (position == 0) ? ": " : ""; message.replace(position, index, contacts.get(0) + limiter); } try { ((JEditorPane) e.getSource()).getDocument().remove(0, ((JEditorPane) e.getSource()).getDocument().getLength()); ((JEditorPane) e.getSource()).getDocument().insertString(0, message.toString(), null); } catch (BadLocationException ex) { ex.printStackTrace(); } } else if (e.getKeyCode() == KeyEvent.VK_UP) { // Only enters editing mode if the write panel is empty in // order not to lose the current message contents, if any. if (this.chatPanel.getLastSentMessageUID() != null && this.chatPanel.isWriteAreaEmpty()) { this.chatPanel.startLastMessageCorrection(); e.consume(); } } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { if (chatPanel.isMessageCorrectionActive()) { Document doc = editorPane.getDocument(); if (editorPane.getCaretPosition() == doc.getLength()) { chatPanel.stopMessageCorrection(); } } } }
From source file:net.sf.jabref.gui.AutoCompleteListener.java
@Override public void keyTyped(KeyEvent e) { LOGGER.debug("key typed event caught " + e.getKeyCode()); char ch = e.getKeyChar(); if (ch == '\n') { // this case is handled at keyPressed(e) return;// ww w .j a v a 2 s . co m } if ((e.getModifiers() | InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) { // plain key or SHIFT + key is pressed, no handling of CTRL+key, META+key, ... if (Character.isLetter(ch) || Character.isDigit(ch) || (Character.isWhitespace(ch) && completer.isSingleUnitField())) { JTextComponent comp = (JTextComponent) e.getSource(); if (toSetIn == null) { LOGGER.debug("toSetIn is null"); } else { LOGGER.debug("toSetIn: >" + toSetIn + '<'); } // The case-insensitive system is a bit tricky here // If keyword is "TODO" and user types "tO", then this is treated as "continue" as the "O" matches the "O" // If keyword is "TODO" and user types "To", then this is treated as "discont" as the "o" does NOT match the "O". if ((toSetIn != null) && (toSetIn.length() > 1) && (ch == toSetIn.charAt(1))) { // User continues on the word that was suggested. LOGGER.debug("cont"); toSetIn = toSetIn.substring(1); if (!toSetIn.isEmpty()) { int cp = comp.getCaretPosition(); //comp.setCaretPosition(cp+1-toSetIn.); //System.out.println(cp-toSetIn.length()+" - "+cp); comp.select((cp + 1) - toSetIn.length(), cp); lastBeginning = lastBeginning + ch; e.consume(); lastCaretPosition = comp.getCaretPosition(); //System.out.println("Added char: '"+toSetIn+"'"); //System.out.println("LastBeginning: '"+lastBeginning+"'"); lastCompletions = findCompletions(lastBeginning, comp); lastShownCompletion = 0; for (int i = 0; i < lastCompletions.length; i++) { String lastCompletion = lastCompletions[i]; //System.out.println("Completion["+i+"] = "+lastCompletion); if (lastCompletion.endsWith(toSetIn)) { lastShownCompletion = i; break; } } //System.out.println("Index now: "+lastShownCompletion); if (toSetIn.length() < 2) { // User typed the last character of the autocompleted word // We have to replace the automcompletion word by the typed word. // This helps if the user presses "space" after the completion // "space" indicates that the user does NOT want the autocompletion, // but the typed word String text = comp.getText(); comp.setText(text.substring(0, lastCaretPosition - lastBeginning.length()) + lastBeginning + text.substring(lastCaretPosition)); // there is no selected text, therefore we are not updating the selection toSetIn = null; } return; } } if ((toSetIn != null) && ((toSetIn.length() <= 1) || (ch != toSetIn.charAt(1)))) { // User discontinues the word that was suggested. lastBeginning = lastBeginning + ch; LOGGER.debug("discont toSetIn: >" + toSetIn + "'<' lastBeginning: >" + lastBeginning + '<'); String[] completed = findCompletions(lastBeginning, comp); if ((completed != null) && (completed.length > 0)) { lastShownCompletion = 0; lastCompletions = completed; String sno = completed[0]; // toSetIn = string used for autocompletion last time // this string has to be removed // lastCaretPosition is the position of the caret after toSetIn. int lastLen = toSetIn.length() - 1; toSetIn = sno.substring(lastBeginning.length() - 1); String text = comp.getText(); //Util.pr(""+lastLen); //we do not use toSetIn as we want to obey the casing of "sno" comp.setText(text.substring(0, (lastCaretPosition - lastLen - lastBeginning.length()) + 1) + sno + text.substring(lastCaretPosition)); int startSelect = (lastCaretPosition + 1) - lastLen; int endSelect = (lastCaretPosition + toSetIn.length()) - lastLen; comp.select(startSelect, endSelect); lastCaretPosition = comp.getCaretPosition(); e.consume(); return; } else { setUnmodifiedTypedLetters(comp, true, false); e.consume(); toSetIn = null; return; } } LOGGER.debug("case else"); comp.replaceSelection(""); StringBuffer currentword = getCurrentWord(comp); if (currentword == null) { currentword = new StringBuffer(); } // only "real characters" end up here assert (!Character.isISOControl(ch)); currentword.append(ch); startCompletion(currentword, e); return; } else { if (Character.isWhitespace(ch)) { assert (!completer.isSingleUnitField()); LOGGER.debug("whitespace && !singleUnitField"); // start a new search if end-of-field is reached // replace displayed letters with typed letters setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, true); resetAutoCompletion(); return; } LOGGER.debug("No letter/digit/whitespace or CHAR_UNDEFINED"); // replace displayed letters with typed letters setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, !Character.isISOControl(ch)); resetAutoCompletion(); return; } } resetAutoCompletion(); }
From source file:CodePointInputMethod.java
/** * This is the input method's main routine. The composed text is stored * in buffer.//from ww w.j a va 2 s . com */ public void dispatchEvent(AWTEvent event) { // This input method handles KeyEvent only. if (!(event instanceof KeyEvent)) { return; } KeyEvent e = (KeyEvent) event; int eventID = event.getID(); boolean notInCompositionMode = buffer.length() == 0; if (eventID == KeyEvent.KEY_PRESSED) { // If we are not in composition mode, pass through if (notInCompositionMode) { return; } switch (e.getKeyCode()) { case KeyEvent.VK_LEFT: moveCaretLeft(); break; case KeyEvent.VK_RIGHT: moveCaretRight(); break; } } else if (eventID == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); // If we are not in composition mode, wait a back slash if (notInCompositionMode) { // If the type character is not a back slash, pass through if (c != '\\') { return; } startComposition(); // Enter to composition mode } else { switch (c) { case ' ': // Exit from composition mode finishComposition(); break; case '\u007f': // Delete deleteCharacter(); break; case '\b': // BackSpace deletePreviousCharacter(); break; case '\u001b': // Escape cancelComposition(); break; case '\n': // Return case '\t': // Tab sendCommittedText(); break; default: composeUnicodeEscape(c); break; } } } else { // KeyEvent.KEY_RELEASED // If we are not in composition mode, pass through if (notInCompositionMode) { return; } } e.consume(); }
From source file:net.sf.jabref.gui.autocompleter.AutoCompleteListener.java
@Override public void keyTyped(KeyEvent e) { LOGGER.debug("key typed event caught " + e.getKeyCode()); char ch = e.getKeyChar(); if (ch == '\n') { // this case is handled at keyPressed(e) return;/*from w w w . j a va 2 s. co m*/ } // don't do auto completion inside words if (!atEndOfWord((JTextComponent) e.getSource())) { return; } if ((e.getModifiers() | InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) { // plain key or SHIFT + key is pressed, no handling of CTRL+key, META+key, ... if (Character.isLetter(ch) || Character.isDigit(ch) || (Character.isWhitespace(ch) && completer.isSingleUnitField())) { JTextComponent comp = (JTextComponent) e.getSource(); if (toSetIn == null) { LOGGER.debug("toSetIn is null"); } else { LOGGER.debug("toSetIn: >" + toSetIn + '<'); } // The case-insensitive system is a bit tricky here // If keyword is "TODO" and user types "tO", then this is treated as "continue" as the "O" matches the "O" // If keyword is "TODO" and user types "To", then this is treated as "discont" as the "o" does NOT match the "O". if ((toSetIn != null) && (toSetIn.length() > 1) && (ch == toSetIn.charAt(1))) { // User continues on the word that was suggested. LOGGER.debug("cont"); toSetIn = toSetIn.substring(1); if (!toSetIn.isEmpty()) { int cp = comp.getCaretPosition(); //comp.setCaretPosition(cp+1-toSetIn.); comp.select((cp + 1) - toSetIn.length(), cp); lastBeginning = lastBeginning + ch; e.consume(); lastCaretPosition = comp.getCaretPosition(); lastCompletions = findCompletions(lastBeginning); lastShownCompletion = 0; for (int i = 0; i < lastCompletions.size(); i++) { String lastCompletion = lastCompletions.get(i); if (lastCompletion.endsWith(toSetIn)) { lastShownCompletion = i; break; } } if (toSetIn.length() < 2) { // User typed the last character of the autocompleted word // We have to replace the automcompletion word by the typed word. // This helps if the user presses "space" after the completion // "space" indicates that the user does NOT want the autocompletion, // but the typed word String text = comp.getText(); comp.setText(text.substring(0, lastCaretPosition - lastBeginning.length()) + lastBeginning + text.substring(lastCaretPosition)); // there is no selected text, therefore we are not updating the selection toSetIn = null; } return; } } if ((toSetIn != null) && ((toSetIn.length() <= 1) || (ch != toSetIn.charAt(1)))) { // User discontinues the word that was suggested. lastBeginning = lastBeginning + ch; LOGGER.debug("discont toSetIn: >" + toSetIn + "'<' lastBeginning: >" + lastBeginning + '<'); List<String> completed = findCompletions(lastBeginning); if ((completed != null) && (!completed.isEmpty())) { lastShownCompletion = 0; lastCompletions = completed; String sno = completed.get(0); // toSetIn = string used for autocompletion last time // this string has to be removed // lastCaretPosition is the position of the caret after toSetIn. int lastLen = toSetIn.length() - 1; toSetIn = sno.substring(lastBeginning.length() - 1); String text = comp.getText(); //we do not use toSetIn as we want to obey the casing of "sno" comp.setText(text.substring(0, (lastCaretPosition - lastLen - lastBeginning.length()) + 1) + sno + text.substring(lastCaretPosition)); int startSelect = (lastCaretPosition + 1) - lastLen; int endSelect = (lastCaretPosition + toSetIn.length()) - lastLen; comp.select(startSelect, endSelect); lastCaretPosition = comp.getCaretPosition(); e.consume(); return; } else { setUnmodifiedTypedLetters(comp, true, false); e.consume(); toSetIn = null; return; } } LOGGER.debug("case else"); comp.replaceSelection(""); StringBuffer currentword = getCurrentWord(comp); // only "real characters" end up here assert (!Character.isISOControl(ch)); currentword.append(ch); startCompletion(currentword, e); return; } else { if (Character.isWhitespace(ch)) { assert (!completer.isSingleUnitField()); LOGGER.debug("whitespace && !singleUnitField"); // start a new search if end-of-field is reached // replace displayed letters with typed letters setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, true); resetAutoCompletion(); return; } LOGGER.debug("No letter/digit/whitespace or CHAR_UNDEFINED"); // replace displayed letters with typed letters setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, !Character.isISOControl(ch)); resetAutoCompletion(); return; } } resetAutoCompletion(); }
From source file:it.imtech.metadata.MetaUtility.java
/** * Metodo adibito alla creazione dinamica ricorsiva dell'interfaccia dei * metadati/* w ww . j a v a 2 s . c o m*/ * * @param submetadatas Map contente i metadati e i sottolivelli di metadati * @param vocabularies Map contenente i dati contenuti nel file xml * vocabulary.xml * @param parent Jpanel nel quale devono venir inseriti i metadati * @param level Livello corrente */ public void create_metadata_view(Map<Object, Metadata> submetadatas, JPanel parent, int level, final String panelname) throws Exception { ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); int lenght = submetadatas.size(); int labelwidth = 220; int i = 0; JButton addcontribute = null; for (Map.Entry<Object, Metadata> kv : submetadatas.entrySet()) { ArrayList<Component> tabobjects = new ArrayList<Component>(); if (kv.getValue().MID == 17 || kv.getValue().MID == 23 || kv.getValue().MID == 18 || kv.getValue().MID == 137) { continue; } //Crea un jpanel nuovo e fa appen su parent JPanel innerPanel = new JPanel(new MigLayout("fillx, insets 1 1 1 1")); innerPanel.setName("pannello" + level + i); i++; String datatype = kv.getValue().datatype.toString(); if (kv.getValue().MID == 45) { JPanel choice = new JPanel(new MigLayout()); JComboBox combo = addClassificationChoice(choice, kv.getValue().sequence, panelname); JLabel labelc = new JLabel(); labelc.setText(Utility.getBundleString("selectclassif", bundle)); labelc.setPreferredSize(new Dimension(100, 20)); choice.add(labelc); findLastClassification(panelname); if (last_classification != 0 && classificationRemoveButton == null) { logger.info("Removing last clasification"); classificationRemoveButton = new JButton("-"); classificationRemoveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); removeClassificationToMetadata(panelname); BookImporter.getInstance().refreshMetadataTab(false, panelname); findLastClassification(panelname); //update last_classification BookImporter.getInstance().setCursor(null); } }); if (Integer.parseInt(kv.getValue().sequence) == last_classification) { choice.add(classificationRemoveButton, "wrap, width :50:"); } } if (classificationAddButton == null) { logger.info("Adding a new classification"); choice.add(combo, "width 100:600:600"); classificationAddButton = new JButton("+"); classificationAddButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); addClassificationToMetadata(panelname); BookImporter.getInstance().refreshMetadataTab(false, panelname); BookImporter.getInstance().setCursor(null); } }); choice.add(classificationAddButton, "width :50:"); } else { //choice.add(combo, "wrap,width 100:700:700"); choice.add(combo, "width 100:700:700"); if (Integer.parseInt(kv.getValue().sequence) == last_classification) { choice.add(classificationRemoveButton, "wrap, width :50"); } } parent.add(choice, "wrap,width 100:700:700"); classificationMID = kv.getValue().MID; innerPanel.setName(panelname + "---ImPannelloClassif---" + kv.getValue().sequence); try { addClassification(innerPanel, classificationMID, kv.getValue().sequence, panelname); } catch (Exception ex) { logger.error("Errore nell'aggiunta delle classificazioni"); } parent.add(innerPanel, "wrap, growx"); BookImporter.policy.addIndexedComponent(combo); continue; } if (datatype.equals("Node")) { JLabel label = new JLabel(); label.setText(kv.getValue().description); label.setPreferredSize(new Dimension(100, 20)); int size = 16 - (level * 2); Font myFont = new Font("MS Sans Serif", Font.PLAIN, size); label.setFont(myFont); if (Integer.toString(kv.getValue().MID).equals("11")) { JPanel temppanel = new JPanel(new MigLayout()); //update last_contribute findLastContribute(panelname); if (last_contribute != 0 && removeContribute == null) { logger.info("Removing last contribute"); removeContribute = new JButton("-"); removeContribute.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { BookImporter.getInstance() .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); removeContributorToMetadata(panelname); BookImporter.getInstance().refreshMetadataTab(false, panelname); BookImporter.getInstance().setCursor(null); } }); if (!kv.getValue().sequence.equals("")) { if (Integer.parseInt(kv.getValue().sequence) == last_contribute) { innerPanel.add(removeContribute, "width :50:"); } } } if (addcontribute == null) { logger.info("Adding a new contribute"); addcontribute = new JButton("+"); addcontribute.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { BookImporter.getInstance() .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); addContributorToMetadata(panelname); BookImporter.getInstance().refreshMetadataTab(false, panelname); BookImporter.getInstance().setCursor(null); } }); temppanel.add(label, " width :200:"); temppanel.add(addcontribute, "width :50:"); innerPanel.add(temppanel, "wrap, growx"); } else { temppanel.add(label, " width :200:"); findLastContribute(panelname); if (!kv.getValue().sequence.equals("")) { if (Integer.parseInt(kv.getValue().sequence) == last_contribute) { temppanel.add(removeContribute, "width :50:"); } } innerPanel.add(temppanel, "wrap, growx"); } } else if (Integer.toString(kv.getValue().MID).equals("115")) { logger.info("Devo gestire una provenience!"); } } else { String title = ""; if (kv.getValue().mandatory.equals("Y") || kv.getValue().MID == 14 || kv.getValue().MID == 15) { title = kv.getValue().description + " *"; } else { title = kv.getValue().description; } innerPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title, TitledBorder.LEFT, TitledBorder.TOP)); if (datatype.equals("Vocabulary")) { TreeMap<String, String> entryCombo = new TreeMap<String, String>(); int index = 0; String selected = null; if (!Integer.toString(kv.getValue().MID).equals("8")) entryCombo.put(Utility.getBundleString("comboselect", bundle), Utility.getBundleString("comboselect", bundle)); for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) { String tempmid = Integer.toString(kv.getValue().MID); if (Integer.toString(kv.getValue().MID_parent).equals("11") || Integer.toString(kv.getValue().MID_parent).equals("13")) { String[] testmid = tempmid.split("---"); tempmid = testmid[0]; } if (vc.getKey().equals(tempmid)) { TreeMap<String, VocEntry> iEntry = vc.getValue(); for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) { entryCombo.put(ivc.getValue().description, ivc.getValue().ID); if (kv.getValue().value != null) { if (kv.getValue().value.equals(ivc.getValue().ID)) { selected = ivc.getValue().ID; } } index++; } } } final ComboMapImpl model = new ComboMapImpl(); model.setVocabularyCombo(true); model.putAll(entryCombo); final JComboBox voc = new javax.swing.JComboBox(model); model.specialRenderCombo(voc); if (Integer.toString(kv.getValue().MID_parent).equals("11") || Integer.toString(kv.getValue().MID_parent).equals("13")) { voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence); } else { voc.setName("MID_" + Integer.toString(kv.getValue().MID)); } if (Integer.toString(kv.getValue().MID).equals("8") && selected == null) selected = "44"; selected = (selected == null) ? Utility.getBundleString("comboselect", bundle) : selected; for (int k = 0; k < voc.getItemCount(); k++) { Map.Entry<String, String> el = (Map.Entry<String, String>) voc.getItemAt(k); if (el.getValue().equals(selected)) voc.setSelectedIndex(k); } voc.setPreferredSize(new Dimension(150, 30)); innerPanel.add(voc, "wrap, width :400:"); tabobjects.add(voc); } else if (datatype.equals("CharacterString") || datatype.equals("GPS")) { final JTextArea textField = new javax.swing.JTextArea(); if (Integer.toString(kv.getValue().MID_parent).equals("11") || Integer.toString(kv.getValue().MID_parent).equals("13")) { textField.setName( "MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence); } else { textField.setName("MID_" + Integer.toString(kv.getValue().MID)); } textField.setPreferredSize(new Dimension(230, 0)); textField.setText(kv.getValue().value); textField.setLineWrap(true); textField.setWrapStyleWord(true); innerPanel.add(textField, "wrap, width :300:"); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_TAB) { if (e.getModifiers() > 0) { textField.transferFocusBackward(); } else { textField.transferFocus(); } e.consume(); } } }); tabobjects.add(textField); } else if (datatype.equals("LangString")) { JScrollPane inner_scroll = new javax.swing.JScrollPane(); inner_scroll.setHorizontalScrollBarPolicy( javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); inner_scroll.setVerticalScrollBarPolicy( javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); inner_scroll.setPreferredSize(new Dimension(240, 80)); inner_scroll.setName("langStringScroll"); final JTextArea jTextArea1 = new javax.swing.JTextArea(); jTextArea1.setName("MID_" + Integer.toString(kv.getValue().MID)); jTextArea1.setText(kv.getValue().value); jTextArea1.setSize(new Dimension(350, 70)); jTextArea1.setLineWrap(true); jTextArea1.setWrapStyleWord(true); inner_scroll.setViewportView(jTextArea1); innerPanel.add(inner_scroll, "width :300:"); //Add combo language box JComboBox voc = getComboLangBox(kv.getValue().language); voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "_lang"); voc.setPreferredSize(new Dimension(200, 20)); innerPanel.add(voc, "wrap, width :300:"); jTextArea1.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_TAB) { if (e.getModifiers() > 0) { jTextArea1.transferFocusBackward(); } else { jTextArea1.transferFocus(); } e.consume(); } } }); tabobjects.add(jTextArea1); tabobjects.add(voc); } else if (datatype.equals("Language")) { final JComboBox voc = getComboLangBox(kv.getValue().value); voc.setName("MID_" + Integer.toString(kv.getValue().MID)); voc.setPreferredSize(new Dimension(150, 20)); voc.setBounds(5, 5, 150, 20); innerPanel.add(voc, "wrap, width :500:"); //BookImporter.policy.addIndexedComponent(voc); tabobjects.add(voc); } else if (datatype.equals("Boolean")) { int selected = 0; TreeMap bin = new TreeMap<String, String>(); bin.put("yes", Utility.getBundleString("voc1", bundle)); bin.put("no", Utility.getBundleString("voc2", bundle)); if (kv.getValue().value == null) { switch (kv.getValue().MID) { case 35: selected = 0; break; case 36: selected = 1; break; } } else if (kv.getValue().value.equals("yes")) { selected = 1; } else { selected = 0; } final ComboMapImpl model = new ComboMapImpl(); model.putAll(bin); final JComboBox voc = new javax.swing.JComboBox(model); model.specialRenderCombo(voc); voc.setName("MID_" + Integer.toString(kv.getValue().MID)); voc.setSelectedIndex(selected); voc.setPreferredSize(new Dimension(150, 20)); voc.setBounds(5, 5, 150, 20); innerPanel.add(voc, "wrap, width :300:"); //BookImporter.policy.addIndexedComponent(voc); tabobjects.add(voc); } else if (datatype.equals("License")) { String selectedIndex = null; int vindex = 0; int defaultIndex = 0; TreeMap<String, String> entryCombo = new TreeMap<String, String>(); for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) { if (vc.getKey().equals(Integer.toString(kv.getValue().MID))) { TreeMap<String, VocEntry> iEntry = vc.getValue(); for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) { entryCombo.put(ivc.getValue().description, ivc.getValue().ID); if (ivc.getValue().ID.equals("1")) defaultIndex = vindex; if (kv.getValue().value != null) { if (ivc.getValue().ID.equals(kv.getValue().value)) { selectedIndex = Integer.toString(vindex); } } vindex++; } } } if (selectedIndex == null) selectedIndex = Integer.toString(defaultIndex); ComboMapImpl model = new ComboMapImpl(); model.putAll(entryCombo); model.setVocabularyCombo(true); JComboBox voc = new javax.swing.JComboBox(model); model.specialRenderCombo(voc); voc.setName("MID_" + Integer.toString(kv.getValue().MID)); voc.setSelectedIndex(Integer.parseInt(selectedIndex)); voc.setPreferredSize(new Dimension(150, 20)); voc.setBounds(5, 5, 150, 20); innerPanel.add(voc, "wrap, width :500:"); //BookImporter.policy.addIndexedComponent(voc); tabobjects.add(voc); } else if (datatype.equals("DateTime")) { //final JXDatePicker datePicker = new JXDatePicker(); JDateChooser datePicker = new JDateChooser(); datePicker.setName("MID_" + Integer.toString(kv.getValue().MID)); JPanel test = new JPanel(new MigLayout()); JLabel lbefore = new JLabel(Utility.getBundleString("beforechristlabel", bundle)); JCheckBox beforechrist = new JCheckBox(); beforechrist.setName("MID_" + Integer.toString(kv.getValue().MID) + "_check"); if (kv.getValue().value != null) { try { if (kv.getValue().value.charAt(0) == '-') { beforechrist.setSelected(true); } Date date1 = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); if (kv.getValue().value.charAt(0) == '-') { date1 = sdf.parse(adjustDate(kv.getValue().value)); } else { date1 = sdf.parse(kv.getValue().value); } datePicker.setDate(date1); } catch (Exception e) { //Console.WriteLine("ERROR import date:" + ex.Message); } } test.add(datePicker, "width :200:"); test.add(lbefore, "gapleft 30"); test.add(beforechrist, "wrap"); innerPanel.add(test, "wrap"); } } //Recursive call create_metadata_view(kv.getValue().submetadatas, innerPanel, level + 1, panelname); if (kv.getValue().editable.equals("Y") || (datatype.equals("Node") && kv.getValue().hidden.equals("0"))) { parent.add(innerPanel, "wrap, growx"); for (Component tabobject : tabobjects) { BookImporter.policy.addIndexedComponent(tabobject); } } } }
From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java
private void handleKeyPress(KeyEvent theE) { int row = getSelectedRow(); if (row == -1) { return;/*from w w w. ja v a2 s . c om*/ } if (theE.getKeyCode() == KeyEvent.VK_ENTER || theE.getKeyCode() == KeyEvent.VK_F2) { AbstractLayoutCache layout = ((OutlineModel) getModel()).getLayout(); TreePath path = layout.getPathForRow(row); TreeNodeBase baseObj = (TreeNodeBase) path.getLastPathComponent(); if (myTableModel.isCellEditable(baseObj, TreeRowModel.COL_VALUE)) { editCellAt(row, TreeRowModel.COL_VALUE + 1); theE.consume(); } } }