private boolean updateTextComponent(final boolean search) { JTextComponent oldComponent = search ? mySearchTextComponent : myReplaceTextComponent; Color oldBackground = oldComponent != null ? oldComponent.getBackground() : null; Wrapper wrapper = search ? mySearchFieldWrapper : myReplaceFieldWrapper; boolean multiline = myFindModel.isMultiline(); if (multiline && oldComponent instanceof JTextArea) return false; if (!multiline && oldComponent instanceof JTextField) return false; final JTextComponent textComponent; if (multiline) { textComponent = new JTextArea(); ((JTextArea) textComponent).setColumns(25); ((JTextArea) textComponent).setRows(2); wrapper.setContent( new SearchWrapper(textComponent, new ShowHistoryAction(textComponent, this))); } else { SearchTextField searchTextField = new SearchTextField(true); searchTextField.setOpaque(false); textComponent = searchTextField.getTextEditor(); searchTextField.getTextEditor().setColumns(25); if (UIUtil.isUnderGTKLookAndFeel()) { textComponent.setOpaque(false); } setupHistoryToSearchField( searchTextField, search ? FindSettings.getInstance().getRecentFindStrings() : FindSettings.getInstance().getRecentReplaceStrings()); textComponent.registerKeyboardAction( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final String text = textComponent.getText(); myFindModel.setMultiline(true); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { if (search) { mySearchTextComponent.setText(text + "\n"); } else { myReplaceTextComponent.setText(text + "\n"); } } }); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.ALT_DOWN_MASK), JComponent.WHEN_FOCUSED); wrapper.setContent(searchTextField); } if (search) { mySearchTextComponent = textComponent; } else { myReplaceTextComponent = textComponent; } UIUtil.addUndoRedoActions(textComponent); Utils.setSmallerFont(textComponent); textComponent.putClientProperty("AuxEditorComponent", Boolean.TRUE); if (oldBackground != null) { textComponent.setBackground(oldBackground); } textComponent.addFocusListener( new FocusListener() { @Override public void focusGained(final FocusEvent e) { textComponent.repaint(); } @Override public void focusLost(final FocusEvent e) { textComponent.repaint(); } }); new CloseOnESCAction(this, textComponent); return true; }
public RegistryUi() { myContent.setLayout(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP)); myModel = new MyTableModel(); myTable = new JBTable(myModel); myTable.setCellSelectionEnabled(true); myTable.setEnableAntialiasing(true); final MyRenderer r = new MyRenderer(); final TableColumn c0 = myTable.getColumnModel().getColumn(0); c0.setCellRenderer(r); c0.setMaxWidth(RESTART_ICON.getIconWidth() + 12); c0.setMinWidth(RESTART_ICON.getIconWidth() + 12); c0.setHeaderValue(null); final TableColumn c1 = myTable.getColumnModel().getColumn(1); c1.setCellRenderer(r); c1.setHeaderValue("Key"); final TableColumn c2 = myTable.getColumnModel().getColumn(2); c2.setCellRenderer(r); c2.setHeaderValue("Value"); c2.setCellEditor(new MyEditor()); myTable.setStriped(true); myDescriptionLabel = new JTextArea(3, 50); myDescriptionLabel.setEditable(false); final JScrollPane label = ScrollPaneFactory.createScrollPane(myDescriptionLabel); final JPanel descriptionPanel = new JPanel(new BorderLayout()); descriptionPanel.add(label, BorderLayout.CENTER); descriptionPanel.setBorder( IdeBorderFactory.createTitledBorder("Description", false, false, true)); myContent.add(ScrollPaneFactory.createScrollPane(myTable), BorderLayout.CENTER); myContent.add(descriptionPanel, BorderLayout.SOUTH); myTable .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; final int selected = myTable.getSelectedRow(); if (selected != -1) { final RegistryValue value = myModel.getRegistryValue(selected); String desc = value.getDescription(); if (value.isRestartRequired()) { String required = "Requires IDE restart."; if (desc.endsWith(".")) { desc += required; } else { desc += (". " + required); } } myDescriptionLabel.setText(desc); } else { myDescriptionLabel.setText(null); } } }); myRestoreDefaultsAction = new RestoreDefaultsAction(); final DefaultActionGroup tbGroup = new DefaultActionGroup(); tbGroup.add(new EditAction()); tbGroup.add(new RevertAction()); final ActionToolbar tb = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, tbGroup, true); tb.setTargetComponent(myTable); myContent.add(tb.getComponent(), BorderLayout.NORTH); new TableSpeedSearch(myTable).setComparator(new SpeedSearchComparator(false)); }
private static void adjustRows(JTextArea area) { area.setRows(Math.max(2, Math.min(3, StringUtil.countChars(area.getText(), '\n') + 1))); }