-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
311 changed files
with
959 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ jdks | |
.bach/workspace | ||
.bach/external-tools | ||
.bach/external-modules | ||
bin | ||
.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
core/ikonli-core/src/main/java/org/kordamp/ikonli/DefaultIkonResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2015-2025 Andres Almiray | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kordamp.ikonli; | ||
|
||
public class DefaultIkonResolver extends AbstractIkonResolver implements IkonResolver { | ||
private final FontLoader fontLoader; | ||
private static volatile DefaultIkonResolver instance; | ||
|
||
protected DefaultIkonResolver(FontLoader fontLoader) { | ||
this.fontLoader = fontLoader; | ||
resolveServiceLoader().forEach(handler -> { | ||
handlers.add(handler); | ||
fontLoader.loadFont(handler); | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean registerHandler(IkonHandler handler) { | ||
boolean result = super.registerHandler(handler); | ||
if (result) { | ||
fontLoader.loadFont(handler); | ||
} | ||
return result; | ||
} | ||
|
||
public static IkonResolver getInstance(FontLoader fontLoader) { | ||
if (instance == null) { | ||
synchronized (DefaultIkonResolver.class) { | ||
if (instance == null) { | ||
instance = new DefaultIkonResolver(fontLoader); | ||
} | ||
} | ||
} | ||
return instance; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
core/ikonli-core/src/main/java/org/kordamp/ikonli/FontLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2015-2025 Andres Almiray | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kordamp.ikonli; | ||
|
||
public interface FontLoader { | ||
|
||
void loadFont(IkonHandler handler); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
core/ikonli-core/src/main/java/org/kordamp/ikonli/IkonResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2015-2025 Andres Almiray | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kordamp.ikonli; | ||
|
||
public interface IkonResolver { | ||
|
||
IkonHandler resolve(String value); | ||
|
||
boolean registerHandler(IkonHandler handler); | ||
|
||
boolean unregisterHandler(IkonHandler handler); | ||
} |
85 changes: 85 additions & 0 deletions
85
core/ikonli-core/src/main/java/org/kordamp/ikonli/IkonResolverProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2015-2025 Andres Almiray | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kordamp.ikonli; | ||
|
||
import org.osgi.framework.Bundle; | ||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.FrameworkUtil; | ||
import org.osgi.framework.ServiceReference; | ||
|
||
public class IkonResolverProvider { | ||
private static volatile IkonResolver instance; | ||
|
||
private IkonResolverProvider() { | ||
} | ||
|
||
public static IkonResolver getInstance(FontLoader fontLoader) { | ||
IkonResolver localInstance = instance; | ||
if (localInstance == null) { | ||
synchronized (IkonResolverProvider.class) { | ||
localInstance = instance; | ||
if (localInstance == null) { | ||
instance = localInstance = createIkonResolver(fontLoader); | ||
} | ||
} | ||
} | ||
return localInstance; | ||
} | ||
|
||
private static IkonResolver createIkonResolver(FontLoader fontLoader) { | ||
return tryGetOSGiResolver().orElseGet(() -> DefaultIkonResolver.getInstance(fontLoader)); | ||
} | ||
|
||
private static java.util.Optional<IkonResolver> tryGetOSGiResolver() { | ||
try { | ||
if (!isOSGiAvailable()) { | ||
return java.util.Optional.empty(); | ||
} | ||
|
||
Bundle bundle = FrameworkUtil.getBundle(IkonResolverProvider.class); | ||
if (bundle == null) { | ||
return java.util.Optional.empty(); | ||
} | ||
|
||
BundleContext context = bundle.getBundleContext(); | ||
if (context == null) { | ||
return java.util.Optional.empty(); | ||
} | ||
|
||
ServiceReference<IkonResolver> ref = context.getServiceReference(IkonResolver.class); | ||
if (ref == null) { | ||
return java.util.Optional.empty(); | ||
} | ||
|
||
IkonResolver resolver = context.getService(ref); | ||
return java.util.Optional.ofNullable(resolver); | ||
|
||
} catch (NoClassDefFoundError | IllegalStateException e) { | ||
return java.util.Optional.empty(); | ||
} | ||
} | ||
|
||
private static boolean isOSGiAvailable() { | ||
try { | ||
Class.forName("org.osgi.framework.BundleContext"); | ||
return true; | ||
} catch (ClassNotFoundException e) { | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.