Skip to content

Commit

Permalink
8301121: rich text area control
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-goryachev-oracle committed Feb 21, 2024
1 parent ee8633c commit 425b5f4
Show file tree
Hide file tree
Showing 162 changed files with 30,597 additions and 12 deletions.
112 changes: 101 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2749,6 +2749,87 @@ project(":controls") {
addValidateSourceSets(project, sourceSets)
}

project(":incubator.controls") {
project.ext.buildModule = true
project.ext.includeSources = true
project.ext.moduleRuntime = true
project.ext.moduleName = "javafx.incubator.controls"
project.ext.incubating = true

sourceSets {
main
shims {
java {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
}
test {
java {
compileClasspath += sourceSets.shims.output
runtimeClasspath += sourceSets.shims.output
}
}
}

project.ext.moduleSourcePath = defaultModuleSourcePath
project.ext.moduleSourcePathShim = defaultModuleSourcePathShim

commonModuleSetup(project, [ 'base', 'graphics', 'controls', 'incubator.controls' ])

dependencies {
testImplementation project(":base").sourceSets.test.output
testImplementation project(":graphics").sourceSets.test.output
testImplementation project(":controls").sourceSets.test.output
implementation project(':base')
implementation project(':graphics')
implementation project(':controls')
}

test {
jvmArgs "-Djavafx.toolkit=test.com.sun.javafx.pgstub.StubToolkit"
}

def modulePath = "${project.sourceSets.main.java.getDestinationDirectory().get().getAsFile()}"
modulePath += File.pathSeparator + "${rootProject.projectDir}/modules/javafx.controls/build/classes/java/main"
modulePath += File.pathSeparator + "${rootProject.projectDir}/modules/javafx.graphics/build/classes/java/main"
modulePath += File.pathSeparator + "${rootProject.projectDir}/modules/javafx.base/build/classes/java/main"

// FIXME: KCR
// processResources {
// doLast {
// def cssFiles = fileTree(dir: "$moduleDir/com/sun/javafx/scene/control/skin")
// cssFiles.include "**/*.css"
// cssFiles.each { css ->
// logger.info("converting CSS to BSS ${css}");
//
// javaexec {
// executable = JAVA
// workingDir = project.projectDir
// jvmArgs += patchModuleArgs
// jvmArgs += "--module-path=$modulePath"
// jvmArgs += "--add-modules=javafx.graphics"
// mainClass = "com.sun.javafx.css.parser.Css2Bin"
// args css
// }
// }
// }
// }
//
// def copyShimBssTask = project.task("copyShimBss", type: Copy,
// dependsOn: [project.tasks.getByName("compileJava"),
// project.tasks.getByName("processResources")]) {
// from project.moduleDir
// into project.moduleShimsDir
// include "**/*.bss"
// }
// processShimsResources.dependsOn(copyShimBssTask)

addMavenPublication(project, [ 'graphics' , 'controls'])

addValidateSourceSets(project, sourceSets)
}

project(":swing") {

// We need to skip setting compiler.options.release for this module,
Expand Down Expand Up @@ -4240,7 +4321,7 @@ task javadoc(type: Javadoc, dependsOn: createMSPfile) {
description = "Generates the JavaDoc for all the public API"
executable = JAVADOC
def projectsToDocument = [
project(":base"), project(":graphics"), project(":controls"), project(":media"),
project(":base"), project(":graphics"), project(":controls"), project(":incubator.controls"), project(":media"),
project(":swing"), /*project(":swt"),*/ project(":fxml"), project(":web")]
source(projectsToDocument.collect({
[it.sourceSets.main.java]
Expand Down Expand Up @@ -5563,6 +5644,7 @@ compileTargets { t ->
def modnames = []
moduleProjList.each { project ->
if (project.hasProperty("moduleName") && project.buildModule) {
def incubating = project.hasProperty("incubating") && project.ext.incubating
modnames << project.ext.moduleName
File dir;
if (project.sourceSets.hasProperty('shims')) {
Expand All @@ -5574,16 +5656,18 @@ compileTargets { t ->
def dstModuleDir = cygpath(dir.path)
modpath << "${dstModuleDir}"

String themod = dir.toURI()
testJavaPolicyFile << "grant codeBase \"${themod}\" {\n" +
" permission java.security.AllPermission;\n" +
"};\n"

dir = new File(rootProject.buildDir, "sdk/lib/${project.ext.moduleName}.jar")
themod = dir.toURI()
runJavaPolicyFile << "grant codeBase \"${themod}\" {\n" +
" permission java.security.AllPermission;\n" +
"};\n"
if (!incubating) {
String themod = dir.toURI()
testJavaPolicyFile << "grant codeBase \"${themod}\" {\n" +
" permission java.security.AllPermission;\n" +
"};\n"

dir = new File(rootProject.buildDir, "sdk/lib/${project.ext.moduleName}.jar")
themod = dir.toURI()
runJavaPolicyFile << "grant codeBase \"${themod}\" {\n" +
" permission java.security.AllPermission;\n" +
"};\n"
}
}
}

Expand Down Expand Up @@ -5629,6 +5713,8 @@ compileTargets { t ->
def jmodName = "${moduleName}.jmod"
def jmodFile = "${jmodsDir}/${jmodName}"

def incubating = project.hasProperty("incubating") && project.ext.incubating

// On Windows, copy the native libraries in the jmod image
// to a "javafx" subdir to avoid conflicting with the Microsoft
// DLLs that are shipped with the JDK
Expand Down Expand Up @@ -5672,6 +5758,10 @@ compileTargets { t ->
if (sourceDateEpoch != null && status >= 0) {
args("--date", extendedTimestamp)
}
if (incubating) {
args("--do-not-resolve-by-default")
args("--warn-if-resolved=incubating")
}
args(jmodFile)
}
}
Expand Down
1 change: 1 addition & 0 deletions modules/javafx.base/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

exports com.sun.javafx to
javafx.controls,
javafx.incubator.controls,
javafx.graphics,
javafx.fxml,
javafx.media,
Expand Down
1 change: 1 addition & 0 deletions modules/javafx.graphics/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
exports com.sun.javafx.util to
javafx.controls,
javafx.fxml,
javafx.incubator.controls,
javafx.media,
javafx.swing,
javafx.web;
Expand Down
53 changes: 53 additions & 0 deletions modules/javafx.incubator.controls/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" output="testbin" path="src/shims/java">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="testbin" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="testbin" path="src/test/resources">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="/controls">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="/graphics">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/base">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/swing">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions modules/javafx.incubator.controls/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>incubator.controls</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
12 changes: 12 additions & 0 deletions modules/javafx.incubator.controls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Incubator

This project incubates
[RichTextArea](src/main/java/javafx/incubator/scene/control/rich/RichTextArea.java)
and
[CodeArea](src/main/java/javafx/incubator/scene/control/rich/code/CodeArea.java)
controls.


## Demo Projects

Please refer to this [README](/tests/manual/RichTextAreaDemo/README.md).
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.javafx.incubator.scene.control.input;

import java.util.ArrayList;
import java.util.Iterator;
import javafx.event.EventHandler;

/**
* List of event handlers, which can be added to its head or tail.
* the order of handlers in the list is guaranteed to be:
* (first added to the head), (second added to the head), ..., (second added to the tail), (first added to the tail).
*/
public class HList implements Iterable<EventHandler<?>> {
private final ArrayList<EventHandler<?>> handlers = new ArrayList<>(4);
private int insertIndex;

public HList() {
}

public static HList from(Object x) {
if (x instanceof HList h) {
return h;
}
return new HList();
}

public void add(EventHandler<?> h, boolean tail) {
if (insertIndex == handlers.size()) {
handlers.add(h);
} else {
handlers.add(insertIndex, h);
}

if (!tail) {
insertIndex++;
}
}

@Override
public Iterator<EventHandler<?>> iterator() {
return handlers.iterator();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.sun.javafx.incubator.scene.control.rich;

import java.util.HashMap;
import javafx.incubator.scene.control.rich.StyleResolver;
import javafx.incubator.scene.control.rich.model.StyleAttrs;
import javafx.scene.Node;
import javafx.scene.image.WritableImage;

/**
* Caching StyleResolver caches conversion results to avoid re-querying for the same information.
*/
public class CachingStyleResolver implements StyleResolver {
private final StyleResolver resolver;
private final HashMap<CssStyles, StyleAttrs> cache = new HashMap<>();

public CachingStyleResolver(StyleResolver r) {
this.resolver = r;
}

@Override
public StyleAttrs resolveStyles(StyleAttrs attrs) {
CssStyles css = attrs.get(CssStyles.CSS);
if (css != null) {
// no conversion is needed
return attrs;
}

StyleAttrs a = cache.get(css);
if (a == null) {
a = resolver.resolveStyles(attrs);
cache.put(css, a);
}
return a;
}

@Override
public WritableImage snapshot(Node node) {
return resolver.snapshot(node);
}
}

0 comments on commit 425b5f4

Please sign in to comment.