public void setEnabled(boolean enabled) { Iterator<FieldEditor> i = editors.values().iterator(); while (i.hasNext()) { FieldEditor editor = i.next(); editor.setEnabled(enabled); } }
public void validateAllFields() { for (Iterator<String> i = editors.keySet().iterator(); i.hasNext(); ) { String field = i.next(); FieldEditor ed = editors.get(field); ed.setEnabled(true); if (((Component) ed).hasFocus()) ed.setActiveBackgroundColor(); else ed.setValidBackgroundColor(); } }
boolean isFieldModified(FieldEditor f) { String text = f.getText().trim(); if (text.length() == 0) { return getEntry().getField(f.getFieldName()) != null; } else { Object entryValue = getEntry().getField(f.getFieldName()); return entryValue == null || !entryValue.toString().equals(text); } }
public void setEntry(BibtexEntry entry) { try { updating = true; Iterator<FieldEditor> i = editors.values().iterator(); while (i.hasNext()) { FieldEditor editor = i.next(); Object content = entry.getField(editor.getFieldName()); String toSet = (content == null) ? "" : content.toString(); if (!toSet.equals(editor.getText())) editor.setText(toSet); } this.entry = entry; } finally { updating = false; } }
void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, String title) { InputMap im = panel.getInputMap(JComponent.WHEN_FOCUSED); ActionMap am = panel.getActionMap(); im.put(Globals.prefs.getKey("Entry editor, previous entry"), "prev"); am.put("prev", parent.prevEntryAction); im.put(Globals.prefs.getKey("Entry editor, next entry"), "next"); am.put("next", parent.nextEntryAction); im.put(Globals.prefs.getKey("Entry editor, store field"), "store"); am.put("store", parent.storeFieldAction); im.put(Globals.prefs.getKey("Entry editor, next panel"), "right"); im.put(Globals.prefs.getKey("Entry editor, next panel 2"), "right"); am.put("left", parent.switchLeftAction); im.put(Globals.prefs.getKey("Entry editor, previous panel"), "left"); im.put(Globals.prefs.getKey("Entry editor, previous panel 2"), "left"); am.put("right", parent.switchRightAction); im.put(Globals.prefs.getKey("Help"), "help"); am.put("help", parent.helpAction); im.put(Globals.prefs.getKey("Save database"), "save"); am.put("save", parent.saveDatabaseAction); im.put(Globals.prefs.getKey("Next tab"), "nexttab"); am.put("nexttab", parent.frame.nextTab); im.put(Globals.prefs.getKey("Previous tab"), "prevtab"); am.put("prevtab", parent.frame.prevTab); panel.setName(title); // String rowSpec = "left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref"; String colSpec = "fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref, " + "8dlu, fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref"; StringBuffer sb = new StringBuffer(); int rows = (int) Math.ceil((double) fields.length / 2.0); for (int i = 0; i < rows; i++) { sb.append("fill:pref:grow, "); } if (addKeyField) sb.append("4dlu, fill:pref"); else if (sb.length() >= 2) sb.delete(sb.length() - 2, sb.length()); String rowSpec = sb.toString(); DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(colSpec, rowSpec), panel); for (int i = 0; i < fields.length; i++) { // Create the text area: int editorType = BibtexFields.getEditorType(fields[i]); final FieldEditor ta; if (editorType == GUIGlobals.FILE_LIST_EDITOR) ta = new FileListEditor(frame, bPanel.metaData(), fields[i], null, parent); else ta = new FieldTextArea(fields[i], null); // ta.addUndoableEditListener(bPanel.undoListener); JComponent ex = parent.getExtra(fields[i], ta); // Add autocompleter listener, if required for this field: AbstractAutoCompleter autoComp = bPanel.getAutoCompleter(fields[i]); AutoCompleteListener acl = null; if (autoComp != null) { acl = new AutoCompleteListener(autoComp); } setupJTextComponent(ta.getTextComponent(), acl); ta.setAutoCompleteListener(acl); // Store the editor for later reference: editors.put(fields[i], ta); if (i == 0) activeField = ta; // System.out.println(fields[i]+": "+BibtexFields.getFieldWeight(fields[i])); // ta.getPane().setPreferredSize(new Dimension(100, // (int)(50.0*BibtexFields.getFieldWeight(fields[i])))); builder.append(ta.getLabel()); if (ex == null) builder.append(ta.getPane(), 3); else { builder.append(ta.getPane()); JPanel pan = new JPanel(); pan.setLayout(new BorderLayout()); pan.add(ex, BorderLayout.NORTH); builder.append(pan); } if (i % 2 == 1) builder.nextLine(); } // Add the edit field for Bibtex-key. if (addKeyField) { final FieldTextField tf = new FieldTextField( BibtexFields.KEY_FIELD, parent.getEntry().getField(BibtexFields.KEY_FIELD), true); // tf.addUndoableEditListener(bPanel.undoListener); setupJTextComponent(tf, null); editors.put("bibtexkey", tf); /* * If the key field is the only field, we should have only one * editor, and this one should be set as active initially: */ if (editors.size() == 1) activeField = tf; builder.nextLine(); builder.append(tf.getLabel()); builder.append(tf, 3); } }
public boolean updateField(String field, String content) { if (!editors.containsKey(field)) return false; FieldEditor ed = editors.get(field); ed.setText(content); return true; }
public void activate() { if (activeField != null) { /** Corrected to fix [ 1594169 ] Entry editor: navigation between panels */ new FocusRequester(activeField.getTextComponent()); } }
FieldEditorHelper(FieldEditor fieldEditor) { this.fieldEditor = fieldEditor; fieldNameField = fieldEditor.getFieldNameField(); fieldNameField.getDocument().addDocumentListener(new FieldNameChangeListener()); dataTypeCombo = fieldEditor.getDataTypeCombo(); dataTypeCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dataTypeComboAction(e); } }); calcTypeCombo = fieldEditor.getCalcTypeCombo(); calcTypeCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { calcTypeComboAction(e); } }); lookupViewCombo = fieldEditor.getLookupViewCombo(); lookupViewCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { lookupViewComboAction(e); } }); lookupFieldCombo = fieldEditor.getLookupFieldCombo(); lookupFieldCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { lookupFieldComboAction(e); } }); objRelationshipCombo = fieldEditor.getObjRelationshipCombo(); objRelationshipCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { objRelationshipComboAction(e); } }); objAttributeCombo = fieldEditor.getObjAttributeCombo(); objAttributeCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { objAttributeComboAction(e); } }); defaultValueField = fieldEditor.getDefaultValueField(); defaultValueField.getDocument().addDocumentListener(new DefaultValueChangeListener()); captionField = fieldEditor.getCaptionField(); captionField.getDocument().addDocumentListener(new CaptionChangeListener()); editableCheckBox = fieldEditor.getEditableCheckBox(); editableCheckBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { editableCheckBoxAction(e); } }); visibleCheckBox = fieldEditor.getVisibleCheckBox(); visibleCheckBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { visibleCheckBoxAction(e); } }); displayClassField = fieldEditor.getDisplayClassField(); displayClassField.getDocument().addDocumentListener(new DisplayClassChangeListener()); displayPatternField = fieldEditor.getDisplayPatternField(); displayPatternField.getDocument().addDocumentListener(new DisplayPatternChangeListener()); editClassField = fieldEditor.getEditClassField(); editClassField.getDocument().addDocumentListener(new EditClassChangeListener()); editPatternField = fieldEditor.getEditPatternField(); editPatternField.getDocument().addDocumentListener(new EditPatternChangeListener()); preferredIndexField = fieldEditor.getPreferredIndexField(); preferredIndexField.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { preferredIndexFieldChanged(e); } }); }