Java Code Examples for javafx.scene.control.Hyperlink#setOnAction()

The following examples show how to use javafx.scene.control.Hyperlink#setOnAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GoogleCloudCredentialsAlert.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public void show()
{
	final Hyperlink hyperlink = new Hyperlink("Google Cloud SDK");
	hyperlink.setOnAction(e -> Paintera.getApplication().getHostServices().showDocument(googleCloudSdkLink));

	final TextArea area = new TextArea(googleCloudAuthCmd);
	area.setFont(Font.font("monospace"));
	area.setEditable(false);
	area.setMaxHeight(24);

	final TextFlow textFlow = new TextFlow(
			new Text("Please install "),
			hyperlink,
			new Text(" and then run this command to initialize the credentials:"),
			new Text(System.lineSeparator() + System.lineSeparator()),
			area);

	final Alert alert = PainteraAlerts.alert(Alert.AlertType.INFORMATION);
	alert.setHeaderText("Could not find Google Cloud credentials.");
	alert.getDialogPane().contentProperty().set(textFlow);
	alert.show();
}
 
Example 2
Source File: StartUpView.java    From LogFX with GNU General Public License v3.0 6 votes vote down vote up
public StartUpView( HostServices hostServices,
                    Stage stage,
                    Consumer<File> openFile ) {
    VBox box = new AboutLogFXView( hostServices ).createNode();

    String metaKey = FxUtils.isMac() ? "⌘" : "Ctrl+";

    Hyperlink link = new Hyperlink( String.format( "Open file (%sO)", metaKey ) );
    link.getStyleClass().add( "large-background-text" );
    link.setOnAction( ( event ) -> new FileOpener( stage, openFile ) );

    Text dropText = new Text( "Or drop files here" );
    dropText.getStyleClass().add( "large-background-text" );

    StackPane fileDropPane = new StackPane( dropText );
    fileDropPane.getStyleClass().add("drop-file-pane");

    FileDragAndDrop.install( fileDropPane, openFile );

    box.getChildren().addAll( link, fileDropPane );
    getChildren().addAll( box );
}
 
Example 3
Source File: CreateFilePane.java    From pattypan with MIT License 6 votes vote down vote up
private void showOpenFileButton() {
  Hyperlink link = new Hyperlink(Util.text("create-file-open"));
  TextFlow flow = new TextFlow(new WikiLabel("create-file-success"), link);
  flow.setTextAlignment(TextAlignment.CENTER);
  addElement(flow);
  link.setOnAction(ev -> {
    try {
      Desktop.getDesktop().open(Session.FILE);
    } catch (IOException ex) {
      Session.LOGGER.log(Level.WARNING, 
          "Cannot open file: {0}",
          new String[]{ex.getLocalizedMessage()}
      );
    }
  });

  nextButton.linkTo("StartPane", stage, true).setText(Util.text("create-file-back-to-start"));
  nextButton.setVisible(true);
}
 
Example 4
Source File: MainScreen.java    From javamoney-examples with Apache License 2.0 5 votes vote down vote up
private void addButton(VBox box, String title,
		final Class<? extends Node> type) {
	Hyperlink button = new Hyperlink(title);
	button.setPrefWidth(200d);
	button.setAlignment(Pos.CENTER_LEFT);
	button.setOnAction(new EventHandler<ActionEvent>() {
		public void handle(ActionEvent arg0) {
			openSample(type);
		}
	});
	box.getChildren().add(button);
}
 
Example 5
Source File: AboutDialog.java    From classpy with MIT License 5 votes vote down vote up
private static Hyperlink createHomeLink() {
    String homeUrl = "https://github.com/zxh0/classpy";
    Hyperlink link = new Hyperlink(homeUrl);
    link.setOnAction(e -> {
        try {
            Desktop.getDesktop().browse(URI.create(homeUrl));
        } catch (IOException x) {
            x.printStackTrace(System.err);
        }
    });

    BorderPane.setAlignment(link, Pos.CENTER);
    BorderPane.setMargin(link, new Insets(8));
    return link;
}
 
