From 532d77a1799869935566c9a041a3dbb928c8073c Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 28 May 2017 20:37:19 +0200 Subject: [PATCH 1/2] Fix Divide by zero exception if rows is zero --- .../gui/entryeditor/EntryEditorTab.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java index e127930c9a0..dc3cbaab223 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java @@ -57,9 +57,8 @@ class EntryEditorTab { private BibEntry entry; private boolean updating; - public EntryEditorTab(JabRefFrame frame, BasePanel basePanel, List fields, EntryEditor parent, - boolean addKeyField, boolean compressed, String tabTitle, BibEntry entry) { + boolean addKeyField, boolean compressed, String tabTitle, BibEntry entry) { this.entry = Objects.requireNonNull(entry); if (fields == null) { this.fields = new ArrayList<>(); @@ -84,8 +83,7 @@ public EntryEditorTab(JabRefFrame frame, BasePanel basePanel, List field root.setStyle( "text-area-background: " + convertToHex(GUIGlobals.validFieldBackgroundColor) + ";" + "text-area-foreground: " + convertToHex(GUIGlobals.editorTextColor) + ";" - + "text-area-highlight: " + convertToHex(GUIGlobals.activeBackgroundColor) + ";" - ); + + "text-area-highlight: " + convertToHex(GUIGlobals.activeBackgroundColor) + ";"); } root.getStylesheets().add("org/jabref/gui/entryeditor/EntryEditor.css"); @@ -110,7 +108,7 @@ private String convertToHex(java.awt.Color color) { } private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, - boolean compressed, String title) { + boolean compressed, String title) { setupKeyBindings(panel.getInputMap(JComponent.WHEN_FOCUSED), panel.getActionMap()); @@ -140,9 +138,9 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyFie //parent.addSearchListener((TextArea) fieldEditor); defaultHeight = fieldEditor.getPane().getPreferredSize().height; } - + Optional extra = parent.getExtra(fieldEditor); - + // Add autocompleter listener, if required for this field: /* AutoCompleter autoCompleter = bPanel.getAutoCompleters().get(field); @@ -154,7 +152,9 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyFie fieldEditor.setAutoCompleteListener(autoCompleteListener); */ - FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService(), Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences(), Globals.prefs, bPanel.getBibDatabaseContext(), entry.getType()); + FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService(), + Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences(), Globals.prefs, + bPanel.getBibDatabaseContext(), entry.getType()); editors.put(fieldName, fieldEditor); /* // TODO: Reenable this @@ -204,7 +204,8 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyFie addColumn(gridPane, 1, editors.values().stream().map(FieldEditorFX::getNode).limit(rows)); addColumn(gridPane, 4, editors.values().stream().map(FieldEditorFX::getNode).skip(rows)); - gridPane.getColumnConstraints().addAll(columnDoNotContract, columnExpand, new ColumnConstraints(10), columnDoNotContract, columnExpand); + gridPane.getColumnConstraints().addAll(columnDoNotContract, columnExpand, new ColumnConstraints(10), + columnDoNotContract, columnExpand); } else { rows = fields.size(); @@ -216,6 +217,11 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyFie RowConstraints rowExpand = new RowConstraints(); rowExpand.setVgrow(Priority.ALWAYS); + + if (rows == 0) { + rows = 1; + } + rowExpand.setPercentHeight(100 / rows); for (int i = 0; i < rows; i++) { gridPane.getRowConstraints().add(rowExpand); @@ -236,12 +242,12 @@ private String getPrompt(String field) { } switch (field) { - case FieldName.YEAR: - return "YYYY"; - case FieldName.MONTH: - return "MM or #mmm#"; - case FieldName.URL: - return "https://"; + case FieldName.YEAR: + return "YYYY"; + case FieldName.MONTH: + return "MM or #mmm#"; + case FieldName.URL: + return "https://"; } return ""; @@ -290,7 +296,7 @@ public boolean updateField(String field, String content) { if (fieldEditor.getText().equals(content)) { return true; } - + // trying to preserve current edit position (fixes SF bug #1285) if (fieldEditor.getTextComponent() instanceof JTextComponent) { int initialCaretPosition = ((JTextComponent) fieldEditor).getCaretPosition(); From 6f234bb346d8ff178a9194eb1561f3ddc40a5e1f Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sun, 28 May 2017 21:05:12 +0200 Subject: [PATCH 2/2] Update EntryEditorTab.java --- .../java/org/jabref/gui/entryeditor/EntryEditorTab.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java index dc3cbaab223..108fd807219 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java @@ -217,12 +217,11 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyFie RowConstraints rowExpand = new RowConstraints(); rowExpand.setVgrow(Priority.ALWAYS); - if (rows == 0) { - rows = 1; + rowExpand.setPercentHeight(100); + } else { + rowExpand.setPercentHeight(100 / rows); } - - rowExpand.setPercentHeight(100 / rows); for (int i = 0; i < rows; i++) { gridPane.getRowConstraints().add(rowExpand); }