|
| 1 | +package org.jabref.gui; |
| 2 | + |
| 3 | +import javafx.collections.ListChangeListener; |
| 4 | +import javafx.geometry.Insets; |
| 5 | +import javafx.geometry.Pos; |
| 6 | +import javafx.scene.Node; |
| 7 | +import javafx.scene.control.Hyperlink; |
| 8 | +import javafx.scene.control.Label; |
| 9 | +import javafx.scene.control.MenuItem; |
| 10 | +import javafx.scene.control.Tab; |
| 11 | +import javafx.scene.layout.BorderPane; |
| 12 | +import javafx.scene.layout.HBox; |
| 13 | +import javafx.scene.layout.Priority; |
| 14 | +import javafx.scene.layout.VBox; |
| 15 | + |
| 16 | +import org.jabref.gui.actions.StandardActions; |
| 17 | +import org.jabref.gui.edit.OpenBrowserAction; |
| 18 | +import org.jabref.gui.frame.FileHistoryMenu; |
| 19 | +import org.jabref.gui.icon.IconTheme; |
| 20 | +import org.jabref.gui.importer.NewDatabaseAction; |
| 21 | +import org.jabref.gui.importer.actions.OpenDatabaseAction; |
| 22 | +import org.jabref.gui.preferences.GuiPreferences; |
| 23 | +import org.jabref.gui.undo.CountingUndoManager; |
| 24 | +import org.jabref.gui.util.URLs; |
| 25 | +import org.jabref.logic.ai.AiService; |
| 26 | +import org.jabref.logic.l10n.Localization; |
| 27 | +import org.jabref.logic.util.BuildInfo; |
| 28 | +import org.jabref.logic.util.TaskExecutor; |
| 29 | +import org.jabref.model.entry.BibEntryTypesManager; |
| 30 | +import org.jabref.model.util.FileUpdateMonitor; |
| 31 | + |
| 32 | +public class WelcomeTab extends Tab { |
| 33 | + |
| 34 | + private final VBox recentLibrariesBox; |
| 35 | + private final LibraryTabContainer tabContainer; |
| 36 | + private final GuiPreferences preferences; |
| 37 | + private final AiService aiService; |
| 38 | + private final DialogService dialogService; |
| 39 | + private final StateManager stateManager; |
| 40 | + private final FileUpdateMonitor fileUpdateMonitor; |
| 41 | + private final BibEntryTypesManager entryTypesManager; |
| 42 | + private final CountingUndoManager undoManager; |
| 43 | + private final ClipBoardManager clipBoardManager; |
| 44 | + private final TaskExecutor taskExecutor; |
| 45 | + private final FileHistoryMenu fileHistoryMenu; |
| 46 | + private final BuildInfo buildInfo; |
| 47 | + |
| 48 | + public WelcomeTab(LibraryTabContainer tabContainer, |
| 49 | + GuiPreferences preferences, |
| 50 | + AiService aiService, |
| 51 | + DialogService dialogService, |
| 52 | + StateManager stateManager, |
| 53 | + FileUpdateMonitor fileUpdateMonitor, |
| 54 | + BibEntryTypesManager entryTypesManager, |
| 55 | + CountingUndoManager undoManager, |
| 56 | + ClipBoardManager clipBoardManager, |
| 57 | + TaskExecutor taskExecutor, |
| 58 | + FileHistoryMenu fileHistoryMenu, |
| 59 | + BuildInfo buildInfo) { |
| 60 | + |
| 61 | + super(Localization.lang("Welcome")); |
| 62 | + setClosable(true); |
| 63 | + |
| 64 | + this.tabContainer = tabContainer; |
| 65 | + this.preferences = preferences; |
| 66 | + this.aiService = aiService; |
| 67 | + this.dialogService = dialogService; |
| 68 | + this.stateManager = stateManager; |
| 69 | + this.fileUpdateMonitor = fileUpdateMonitor; |
| 70 | + this.entryTypesManager = entryTypesManager; |
| 71 | + this.undoManager = undoManager; |
| 72 | + this.clipBoardManager = clipBoardManager; |
| 73 | + this.taskExecutor = taskExecutor; |
| 74 | + this.fileHistoryMenu = fileHistoryMenu; |
| 75 | + this.buildInfo = buildInfo; |
| 76 | + |
| 77 | + this.recentLibrariesBox = new VBox(10); |
| 78 | + |
| 79 | + VBox welcomeBox = createWelcomeBox(); |
| 80 | + VBox startBox = createWelcomeStartBox(); |
| 81 | + VBox recentBox = createWelcomeRecentBox(); |
| 82 | + |
| 83 | + VBox welcomePageContainer = new VBox(10); |
| 84 | + welcomePageContainer.setAlignment(Pos.CENTER); |
| 85 | + welcomePageContainer.getChildren().addAll(welcomeBox, startBox, recentBox); |
| 86 | + |
| 87 | + HBox welcomeMainContainer = new HBox(10); |
| 88 | + welcomeMainContainer.setAlignment(Pos.CENTER); |
| 89 | + welcomeMainContainer.setPadding(new Insets(10, 10, 10, 50)); |
| 90 | + |
| 91 | + welcomeMainContainer.getChildren().add(welcomePageContainer); |
| 92 | + |
| 93 | + BorderPane rootLayout = new BorderPane(); |
| 94 | + rootLayout.setCenter(welcomeMainContainer); |
| 95 | + rootLayout.setBottom(createFooter()); |
| 96 | + |
| 97 | + VBox container = new VBox(); |
| 98 | + container.getChildren().add(rootLayout); |
| 99 | + VBox.setVgrow(rootLayout, Priority.ALWAYS); |
| 100 | + setContent(container); |
| 101 | + } |
| 102 | + |
| 103 | + private VBox createWelcomeBox() { |
| 104 | + Label welcomeLabel = new Label(Localization.lang("Welcome to JabRef")); |
| 105 | + welcomeLabel.getStyleClass().add("welcome-label"); |
| 106 | + |
| 107 | + Label descriptionLabel = new Label(Localization.lang("Stay on top of your literature")); |
| 108 | + descriptionLabel.getStyleClass().add("welcome-description-label"); |
| 109 | + |
| 110 | + return createVBoxContainer(welcomeLabel, descriptionLabel); |
| 111 | + } |
| 112 | + |
| 113 | + private VBox createWelcomeStartBox() { |
| 114 | + Label startLabel = new Label(Localization.lang("Start")); |
| 115 | + startLabel.getStyleClass().add("welcome-header-label"); |
| 116 | + |
| 117 | + Hyperlink newLibraryLink = new Hyperlink(Localization.lang("New library")); |
| 118 | + newLibraryLink.getStyleClass().add("welcome-hyperlink"); |
| 119 | + newLibraryLink.setOnAction(e -> new NewDatabaseAction(tabContainer, preferences).execute()); |
| 120 | + |
| 121 | + Hyperlink openLibraryLink = new Hyperlink(Localization.lang("Open library")); |
| 122 | + openLibraryLink.getStyleClass().add("welcome-hyperlink"); |
| 123 | + openLibraryLink.setOnAction(e -> new OpenDatabaseAction(tabContainer, preferences, aiService, dialogService, |
| 124 | + stateManager, fileUpdateMonitor, entryTypesManager, undoManager, clipBoardManager, |
| 125 | + taskExecutor).execute()); |
| 126 | + |
| 127 | + return createVBoxContainer(startLabel, newLibraryLink, openLibraryLink); |
| 128 | + } |
| 129 | + |
| 130 | + private VBox createWelcomeRecentBox() { |
| 131 | + Label recentLabel = new Label(Localization.lang("Recent")); |
| 132 | + recentLabel.getStyleClass().add("welcome-header-label"); |
| 133 | + |
| 134 | + recentLibrariesBox.setAlignment(Pos.TOP_LEFT); |
| 135 | + updateWelcomeRecentLibraries(); |
| 136 | + |
| 137 | + fileHistoryMenu.getItems().addListener((ListChangeListener<MenuItem>) change -> updateWelcomeRecentLibraries()); |
| 138 | + |
| 139 | + return createVBoxContainer(recentLabel, recentLibrariesBox); |
| 140 | + } |
| 141 | + |
| 142 | + private void updateWelcomeRecentLibraries() { |
| 143 | + if (fileHistoryMenu.getItems().isEmpty()) { |
| 144 | + displayNoRecentLibrariesMessage(); |
| 145 | + return; |
| 146 | + } |
| 147 | + |
| 148 | + recentLibrariesBox.getChildren().clear(); |
| 149 | + fileHistoryMenu.disableProperty().unbind(); |
| 150 | + fileHistoryMenu.setDisable(false); |
| 151 | + |
| 152 | + for (MenuItem item : fileHistoryMenu.getItems()) { |
| 153 | + Hyperlink recentLibraryLink = new Hyperlink(item.getText()); |
| 154 | + recentLibraryLink.getStyleClass().add("welcome-hyperlink"); |
| 155 | + recentLibraryLink.setOnAction(item.getOnAction()); |
| 156 | + recentLibrariesBox.getChildren().add(recentLibraryLink); |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + private void displayNoRecentLibrariesMessage() { |
| 161 | + recentLibrariesBox.getChildren().clear(); |
| 162 | + Label noRecentLibrariesLabel = new Label(Localization.lang("No recent libraries")); |
| 163 | + noRecentLibrariesLabel.getStyleClass().add("welcome-no-recent-label"); |
| 164 | + recentLibrariesBox.getChildren().add(noRecentLibrariesLabel); |
| 165 | + |
| 166 | + fileHistoryMenu.disableProperty().unbind(); |
| 167 | + fileHistoryMenu.setDisable(true); |
| 168 | + } |
| 169 | + |
| 170 | + private VBox createVBoxContainer(Node... nodes) { |
| 171 | + VBox box = new VBox(10); |
| 172 | + box.setAlignment(Pos.TOP_LEFT); |
| 173 | + box.getChildren().addAll(nodes); |
| 174 | + return box; |
| 175 | + } |
| 176 | + |
| 177 | + private VBox createFooter() { |
| 178 | + // Heading for the footer area |
| 179 | + Label communityLabel = createFooterLabel(Localization.lang("Community")); |
| 180 | + |
| 181 | + HBox iconLinksContainer = createIconLinksContainer(); |
| 182 | + HBox textLinksContainer = createTextLinksContainer(); |
| 183 | + HBox versionContainer = createVersionContainer(); |
| 184 | + |
| 185 | + VBox footerBox = new VBox(10); |
| 186 | + footerBox.setAlignment(Pos.CENTER); |
| 187 | + footerBox.getChildren().addAll(communityLabel, iconLinksContainer, textLinksContainer, versionContainer); |
| 188 | + footerBox.setPadding(new Insets(10, 0, 10, 0)); |
| 189 | + footerBox.getStyleClass().add("welcome-footer-container"); |
| 190 | + |
| 191 | + return footerBox; |
| 192 | + } |
| 193 | + |
| 194 | + private Label createFooterLabel(String text) { |
| 195 | + Label label = new Label(text); |
| 196 | + label.getStyleClass().add("welcome-footer-label"); |
| 197 | + return label; |
| 198 | + } |
| 199 | + |
| 200 | + private HBox createIconLinksContainer() { |
| 201 | + HBox container = new HBox(10); |
| 202 | + container.setAlignment(Pos.CENTER); |
| 203 | + |
| 204 | + Hyperlink onlineHelpLink = createFooterLink(Localization.lang("Online help"), StandardActions.HELP, IconTheme.JabRefIcons.HELP); |
| 205 | + Hyperlink forumLink = createFooterLink(Localization.lang("Community forum"), StandardActions.OPEN_FORUM, IconTheme.JabRefIcons.FORUM); |
| 206 | + Hyperlink mastodonLink = createFooterLink(Localization.lang("Mastodon"), StandardActions.OPEN_MASTODON, IconTheme.JabRefIcons.MASTODON); |
| 207 | + Hyperlink linkedInLink = createFooterLink(Localization.lang("LinkedIn"), StandardActions.OPEN_LINKEDIN, IconTheme.JabRefIcons.LINKEDIN); |
| 208 | + Hyperlink donationLink = createFooterLink(Localization.lang("Donation"), StandardActions.DONATE, IconTheme.JabRefIcons.DONATE); |
| 209 | + |
| 210 | + container.getChildren().addAll(onlineHelpLink, forumLink, mastodonLink, linkedInLink, donationLink); |
| 211 | + return container; |
| 212 | + } |
| 213 | + |
| 214 | + private HBox createTextLinksContainer() { |
| 215 | + HBox container = new HBox(10); |
| 216 | + container.setAlignment(Pos.CENTER); |
| 217 | + |
| 218 | + Hyperlink devVersionLink = createFooterLink(Localization.lang("Download development version"), StandardActions.OPEN_DEV_VERSION_LINK, null); |
| 219 | + Hyperlink changelogLink = createFooterLink(Localization.lang("CHANGELOG"), StandardActions.OPEN_CHANGELOG, null); |
| 220 | + |
| 221 | + container.getChildren().addAll(devVersionLink, changelogLink); |
| 222 | + return container; |
| 223 | + } |
| 224 | + |
| 225 | + private Hyperlink createFooterLink(String text, StandardActions action, IconTheme.JabRefIcons icon) { |
| 226 | + Hyperlink link = new Hyperlink(text); |
| 227 | + link.getStyleClass().add("welcome-footer-link"); |
| 228 | + |
| 229 | + String url = switch (action) { |
| 230 | + case HELP -> URLs.HELP_URL; |
| 231 | + case OPEN_FORUM -> URLs.FORUM_URL; |
| 232 | + case OPEN_MASTODON -> URLs.MASTODON_URL; |
| 233 | + case OPEN_LINKEDIN -> URLs.LINKEDIN_URL; |
| 234 | + case DONATE -> URLs.DONATE_URL; |
| 235 | + case OPEN_DEV_VERSION_LINK -> URLs.DEV_VERSION_LINK_URL; |
| 236 | + case OPEN_CHANGELOG -> URLs.CHANGELOG_URL; |
| 237 | + default -> null; |
| 238 | + }; |
| 239 | + |
| 240 | + if (url != null) { |
| 241 | + link.setOnAction(e -> new OpenBrowserAction(url, dialogService, preferences.getExternalApplicationsPreferences()).execute()); |
| 242 | + } |
| 243 | + |
| 244 | + if (icon != null) { |
| 245 | + link.setGraphic(icon.getGraphicNode()); |
| 246 | + } |
| 247 | + |
| 248 | + return link; |
| 249 | + } |
| 250 | + |
| 251 | + private HBox createVersionContainer() { |
| 252 | + HBox container = new HBox(10); |
| 253 | + container.setAlignment(Pos.CENTER); |
| 254 | + |
| 255 | + Label versionLabel = new Label(Localization.lang("Current JabRef version: %0", buildInfo.version)); |
| 256 | + versionLabel.getStyleClass().add("welcome-footer-version"); |
| 257 | + |
| 258 | + container.getChildren().add(versionLabel); |
| 259 | + return container; |
| 260 | + } |
| 261 | +} |
0 commit comments