Example 6
Source File: AboutLogFXView.java    From LogFX with GNU General Public License v3.0 5 votes vote down vote up
VBox createNode() {
    VBox contents = new VBox( 25 );
    contents.setPrefSize( 500, 300 );
    contents.setAlignment( Pos.CENTER );
    contents.getStylesheets().add( "css/about.css" );

    HBox textBox = new HBox( 0 );
    textBox.setPrefWidth( 500 );
    textBox.setAlignment( Pos.CENTER );
    Text logText = new Text( "Log" );
    logText.setId( "logfx-text-log" );
    Text fxText = new Text( "FX" );
    fxText.setId( "logfx-text-fx" );
    textBox.getChildren().addAll( logText, fxText );

    VBox smallText = new VBox( 10 );
    smallText.setPrefWidth( 500 );
    smallText.setAlignment( Pos.CENTER );
    Text version = new Text( "Version " + Constants.LOGFX_VERSION );
    Text byRenato = new Text( "Copyright Renato Athaydes, 2017. All rights reserved." );
    Text license = new Text( "Licensed under the GPLv3 License." );
    Hyperlink link = new Hyperlink( "https://github.com/renatoathaydes/LogFX" );
    link.setOnAction( ( event ) -> hostServices.showDocument( link.getText() ) );
    smallText.getChildren().addAll( version, byRenato, link, license );

    contents.getChildren().addAll( textBox, smallText );

    return contents;
}
 
Example 7
Source File: AboutPanelSkin.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates the {@link Hyperlink} leading to the git revision on github
 *
 * @return The {@link Hyperlink} leading to the git revision on github
 */
private Hyperlink createGitRevisionHyperlink() {
    final StringBinding revisionText = Bindings.createStringBinding(
            () -> Optional.ofNullable(getControl().getBuildInformation())
                    .map(ApplicationBuildInformation::getApplicationGitRevision).orElse(null),
            getControl().buildInformationProperty());

    final BooleanBinding disableProperty = Bindings.when(Bindings
            .and(Bindings.isNotNull(revisionText), Bindings.notEqual(revisionText, "unknown")))
            .then(false).otherwise(true);

    final Hyperlink gitRevisionHyperlink = new Hyperlink();

    gitRevisionHyperlink.textProperty().bind(revisionText);

    // if the git revision equals "unknown" disable the hyperlink
    gitRevisionHyperlink.disableProperty().bind(disableProperty);
    gitRevisionHyperlink.visitedProperty().bind(disableProperty);
    gitRevisionHyperlink.underlineProperty().bind(disableProperty);

    // if the git revision has been clicked on open the corresponding commit page on github
    gitRevisionHyperlink.setOnAction(event -> {
        try {
            final URI uri = new URI("https://github.com/PhoenicisOrg/phoenicis/commit/"
                    + getControl().getBuildInformation().getApplicationGitRevision());

            getControl().getOpener().open(uri);
        } catch (URISyntaxException e) {
            LOGGER.error("Could not open GitHub URL.", e);
        }
    });

    return gitRevisionHyperlink;
}
 
Example 8
Source File: JFXLinkLabel.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Hyperlink createHyperlink(final String text, final String value) {
	Hyperlink hyperLink = new Hyperlink(text);
	hyperLink.setPadding(new Insets(0));
	hyperLink.setOnAction(new EventHandler<ActionEvent>() {
		public void handle(ActionEvent event) {
			JFXLinkLabel.this.fireEvent(value);
		}
	});
	if( this.getFont() != null ) {
		hyperLink.setFont(((JFXFont) this.getFont()).getHandle());
	}
	return hyperLink;
}
 
Example 9
Source File: LanguageSelectionPane.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
private void addLanguage(@NotNull Language language) {
	if (links.containsKey(language)) {
		return;
	}
	Hyperlink hyperlinkLanguage = new Hyperlink(language.getName());
	hyperlinkLanguage.setOnAction(new EventHandler<ActionEvent>() {
		@Override
		public void handle(ActionEvent event) {
			hyperlinkLanguage.setVisited(false);
			chosenLanguageObserver.updateValue(language);
		}
	});

	getChildren().add(hyperlinkLanguage);
}
 
Example 10
Source File: CheckPane.java    From pattypan with MIT License 5 votes vote down vote up
/**
 * Shows details of selected file
 *
 * @param ue
 */
