Java Code Examples for org.netbeans.editor.Utilities#createSingleLineEditor()

The following examples show how to use org.netbeans.editor.Utilities#createSingleLineEditor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassBreakpointPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static Pair<JScrollPane, JEditorPane> addClassNameEditorCC(String mimeType, JComponent comp, String className, String tooltipText) {
    JComponent [] editorComponents = Utilities.createSingleLineEditor(mimeType);
    JScrollPane sle = (JScrollPane) editorComponents[0];
    JEditorPane epClassName = (JEditorPane) editorComponents[1];
    epClassName.setText(className);
    if (comp != null) {
        java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        comp.add(sle, gridBagConstraints);
    }
    sle.setToolTipText(tooltipText);
    epClassName.setToolTipText(tooltipText);
    return Pair.<JScrollPane, JEditorPane>of(sle, epClassName);
}
 
Example 2
Source File: WatchPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public JComponent getPanel() {
    if (panel != null) {
        return panel;
    }

    panel = new JPanel();
    ResourceBundle bundle = NbBundle.getBundle(WatchPanel.class);

    panel.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_WatchPanel")); // NOI18N
    JLabel textLabel = new JLabel();
    Mnemonics.setLocalizedText(textLabel, bundle.getString ("CTL_Watch_Name")); // NOI18N
    if (expression != null && expression.trim().length() == 0) {
        JEditorPane editor = EditorContextDispatcher.getDefault().getMostRecentEditor();
        if (editor != null && editor.getDocument() instanceof StyledDocument) {
            StyledDocument doc = (StyledDocument) editor.getDocument();
            String selectedExpression = getSelectedIdentifier(doc, editor, editor.getCaret ().getDot ());
            if (selectedExpression != null) {
                expression = selectedExpression;
            }
        }
    }
    JComponent [] editorComponents = Utilities.createSingleLineEditor("text/plain");
    JScrollPane sp = (JScrollPane) editorComponents[0];
    editorPane = (JEditorPane) editorComponents[1];

    int h = sp.getPreferredSize().height;
    int w = Math.min(70*editorPane.getFontMetrics(editorPane.getFont()).charWidth('a'),
                     org.openide.windows.WindowManager.getDefault().getMainWindow().getSize().width);
    sp.setPreferredSize(new Dimension(w, h));
    /*
    FontMetrics fm = editorPane.getFontMetrics(editorPane.getFont());
    int size = 2*fm.getLeading() + fm.getMaxAscent() + fm.getMaxDescent();
    Insets eInsets = editorPane.getInsets();
    Insets spInsets = sp.getInsets();
    sp.setPreferredSize(new Dimension(30*size,
            size +
            eInsets.bottom + eInsets.top +
            spInsets.bottom + spInsets.top));
    */
    textLabel.setBorder (new EmptyBorder (0, 0, 5, 0));
    panel.setLayout (new BorderLayout ());
    panel.setBorder (new EmptyBorder (11, 12, 1, 11));
    panel.add (BorderLayout.NORTH, textLabel);
    panel.add (BorderLayout.CENTER, sp);
    
    editorPane.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Watch_Name")); // NOI18N
    editorPane.setText (expression);
    editorPane.selectAll ();

    Runnable editorPaneUpdated = new Runnable() {
        @Override
        public void run() {
            editorPane.setText (expression);
            editorPane.selectAll ();
        }
    };
    setupContext(editorPane, editorPaneUpdated);

    textLabel.setLabelFor (editorPane);
    HelpCtx.setHelpIDString(editorPane, "debug.customize.watch");
    editorPane.requestFocus ();
    
    return panel;
}
 
Example 3
Source File: ConditionsPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private JScrollPane createScrollableLineEditor() {
    JComponent [] editorComponents = Utilities.createSingleLineEditor("text/x-java");
    JScrollPane sp = (JScrollPane) editorComponents[0];
    tfCondition = (JEditorPane) editorComponents[1];
    return sp;
}
 
Example 4
Source File: ChangeParametersPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Creates new form ChangeMethodSignature */
public ChangeParametersPanel(TreePathHandle refactoredObj, ChangeListener parent, ParameterInfo[] preConfiguration, CodeStyle cs) {
    returnTypeDocListener = new ReturnTypeDocListener();
    methodNameDocListener = new MethodNameDocListener();
    this.refactoredObj = refactoredObj;
    this.parent = parent;
    this.preConfiguration = preConfiguration;
    model = new ParamTableModel(columnNames, 0) {

        @Override
        public void addRow(Object[] rowData) {
            int row = paramTable.getRowCount();
            super.addRow(rowData);
            for (int i = 0; i < paramTable.getColumnCount(); i++) {
                TableCellEditor cellEditor = paramTable.getCellEditor(row, i);
                int rowHeight = cellEditor.getTableCellEditorComponent(paramTable, rowData[0], true, row, i).getPreferredSize().height;
                if(paramTable.getRowHeight() < rowHeight) {
                    paramTable.setRowHeight(rowHeight);
                }
            }
        }
    };
    this.returnTypeAction = new ReturnTypeAction();
    singleLineEditor = Utilities.createSingleLineEditor(MIME_JAVA);
    paramname = CodeStyleUtils.addPrefixSuffix("par", cs.getParameterNamePrefix(), cs.getParameterNameSuffix());

    initComponents();

    InputMap im = paramTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    ActionMap ptActionMap = paramTable.getActionMap();

    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    Action oldTabAction = ptActionMap.get(im.get(tab));
    tableTabAction = new TableTabAction(oldTabAction);
    ptActionMap.put(im.get(tab), tableTabAction);
    
    KeyStroke shiftTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK);
    Action oldShiftTabAction = ptActionMap.get(im.get(shiftTab));
    tableShiftTabAction = new TableTabAction(oldShiftTabAction);
    ptActionMap.put(im.get(shiftTab), tableShiftTabAction);
    
    methodNameText.getDocument().addDocumentListener(methodNameDocListener);
}