Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an icon picker in group edit dialog for issue#6142 #7758

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We added a feature that allows the user to choose whether to trust the target site when unable to find a valid certification path from the file download site. [#7616](https://github.com/JabRef/jabref/issues/7616)
- We added a feature that allows the user to open all linked files of multiple selected entries by "Open file" option. [#6966](https://github.com/JabRef/jabref/issues/6966)
- We added a keybinding preset for new entries. [#7705](https://github.com/JabRef/jabref/issues/7705)
- We added an icon picker in group edit dialog. [#6142](https://github.com/JabRef/jabref/issues/6142)

### Changed

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupDialog.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import org.jabref.gui.icon.JabRefIconView?>
<?import javafx.scene.text.Font?>
<DialogPane prefHeight="300.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.2-internal"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.groups.GroupDialogView">
<content>
Expand All @@ -38,8 +39,16 @@
</VBox>
<HBox spacing="10.0">
<VBox HBox.hgrow="ALWAYS">
<Label text="%Icon"/>
<TextField fx:id="iconField"/>
<Label text="%Icon" />
<Button fx:id="iconButton" onAction="#openIconPicker" text="IconPicker" minHeight="23.5" maxHeight="23.5" prefHeight="23.5">
<font>
<Font size="10.5" />
</font>
</Button>
</VBox>
<VBox HBox.hgrow="ALWAYS">
<Label text="IconField"/>
<TextField fx:id="iconField" />
</VBox>
<VBox layoutX="10.0" layoutY="10.0" minWidth="130.0" maxWidth="130.0" prefWidth="130.0">
<Label text="%Color"/>
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/jabref/gui/groups/GroupDialogView.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import javafx.scene.control.ComboBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;

import org.jabref.gui.DialogService;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.IconValidationDecorator;
Expand All @@ -31,6 +30,7 @@ public class GroupDialogView extends BaseDialog<AbstractGroup> {
// Basic Settings
@FXML private TextField nameField;
@FXML private TextField descriptionField;
@FXML private Button iconButton;
@FXML private TextField iconField;
@FXML private ColorPicker colorField;
@FXML private ComboBox<GroupHierarchyType> hierarchicalContextCombo;
Expand Down Expand Up @@ -165,4 +165,9 @@ private void texGroupBrowse() {
private void openHelp() {
viewModel.openHelpPage();
}

@FXML
private void openIconPicker() {
viewModel.openIconPickerPage();
}
}
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ public void openHelpPage() {
HelpAction.openHelpPage(HelpFile.GROUPS);
}

public void openIconPickerPage(){
GroupIconPicker groupIconPicker= new GroupIconPicker();
dialogService.showCustomDialogAndWait(groupIconPicker);
iconProperty.setValue(groupIconPicker.selectedIconName);
}

private List<Path> getFileDirectoriesAsPaths() {
List<Path> fileDirs = new ArrayList<>();
MetaData metaData = currentDatabase.getMetaData();
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupIconPicker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.jabref.gui.groups;

import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.util.Callback;
import org.jabref.gui.icon.InternalMaterialDesignIcon;
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.gui.util.BaseDialog;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.groups.AbstractGroup;
import org.kordamp.ikonli.Ikon;
import org.kordamp.ikonli.IkonProvider;

import java.util.*;

import static java.util.EnumSet.allOf;


public class GroupIconPicker extends BaseDialog<AbstractGroup> {

private static final List<Ikon> ICONS = new ArrayList<>();

public String selectedIconName;
private Pagination pagination;
private static int iconInOnePage = 504;
private static int iconInOneRow = 6;


private ScrollPane createPage(int PageIndex) {
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setMaxWidth(Double.MAX_VALUE);
grid.setAlignment(Pos.CENTER_LEFT);
ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(grid);
scrollPane.setPrefWidth(300);
scrollPane.setPrefHeight(300);
int colPointer = 0;
int rowPointer = 0;
for (int i = PageIndex * iconInOnePage; i < ICONS.size() - 1 && i < (PageIndex + 1) * iconInOnePage; i++) {
Ikon ikon = ICONS.get(i);
Button button = new Button();
JabRefIcon jabRefIcon = new InternalMaterialDesignIcon(ikon);
button.setGraphic(new InternalMaterialDesignIcon(ikon).getGraphicNode());
grid.add(button, colPointer++, rowPointer);
if (colPointer % iconInOneRow == 0) {
rowPointer++;
colPointer = colPointer % iconInOneRow;
}
button.setOnAction(event -> {
selectedIconName = jabRefIcon.getIkon().toString();
});
}
return scrollPane;
}

public GroupIconPicker() {
loadAllIkons();
this.setTitle(Localization.lang("Icon Picker"));
int iconNumber = ICONS.size();
pagination = new Pagination((int) Math.ceil(iconNumber / (iconInOnePage * 1.0)));
pagination.setPageFactory(new Callback<Integer, Node>() {
@Override
public Node call(Integer pageIndex) {
return createPage(pageIndex);
}
});
getDialogPane().getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL);
getDialogPane().setContent(pagination);
}

private static void loadAllIkons() {
ServiceLoader<IkonProvider> providers = ServiceLoader.load(IkonProvider.class);
for (IkonProvider provider : providers) {
ICONS.addAll(allOf(provider.getIkon()));
}
}
}