private void setDetails(UploadElement ue, Hyperlink label) {
  String name = Util.getNormalizedName(ue.getData("name"));

  WikiLabel title = new WikiLabel(name).setClass("header").setAlign("left");
  WikiLabel path = new WikiLabel(ue.getData("path")).setAlign("left");
  Hyperlink pathURL = new Hyperlink(ue.getData("path"));
  Hyperlink preview = new Hyperlink(Util.text("check-preview"));
  WikiLabel wikitext = new WikiLabel(ue.getWikicode()).setClass("monospace").setAlign("left");

  prevLabel.getStyleClass().remove("bold");
  prevLabel = label;
  prevLabel.getStyleClass().add("bold");

  preview.setOnAction(event -> {
    try {
      Util.openUrl(Session.WIKI.getProtocol() + Session.WIKI.getDomain()
              + "/wiki/Special:ExpandTemplates"
              + "?wpRemoveComments=true"
              + "&wpInput=" + URLEncoder.encode(ue.getWikicode(), "UTF-8")
              + "&wpContextTitle=" + URLEncoder.encode(name, "UTF-8"));
    } catch (UnsupportedEncodingException ex) {
      Session.LOGGER.log(Level.SEVERE, null, ex);
    }
  });

  pathURL.setOnAction(event -> {
    Util.openUrl(ue.getData("path"));
  });

  detailsContainer.getChildren().clear();

  if (ue.getData("path").startsWith("https://") || ue.getData("path").startsWith("http://")) {
    detailsContainer.getChildren().addAll(title, pathURL, preview, wikitext);
  } else {
    detailsContainer.getChildren().addAll(title, path, getScaledThumbnail(ue.getFile()), preview, wikitext);
  }
}
 
Example 11
Source File: InfoController.java    From G-Earth with MIT License 5 votes vote down vote up
public static void activateHyperlink(Hyperlink link) {
    link.setOnAction((ActionEvent event) -> {
        Hyperlink h = (Hyperlink) event.getTarget();
        String s = h.getTooltip().getText();
        Main.main.getHostServices().showDocument(s);
        event.consume();
    });
}
 
Example 12
Source File: RestObjectView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public RestObjectView() {

        Label lbQuestionId = new Label();
        Label lbTitle = new Label();
        Hyperlink hlLink = new Hyperlink();

        GridPane gridPane = new GridPane();
        gridPane.setVgap(5.0);
        gridPane.setHgap(5.0);
        gridPane.setPadding(new Insets(5.0));
        gridPane.addRow(0, new Label("Question ID:"), lbQuestionId);
        gridPane.addRow(1, new Label("Title:"), lbTitle);
        gridPane.addRow(2, new Label("Link:"), hlLink);
        gridPane.getColumnConstraints().add(new ColumnConstraints(75));

        lbQuestionId.setWrapText(true);
        lbTitle.setWrapText(true);
        hlLink.setWrapText(true);

        hlLink.setOnAction(e -> {
            if (Platform.isDesktop()) {
                getApplication().getHostServices().showDocument(hlLink.getText());
            } else {
                Services.get(BrowserService.class).ifPresent(service -> {
                    try {
                        service.launchExternalBrowser(hlLink.getText());
                    } catch (IOException | URISyntaxException ex) {
                        Alert alert = new Alert(Alert.AlertType.ERROR);
                        alert.setTitle("Failed to open URL");
                        alert.setContentText("Failed to open URL. Reason: " + ex.getMessage());
                        alert.showAndWait();
                    }
                });
            }
        });

        setCenter(gridPane);

        // create a RestClient to the specific URL
        RestClient restClient = RestClient.create()
                .method("GET")
                .host("https://api.stackexchange.com")
                .path("/2.2/questions/36243147")
                .queryParam("order", "desc")
                .queryParam("sort", "activity")
                .queryParam("site", "stackoverflow");

        // create a custom Converter that is able to parse the response into a single object
        InputStreamInputConverter<Question> converter = new SingleItemInputConverter<>(Question.class);

        // retrieve an object from the DataProvider
        GluonObservableObject<Question> question = DataProvider.retrieveObject(restClient.createObjectDataReader(converter));

        // when the object is initialized, bind its properties to the JavaFX UI controls
        question.initializedProperty().addListener((obs, oldValue, newValue) -> {
            if (newValue) {
                lbQuestionId.textProperty().bind(question.get().questionIdProperty().asString());
                lbTitle.textProperty().bind(question.get().titleProperty());
                hlLink.textProperty().bind(question.get().linkProperty());
            }
        });
    }
 
