mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 15:27:16 -06:00
StringUtils added
This commit is contained in:
@@ -241,10 +241,6 @@ public abstract class FlatLaf
|
|||||||
defaults.put( "MenuItem.acceleratorFont", uiFont );
|
defaults.put( "MenuItem.acceleratorFont", uiFont );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> split( String str, char delim ) {
|
|
||||||
return UIDefaultsLoader.split( str, delim );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void reSetLookAndFeel() {
|
private static void reSetLookAndFeel() {
|
||||||
EventQueue.invokeLater( () -> {
|
EventQueue.invokeLater( () -> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import javax.swing.UIDefaults;
|
|||||||
import javax.swing.plaf.ColorUIResource;
|
import javax.swing.plaf.ColorUIResource;
|
||||||
import com.formdev.flatlaf.json.Json;
|
import com.formdev.flatlaf.json.Json;
|
||||||
import com.formdev.flatlaf.json.ParseException;
|
import com.formdev.flatlaf.json.ParseException;
|
||||||
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -183,15 +184,14 @@ public class IntelliJTheme
|
|||||||
|
|
||||||
boolean checkboxModified = false;
|
boolean checkboxModified = false;
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" )
|
||||||
Map<String, Object> map = (Map<String, Object>) palette;
|
Map<String, Object> colorPalette = (Map<String, Object>) palette;
|
||||||
for( Map.Entry<String, Object> e : map.entrySet() ) {
|
for( Map.Entry<String, Object> e : colorPalette.entrySet() ) {
|
||||||
String key = e.getKey();
|
String key = e.getKey();
|
||||||
Object value = e.getValue();
|
Object value = e.getValue();
|
||||||
if( !key.startsWith( "Checkbox." ) || !(value instanceof String) )
|
if( !key.startsWith( "Checkbox." ) || !(value instanceof String) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( key.endsWith( ".Dark" ) )
|
key = StringUtils.removeTrailing( key, ".Dark" );
|
||||||
key = key.substring( 0, key.length() - 5 );
|
|
||||||
|
|
||||||
String newKey = checkboxKeyMapping.get( key );
|
String newKey = checkboxKeyMapping.get( key );
|
||||||
if( newKey != null ) {
|
if( newKey != null ) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import javax.swing.text.StyleContext;
|
import javax.swing.text.StyleContext;
|
||||||
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,7 +152,7 @@ class LinuxFontPolicy
|
|||||||
int size = 10;
|
int size = 10;
|
||||||
|
|
||||||
if( generalFont != null ) {
|
if( generalFont != null ) {
|
||||||
List<String> strs = FlatLaf.split( generalFont, ',' );
|
List<String> strs = StringUtils.split( generalFont, ',' );
|
||||||
try {
|
try {
|
||||||
family = strs.get( 0 );
|
family = strs.get( 0 );
|
||||||
size = Integer.parseInt( strs.get( 1 ) );
|
size = Integer.parseInt( strs.get( 1 ) );
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import com.formdev.flatlaf.ui.FlatLineBorder;
|
|||||||
import com.formdev.flatlaf.util.ColorFunctions;
|
import com.formdev.flatlaf.util.ColorFunctions;
|
||||||
import com.formdev.flatlaf.util.DerivedColor;
|
import com.formdev.flatlaf.util.DerivedColor;
|
||||||
import com.formdev.flatlaf.util.ScaledNumber;
|
import com.formdev.flatlaf.util.ScaledNumber;
|
||||||
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load UI defaults from properties files associated to Flat LaF classes and add to UI defaults.
|
* Load UI defaults from properties files associated to Flat LaF classes and add to UI defaults.
|
||||||
@@ -255,7 +256,7 @@ class UIDefaultsLoader
|
|||||||
private static Object parseBorder( String value, Function<String, String> resolver ) {
|
private static Object parseBorder( String value, Function<String, String> resolver ) {
|
||||||
if( value.indexOf( ',' ) >= 0 ) {
|
if( value.indexOf( ',' ) >= 0 ) {
|
||||||
// top,left,bottom,right[,lineColor]
|
// top,left,bottom,right[,lineColor]
|
||||||
List<String> parts = split( value, ',' );
|
List<String> parts = StringUtils.split( value, ',' );
|
||||||
Insets insets = parseInsets( value );
|
Insets insets = parseInsets( value );
|
||||||
ColorUIResource lineColor = (parts.size() == 5)
|
ColorUIResource lineColor = (parts.size() == 5)
|
||||||
? parseColorOrFunction( resolver.apply( parts.get( 4 ) ), true )
|
? parseColorOrFunction( resolver.apply( parts.get( 4 ) ), true )
|
||||||
@@ -282,7 +283,7 @@ class UIDefaultsLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Insets parseInsets( String value ) {
|
private static Insets parseInsets( String value ) {
|
||||||
List<String> numbers = split( value, ',' );
|
List<String> numbers = StringUtils.split( value, ',' );
|
||||||
try {
|
try {
|
||||||
return new InsetsUIResource(
|
return new InsetsUIResource(
|
||||||
Integer.parseInt( numbers.get( 0 ) ),
|
Integer.parseInt( numbers.get( 0 ) ),
|
||||||
@@ -295,7 +296,7 @@ class UIDefaultsLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Dimension parseSize( String value ) {
|
private static Dimension parseSize( String value ) {
|
||||||
List<String> numbers = split( value, ',' );
|
List<String> numbers = StringUtils.split( value, ',' );
|
||||||
try {
|
try {
|
||||||
return new DimensionUIResource(
|
return new DimensionUIResource(
|
||||||
Integer.parseInt( numbers.get( 0 ) ),
|
Integer.parseInt( numbers.get( 0 ) ),
|
||||||
@@ -317,8 +318,7 @@ class UIDefaultsLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ColorUIResource parseColor( String value, boolean reportError ) {
|
private static ColorUIResource parseColor( String value, boolean reportError ) {
|
||||||
if( value.startsWith( "#" ) )
|
value = StringUtils.removeLeading( value, "#" );
|
||||||
value = value.substring( 1 );
|
|
||||||
|
|
||||||
int valueLength = value.length();
|
int valueLength = value.length();
|
||||||
if( valueLength != 6 && valueLength != 8 )
|
if( valueLength != 6 && valueLength != 8 )
|
||||||
@@ -351,7 +351,7 @@ class UIDefaultsLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
String function = value.substring( 0, paramsStart ).trim();
|
String function = value.substring( 0, paramsStart ).trim();
|
||||||
List<String> params = split( value.substring( paramsStart + 1, value.length() - 1 ), ',' );
|
List<String> params = StringUtils.split( value.substring( paramsStart + 1, value.length() - 1 ), ',' );
|
||||||
if( params.isEmpty() )
|
if( params.isEmpty() )
|
||||||
throw new IllegalArgumentException( "missing parameters in function '" + value + "'" );
|
throw new IllegalArgumentException( "missing parameters in function '" + value + "'" );
|
||||||
|
|
||||||
@@ -417,18 +417,4 @@ class UIDefaultsLoader
|
|||||||
throw new NumberFormatException( "invalid integer '" + value + "'" );
|
throw new NumberFormatException( "invalid integer '" + value + "'" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<String> split( String str, char delim ) {
|
|
||||||
ArrayList<String> strs = new ArrayList<>();
|
|
||||||
int delimIndex = str.indexOf( delim );
|
|
||||||
int index = 0;
|
|
||||||
while( delimIndex >= 0 ) {
|
|
||||||
strs.add( str.substring( index, delimIndex ) );
|
|
||||||
index = delimIndex + 1;
|
|
||||||
delimIndex = str.indexOf( delim, index );
|
|
||||||
}
|
|
||||||
strs.add( str.substring( index ) );
|
|
||||||
|
|
||||||
return strs;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import javax.swing.JToolTip;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicToolTipUI;
|
import javax.swing.plaf.basic.BasicToolTipUI;
|
||||||
import com.formdev.flatlaf.FlatLaf;
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JToolTip}.
|
* Provides the Flat LaF UI delegate for {@link javax.swing.JToolTip}.
|
||||||
@@ -61,7 +61,7 @@ public class FlatToolTipUI
|
|||||||
FontMetrics fm = c.getFontMetrics( c.getFont() );
|
FontMetrics fm = c.getFontMetrics( c.getFont() );
|
||||||
Insets insets = c.getInsets();
|
Insets insets = c.getInsets();
|
||||||
|
|
||||||
List<String> lines = FlatLaf.split( ((JToolTip)c).getTipText(), '\n' );
|
List<String> lines = StringUtils.split( ((JToolTip)c).getTipText(), '\n' );
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = fm.getHeight() * Math.max( lines.size(), 1 );
|
int height = fm.getHeight() * Math.max( lines.size(), 1 );
|
||||||
for( String line : lines )
|
for( String line : lines )
|
||||||
@@ -81,7 +81,7 @@ public class FlatToolTipUI
|
|||||||
FlatUIUtils.setRenderingHints( (Graphics2D) g );
|
FlatUIUtils.setRenderingHints( (Graphics2D) g );
|
||||||
g.setColor( c.getForeground() );
|
g.setColor( c.getForeground() );
|
||||||
|
|
||||||
List<String> lines = FlatLaf.split( ((JToolTip)c).getTipText(), '\n' );
|
List<String> lines = StringUtils.split( ((JToolTip)c).getTipText(), '\n' );
|
||||||
|
|
||||||
int x = insets.left;
|
int x = insets.left;
|
||||||
int x2 = c.getWidth() - insets.right;
|
int x2 = c.getWidth() - insets.right;
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 FormDev Software GmbH
|
||||||
|
*
|
||||||
|
* 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 com.formdev.flatlaf.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility methods for strings.
|
||||||
|
*
|
||||||
|
* @author Karl Tauber
|
||||||
|
*/
|
||||||
|
public class StringUtils
|
||||||
|
{
|
||||||
|
public static String removeLeading( String string, String leading ) {
|
||||||
|
return string.startsWith( leading )
|
||||||
|
? string.substring( leading.length() )
|
||||||
|
: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String removeTrailing( String string, String trailing ) {
|
||||||
|
return string.endsWith( trailing )
|
||||||
|
? string.substring( 0, string.length() - trailing.length() )
|
||||||
|
: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> split( String str, char delim ) {
|
||||||
|
ArrayList<String> strs = new ArrayList<>();
|
||||||
|
int delimIndex = str.indexOf( delim );
|
||||||
|
int index = 0;
|
||||||
|
while( delimIndex >= 0 ) {
|
||||||
|
strs.add( str.substring( index, delimIndex ) );
|
||||||
|
index = delimIndex + 1;
|
||||||
|
delimIndex = str.indexOf( delim, index );
|
||||||
|
}
|
||||||
|
strs.add( str.substring( index ) );
|
||||||
|
|
||||||
|
return strs;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user