ListView lv = (ListView) findViewById(R.id.layout_lv); lv.setOnTouchListener(new OnTouchListener() { // Setting on Touch Listener for handling the touch inside ScrollView @Override public boolean onTouch(View v, MotionEvent event) { // Disallow the touch request for parent scroll on touch of child view v.getParent().requestDisallowInterceptTouchEvent(true); return false; } });
@Override public void actionPerformed(ActionEvent ae) { textComponent.replaceSelection(""); } };
@Override public void actionPerformed(ActionEvent ae) { textComponent.cut(); } };
protected String getTextLineNumber(int rowStartOffset) { Element root = component.getDocument().getDefaultRootElement(); int index = root.getElementIndex(rowStartOffset); Element line = root.getElement(index); if (line.getStartOffset() == rowStartOffset) return String.valueOf(index + 1); else return ""; }
private boolean isCurrentLine(int rowStartOffset) { int caretPosition = component.getCaretPosition(); Element root = component.getDocument().getDefaultRootElement(); return root.getElementIndex(rowStartOffset) == root.getElementIndex(caretPosition); }
public void run () { ui.textArea.append(text + "\n"); ui.textArea.setCaretPosition(ui.textArea.getDocument().getLength()); } });
private void registerListeners() { textComponent.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == 3 && e.getSource() == textComponent) { process(e); } } }); textComponent.getDocument().addUndoableEditListener(event -> undoManager.addEdit(event.getEdit())); }
private AttributeSet getAttributeSet(String tag) { MutableAttributeSet attr = new SimpleAttributeSet(); Color color = tagToColorMap.get(tag); StyleConstants.setBackground(attr, color); StyleConstants.setForeground(attr, Color.WHITE); return attr; }
StyledDocument doc = textPane.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false);
private boolean isCurrentLine(int rowStartOffset) { int caretPosition = codeArea.getCaretPosition(); Element root = codeArea.getDocument().getDefaultRootElement(); return root.getElementIndex(rowStartOffset) == root.getElementIndex(caretPosition); }
@Override public void actionPerformed(ActionEvent ae) { textComponent.selectAll(); } };
@Override public void actionPerformed(ActionEvent ae) { textComponent.copy(); } };
private void addKeyActions() { KeyStroke undoKey = KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK); textComponent.getInputMap().put(undoKey, undoAction); KeyStroke redoKey = KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK); textComponent.getInputMap().put(redoKey, redoAction); }
@Override public void actionPerformed(ActionEvent ae) { textComponent.paste(); } };
/** * Fetches the set of commands that can be used * on a text component that is using a model and * view produced by this kit. * * @return the set of actions */ public Action[] getActions() { Action[] res = TextAction.augmentList(super.getActions(), this.exActions); if (logger.isDebugEnabled()) logger.debug("res.length=" + res.length); return res; }
@Override public void caretUpdate(CaretEvent e) { // Get the line the caret is positioned on int caretPosition = component.getCaretPosition(); Element root = component.getDocument().getDefaultRootElement(); int currentLine = root.getElementIndex(caretPosition); // Need to repaint so the correct line number can be highlighted if (lastLine != currentLine) { repaint(); lastLine = currentLine; } }
private AttributeSet getAttributeSet(String tag) { MutableAttributeSet attr = new SimpleAttributeSet(); Color color = tagToColorMap.get(tag); StyleConstants.setBackground(attr, color); StyleConstants.setForeground(attr, Color.WHITE); return attr; }
@Override public void caretUpdate(CaretEvent e) { int caretPosition = codeArea.getCaretPosition(); Element root = codeArea.getDocument().getDefaultRootElement(); int currentLine = root.getElementIndex(caretPosition); if (lastLine != currentLine) { repaint(); lastLine = currentLine; } }
View namebar = view.findViewById(R.id.namebar); ((ViewGroup) namebar.getParent()).removeView(namebar);
int optionId = someExpression ? R.layout.option1 : R.layout.option2; View C = findViewById(R.id.C); ViewGroup parent = (ViewGroup) C.getParent(); int index = parent.indexOfChild(C); parent.removeView(C); C = getLayoutInflater().inflate(optionId, parent, false); parent.addView(C, index);