Example 13
Source File: Main.java    From ShootOFF with GNU General Public License v3.0 4 votes vote down vote up
public void checkVersion() {
	final Optional<String> versionXML = getVersionXML(SHOOTOFF_DOMAIN + VERSION_METADATA_NAME);

	if (versionXML.isPresent()) {
		final Optional<String> stableVersion = parseField(versionXML.get(), "stableRelease", "version");

		if (stableVersion.isPresent() && VersionChecker.compareVersions(stableVersion.get(), version.get()) > 0) {
			final Optional<String> downloadLink = parseField(versionXML.get(), "stableRelease", "download");

			final String link;

			if (downloadLink.isPresent())
				link = downloadLink.get();
			else
				link = SHOOTOFF_DOMAIN;

			final Alert shootoffWelcome = new Alert(AlertType.INFORMATION);
			shootoffWelcome.setTitle("ShootOFF Updated");
			shootoffWelcome.setHeaderText("This version of ShootOFF is outdated!");
			shootoffWelcome.setResizable(true);

			final FlowPane fp = new FlowPane();
			final Label lbl = new Label(
					"The current stable release of ShootOFF is " + stableVersion.get() + ", but you are running "
							+ version.get() + ". " + "You can download the current version of ShootOFF here:\n\n");

			final Hyperlink lnk = new Hyperlink(link);

			lnk.setOnAction((event) -> {
				final HostServicesDelegate hostServices = HostServicesFactory.getInstance(this);
				hostServices.showDocument(link);
				lnk.setVisited(true);
			});

			fp.getChildren().addAll(lbl, lnk);

			shootoffWelcome.getDialogPane().contentProperty().set(fp);
			shootoffWelcome.showAndWait();
		} else if (stableVersion.isPresent() && stableVersion.get().compareTo(version.get()) < 0) {
			logger.warn("Future version of ShootOFF? stableVersion = {}, this.version = {}", stableVersion.get(),
					version.get());
		} else {
			logger.debug("ShootOFF is up to date");
		}
	}
}
 
