Skip to content

Commit

Permalink
replace most of Deprecated APIs (#12045)
Browse files Browse the repository at this point in the history
* fix CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN

fix CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN Deprecated issue in comment

* fix override deprecated method

fix override deprecated method in IconValidationDecorator

* fix Deprecated ANTLRInputStream

replace ANTLRInputStream to CharStreams

* fix Deprecated BOMInputStream

use builder instead.

* fix wrong CharStreams method

fromFileName -> fromString

* fix requested changes

1.fix requested changes
2.add more unit test to support change in  IconValidationDecorator

* fix last Deprecated API

remove Deprecated setGroup

* remove unnecessary IOException and add comment

remove unnecessary IOException and add comment

* revert wrong change

revert wrong change with added comment

* merge from main

merge from main

* Discard changes to src/main/java/org/jabref/logic/database/DatabaseMerger.java

---------

Co-authored-by: Oliver Kopp <[email protected]>
  • Loading branch information
leaf-soba and koppor authored Oct 27, 2024
1 parent 598d269 commit e9a6c5a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* This resize policy is almost the same as {@link TableView#CONSTRAINED_RESIZE_POLICY}
* We make sure that the width of all columns sums up to the total width of the table.
* However, in contrast to {@link TableView#CONSTRAINED_RESIZE_POLICY} we size the columns initially by their preferred width.
* Although {@link TableView#CONSTRAINED_RESIZE_POLICY} is deprecated, this policy maintains a similar resizing behavior.
*/
public class SmartConstrainedResizePolicy implements Callback<TableView.ResizeFeatures, Boolean> {

Expand Down
14 changes: 3 additions & 11 deletions src/main/java/org/jabref/gui/util/IconValidationDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,11 @@ public IconValidationDecorator(Pos position) {
this.position = position;
}

@Override
protected Node createErrorNode() {
return IconTheme.JabRefIcons.ERROR.getGraphicNode();
}

@Override
protected Node createWarningNode() {
return IconTheme.JabRefIcons.WARNING.getGraphicNode();
}

@Override
public Node createDecorationNode(ValidationMessage message) {
Node graphic = Severity.ERROR == message.getSeverity() ? createErrorNode() : createWarningNode();
Node graphic = Severity.ERROR == message.getSeverity()
? IconTheme.JabRefIcons.ERROR.getGraphicNode()
: IconTheme.JabRefIcons.WARNING.getGraphicNode();
graphic.getStyleClass().add(Severity.ERROR == message.getSeverity() ? "error-icon" : "warning-icon");
Label label = new Label();
label.setGraphic(graphic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,11 @@ private BufferedReader getReaderFromZip(Path filePath) throws IOException {
// Solution inspired by https://stackoverflow.com/a/37445972/873282
return new BufferedReader(
new InputStreamReader(
new BOMInputStream(
Files.newInputStream(newFile, StandardOpenOption.READ),
false,
ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE)));
new BOMInputStream.Builder()
.setInputStream(Files.newInputStream(newFile, StandardOpenOption.READ))
.setInclude(false)
.setByteOrderMarks(ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE)
.get()));
}

private String clean(String input) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jabref/model/groups/GroupTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ public ObjectProperty<AbstractGroup> getGroupProperty() {
* Associates the specified group with this node.
*
* @param newGroup the new group (has to be non-null)
* @deprecated use {@link #setGroup(AbstractGroup, boolean, boolean, List)}} instead
*/
@Deprecated
public void setGroup(AbstractGroup newGroup) {
this.groupProperty.set(Objects.requireNonNull(newGroup));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.jabref.logic.util;

import javafx.scene.control.Control;
import javafx.scene.control.Label;

import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.IconValidationDecorator;

import org.controlsfx.validation.Severity;
import org.controlsfx.validation.ValidationMessage;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.testfx.framework.junit5.ApplicationExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;

@ExtendWith(ApplicationExtension.class)
public class IconValidationDecoratorTest {
static Object[][] decorationTestData() {
return new Object[][]{
{Severity.ERROR, IconTheme.JabRefIcons.ERROR.getGraphicNode().toString()},
{Severity.WARNING, IconTheme.JabRefIcons.WARNING.getGraphicNode().toString()}
};
}

@ParameterizedTest
@MethodSource("decorationTestData")
public void createDecorationNodeTest(Severity severity, String expectedGraphic) {
IconValidationDecorator iconValidationDecorator = new IconValidationDecorator();
Label node = (Label) iconValidationDecorator.createDecorationNode(new ValidationMessage() {
@Override
public String getText() {
return "test";
}

@Override
public Severity getSeverity() {
return severity;
}

@Override
public Control getTarget() {
return null;
}
});

assertEquals(node.getGraphic().toString(), expectedGraphic);
}
}

0 comments on commit e9a6c5a

Please sign in to comment.