Example 14
Source File: About.java    From Game2048FX with GNU General Public License v3.0 4 votes vote down vote up
public About() {
    
    HBox title = new HBox(10);
    title.setAlignment(Pos.CENTER_LEFT);
    title.getChildren().add(new ImageView());
    title.getChildren().add(new Label("About the App"));
    
    Dialog<ButtonType> dialog = new Dialog<>();
    
    Text t00 = new Text("2048");
    t00.getStyleClass().setAll("game-label","game-lblAbout");
    Text t01 = new Text("FX");
    t01.getStyleClass().setAll("game-label","game-lblAbout2");
    Text t02 = new Text(" Game\n");
    t02.getStyleClass().setAll("game-label","game-lblAbout");
    Text t1 = new Text("JavaFX game - " + Platform.getCurrent().name() + " version\n\n");
    t1.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Text t20 = new Text("Powered by ");
    t20.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Hyperlink link11 = new Hyperlink();
    link11.setText("JavaFXPorts");
    link11.setOnAction(e -> browse("http://gluonhq.com/open-source/javafxports/"));
    link11.getStyleClass().setAll("game-label", "game-lblAboutSub2");
    Text t210 = new Text(" & ");
    t210.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Hyperlink link12 = new Hyperlink();
    link12.setText("Gluon Mobile");
    link12.setOnAction(e -> browse("https://gluonhq.com/products/mobile/"));
    link12.getStyleClass().setAll("game-label", "game-lblAboutSub2");
    Text t21 = new Text(" Projects \n\n");
    t21.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Text t23 = new Text("\u00A9 ");
    t23.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Hyperlink link2 = new Hyperlink();
    link2.setText("José Pereda");
    link2.setOnAction(e -> browse("https://twitter.com/JPeredaDnr"));
    link2.getStyleClass().setAll("game-label", "game-lblAboutSub2");
    Text t22 = new Text(", ");
    t22.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Hyperlink link3 = new Hyperlink();
    link3.setText("Bruno Borges");
    link3.setOnAction(e -> browse("https://twitter.com/brunoborges"));
    Text t32 = new Text(" & ");
    t32.getStyleClass().setAll("game-label", "game-lblAboutSub");
    link3.getStyleClass().setAll("game-label", "game-lblAboutSub2");
    Hyperlink link4 = new Hyperlink();
    link4.setText("Jens Deters");
    link4.setOnAction(e -> browse("https://twitter.com/Jerady"));
    link4.getStyleClass().setAll("game-label", "game-lblAboutSub2");
    Text t24 = new Text("\n\n");
    t24.getStyleClass().setAll("game-label", "game-lblAboutSub");

    Text t31 = new Text(" Version " + Game2048.VERSION + " - " + Year.now().toString() + "\n\n");
    t31.getStyleClass().setAll("game-label", "game-lblAboutSub");

    TextFlow flow = new TextFlow();
    flow.setTextAlignment(TextAlignment.CENTER);
    flow.setPadding(new Insets(10,0,0,0));

    flow.getChildren().setAll(t00, t01, t02, t1, t20, link11, t210, link12, t21, t23, link2, t22, link3);
    flow.getChildren().addAll(t32, link4);
    flow.getChildren().addAll(t24, t31);
    
    final ImageView imageView = new ImageView();
    imageView.getStyleClass().add("about");
    
    double scale = Services.get(DisplayService.class)
            .map(display -> {
                if (display.isTablet()) {
                    flow.setTranslateY(30);
                    return 1.3;
                } else {
                    flow.setTranslateY(25);
                    return 1.0;
                }
            })
            .orElse(1.0);
    
    imageView.setFitWidth(270 * scale);
    imageView.setFitHeight(270 * scale);
    imageView.setOpacity(0.1);
    
    dialog.setContent(new StackPane(imageView, flow));
    dialog.setTitle(title);
    
    Button yes = new Button("Accept");
    yes.setOnAction(e -> {
        dialog.setResult(ButtonType.YES); 
        dialog.hide();
    });
    yes.setDefaultButton(true);
    dialog.getButtons().addAll(yes);
    javafx.application.Platform.runLater(dialog::showAndWait);
}
 
Example 15
Source File: ChooseColumnsPane.java    From pattypan with MIT License 4 votes vote down vote up
/**
 * Adds checkboxes with wikitemplate fields.
 *
 * @param templateName name of wikitemplate
 * @return true, if template exists
 */
private boolean showTemplateFields(String templateName) {
  Template template = Settings.TEMPLATES.get(templateName);

  Hyperlink docLink = new Hyperlink(Util.text("choose-columns-template-doc"));
  docLink.setMinHeight(25);
  docLink.setOnAction(event -> {
    Util.openUrl("https://commons.wikimedia.org/wiki/Template:" + template.name + "/doc");
  });

  templateDescContainer.getChildren().clear();
  templateDescContainer.getChildren().add(new HBox(10,
          new WikiLabel("{{" + template.name + "}}")
                  .setClass("header")
                  .setAlign("left"),
          docLink
  ));
  templateDescContainer.getChildren().add(
          new WikiLabel("choose-columns-template-intro")
                  .setAlign("left")
                  .setHeight(70));

  HBox headersContainer = new HBox(10);
  headersContainer.getChildren().addAll(
          new WikiLabel("choose-columns-fields-name")
                  .setClass("bold")
                  .setWidth(200, 495)
                  .setHeight(35),
          new WikiLabel("choose-columns-radio-buttons")
                  .setClass("bold")
                  .setWidth(150)
                  .setHeight(35),
          new WikiLabel("choose-columns-value")
                  .setClass("bold")
                  .setWidth(50, 500)
                  .setHeight(35));
  templateDescContainer.getChildren().add(headersContainer);

  for (TemplateField tf : template.variables) {
    templateDescContainer.getChildren().add(tf.getRow());
  }
  return true;
}
 
Example 16
Source File: AboutDialog.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@FxThread
protected void createContent(@NotNull final VBox root) {
    super.createContent(root);

    final JfxApplication application = JfxApplication.getInstance();
    final HostServices hostServices = application.getHostServices();

    final GridPane gridPane = new GridPane();

    final Label applicationLabel = new Label(Config.TITLE);
    applicationLabel.setGraphic(new ImageView(Icons.APPLICATION_64));

    final Label versionLabel = new Label(Messages.ABOUT_DIALOG_VERSION + ":");
    versionLabel.prefWidthProperty().bind(gridPane.widthProperty().multiply(0.5));

    final Label versionField = new Label(Config.STRING_VERSION);

    final Label projectHomeLabel = new Label(Messages.ABOUT_DIALOG_PROJECT_HOME + ":");

    final Hyperlink projectHomeField = new Hyperlink("bitbucket.org");
    projectHomeField.setOnAction(event -> hostServices.showDocument(PROJECT_HOME));
    projectHomeField.setFocusTraversable(false);

    final Label forumThreadLabel = new Label(Messages.ABOUT_DIALOG_FORUM_THREAD + ":");

    final Hyperlink forumThreadField = new Hyperlink("hub.jmonkeyengine.org");
    forumThreadField.setOnAction(event -> hostServices.showDocument(FORUM_THREAD));
    forumThreadField.setFocusTraversable(false);

    final Label usedLibrariesLabel = new Label(Messages.ABOUT_DIALOG_USED_LIBRARIES + ":");
    usedLibrariesLabel.prefWidthProperty().bind(gridPane.widthProperty());

    final Label usedIcons = new Label(Messages.ABOUT_DIALOG_USED_ICONS + ":");
    usedIcons.prefWidthProperty().bind(gridPane.widthProperty());

    final TextArea librariesArea = new TextArea(LIBRARIES);
    librariesArea.setEditable(false);
    librariesArea.setFocusTraversable(false);

    final TextArea iconsArea = new TextArea(ICONS);
    iconsArea.setEditable(false);
    iconsArea.setFocusTraversable(false);

    gridPane.add(applicationLabel, 0, 0, 2, 1);
    gridPane.add(versionLabel, 0, 1, 1, 1);
    gridPane.add(versionField, 1, 1, 1, 1);
    gridPane.add(projectHomeLabel, 0, 2, 1, 1);
    gridPane.add(projectHomeField, 1, 2, 1, 1);
    gridPane.add(forumThreadLabel, 0, 3, 1, 1);
    gridPane.add(forumThreadField, 1, 3, 1, 1);
    gridPane.add(usedLibrariesLabel, 0, 4, 2, 1);
    gridPane.add(librariesArea, 0, 5, 2, 1);
    gridPane.add(usedIcons, 0, 6, 2, 1);
    gridPane.add(iconsArea, 0, 7, 2, 1);

    FXUtils.addToPane(gridPane, root);

    FXUtils.addClassTo(root, CssClasses.ABOUT_DIALOG);
    FXUtils.addClassTo(gridPane, CssClasses.DEF_GRID_PANE);
    FXUtils.addClassTo(usedLibrariesLabel, usedIcons, CssClasses.ABOUT_DIALOG_LONG_LABEL);
    FXUtils.addClassesTo(versionLabel, projectHomeLabel, forumThreadLabel, usedLibrariesLabel, usedIcons,
            versionField, projectHomeField, forumThreadField, CssClasses.SPECIAL_FONT_16);
    FXUtils.addClassTo(applicationLabel, CssClasses.ABOUT_DIALOG_TITLE_LABEL);
}
 
Example 17
Source File: ConfigController.java    From logbook-kai with MIT License 4 votes vote down vote up
private void bouyomiChanInit() {
    AppBouyomiConfig config = AppBouyomiConfig.get();

    this.enableBouyomi.setSelected(config.isEnable());
    this.bouyomiHost.setText(config.getHost());
    this.bouyomiPort.setText(Integer.toString(config.getPort()));
    this.bouyomiTryExecute.setSelected(config.isTryExecute());
    this.bouyomiPath.setText(config.getBouyomiPath());

    BouyomiDefaultSettings settings = BouyomiChanUtils.getDefaultSettings();
    int row = 0;
    for (BouyomiSetting setting : settings.getSettings()) {
        BouyomiChanUtils.Type type = BouyomiChanUtils.Type.valueOf(setting.getId());

        AppBouyomiText bouyomiConfig = config.getText()
                .get(setting.getId());

        CheckBox checkBox = new CheckBox(setting.getLabel());
        checkBox.setSelected(true);

        TextField text = new TextField(setting.getText());
        TextFlow params = new TextFlow();
        for (Params param : setting.getParams()) {
            Hyperlink link = new Hyperlink(param.getComment());
            link.setFocusTraversable(false);
            link.setOnAction(ev -> {
                text.replaceSelection(param.getTag());
            });
            params.getChildren().add(link);
        }
        if (bouyomiConfig != null) {
            checkBox.setSelected(bouyomiConfig.isEnable());
            text.setText(bouyomiConfig.getText());
        }

        this.bouyomiTexts.add(checkBox, 0, row);
        this.bouyomiTexts.add(text, 1, row);
        GridPane.setHgrow(text, Priority.ALWAYS);
        this.bouyomiTexts.add(params, 1, ++row);
        row++;

        this.enableBouyomiTextMap.put(type, checkBox::isSelected);
        this.bouyomiTextMap.put(type, text::getText);
    }
}
 
Example 18
Source File: InfoDisplay.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
public InfoDisplay() {
    icon.setId("non-clickable-icon");
    icon.visibleProperty().bind(visibleProperty());

    GridPane.setValignment(icon, VPos.TOP);
    GridPane.setMargin(icon, new Insets(-2, 0, 0, 0));
    GridPane.setRowSpan(icon, 2);

    label = new AutoTooltipLabel();
    label.textProperty().bind(text);
    label.setTextOverrun(OverrunStyle.WORD_ELLIPSIS);
    // width is set a frame later so we hide it first
    label.setVisible(false);

    link = new Hyperlink(Res.get("shared.readMore"));
    link.setPadding(new Insets(0, 0, 0, -2));

    // We need that to know if we have a wrapping or not.
    // Did not find a way to get that from the API.
    Label testLabel = new AutoTooltipLabel();
    testLabel.textProperty().bind(text);

    textFlow = new TextFlow();
    textFlow.visibleProperty().bind(visibleProperty());
    textFlow.getChildren().addAll(testLabel);

    testLabel.widthProperty().addListener((ov, o, n) -> {
        useReadMore = (double) n > textFlow.getWidth();
        link.setText(Res.get(useReadMore ? "shared.readMore" : "shared.openHelp"));
        UserThread.execute(() -> textFlow.getChildren().setAll(label, link));
    });

    // update the width when the window gets resized
    ChangeListener<Number> listener = (ov2, oldValue2, windowWidth) -> {
        if (label.prefWidthProperty().isBound())
            label.prefWidthProperty().unbind();
        label.setPrefWidth((double) windowWidth - localToScene(0, 0).getX() - 35);
    };


    // when clicking "Read more..." we expand and change the link to the Help
    link.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            if (useReadMore) {

                label.setWrapText(true);
                link.setText(Res.get("shared.openHelp"));
                getScene().getWindow().widthProperty().removeListener(listener);
                if (label.prefWidthProperty().isBound())
                    label.prefWidthProperty().unbind();
                label.prefWidthProperty().bind(textFlow.widthProperty());
                link.setVisited(false);
                // focus border is a bit confusing here so we remove it
                link.getStyleClass().add("hide-focus");
                link.setOnAction(onAction.get());
                getParent().layout();
            } else {
                onAction.get().handle(actionEvent);
            }
        }
    });

    sceneProperty().addListener((ov, oldValue, newValue) -> {
        if (oldValue == null && newValue != null && newValue.getWindow() != null) {
            newValue.getWindow().widthProperty().addListener(listener);
            // localToScene does deliver 0 instead of the correct x position when scene property gets set,
            // so we delay for 1 render cycle
            UserThread.execute(() -> {
                label.setVisible(true);
                label.prefWidthProperty().unbind();
                label.setPrefWidth(newValue.getWindow().getWidth() - localToScene(0, 0).getX() - 35);
            });
        }
    });
}
 
Example 19
Source File: HelpfulPlaceholder.java    From pmd-designer with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public PlaceHolderBuilder withSuggestedAction(String message, Runnable action) {
    Hyperlink hyperlink = new Hyperlink(message);
    hyperlink.setOnAction(e -> action.run());
    myActions.add(hyperlink);
    return this;
}