IntelliJ Themes Demo: IJThemesUpdater tool added to update themes from source code repositories

This commit is contained in:
Karl Tauber
2019-11-26 13:31:44 +01:00
parent f3b1f4b608
commit 8edcca9745
5 changed files with 179 additions and 57 deletions

View File

@@ -26,13 +26,17 @@ class IJThemeInfo
final String name;
final String resourceName;
final String sourceCodeUrl;
final String sourceCodePath;
final File themeFile;
final String lafClassName;
IJThemeInfo( String name, String resourceName, String sourceCodeUrl, File themeFile, String lafClassName ) {
IJThemeInfo( String name, String resourceName, String sourceCodeUrl, String sourceCodePath,
File themeFile, String lafClassName )
{
this.name = name;
this.resourceName = resourceName;
this.sourceCodeUrl = sourceCodeUrl;
this.sourceCodePath = sourceCodePath;
this.themeFile = themeFile;
this.lafClassName = lafClassName;
}

View File

@@ -56,8 +56,9 @@ class IJThemesManager
Map<String, String> value = (Map<String, String>) e.getValue();
String name = value.get( "name" );
String sourceCodeUrl = value.get( "sourceCodeUrl" );
String sourceCodePath = value.get( "sourceCodePath" );
bundledThemes.add( new IJThemeInfo( name, resourceName, sourceCodeUrl, null, null ) );
bundledThemes.add( new IJThemeInfo( name, resourceName, sourceCodeUrl, sourceCodePath, null, null ) );
}
}
@@ -75,7 +76,7 @@ class IJThemesManager
moreThemes.clear();
for( File f : themeFiles ) {
String name = StringUtils.removeTrailing( f.getName(), ".theme.json" );
moreThemes.add( new IJThemeInfo( name, null, null, f, null ) );
moreThemes.add( new IJThemeInfo( name, null, null, null, f, null ) );
lastModifiedMap.put( f, f.lastModified() );
}
}

View File

@@ -99,10 +99,10 @@ public class IJThemesPanel
// add core themes at beginning
categories.put( themes.size(), "Core Themes" );
themes.add( new IJThemeInfo( "Flat Light", null, null, null, FlatLightLaf.class.getName() ) );
themes.add( new IJThemeInfo( "Flat Dark", null, null, null, FlatDarkLaf.class.getName() ) );
themes.add( new IJThemeInfo( "Flat IntelliJ", null, null, null, FlatIntelliJLaf.class.getName() ) );
themes.add( new IJThemeInfo( "Flat Darcula", null, null, null, FlatDarculaLaf.class.getName() ) );
themes.add( new IJThemeInfo( "Flat Light", null, null, null, null, FlatLightLaf.class.getName() ) );
themes.add( new IJThemeInfo( "Flat Dark", null, null, null, null, FlatDarkLaf.class.getName() ) );
themes.add( new IJThemeInfo( "Flat IntelliJ", null, null, null, null, FlatIntelliJLaf.class.getName() ) );
themes.add( new IJThemeInfo( "Flat Darcula", null, null, null, null, FlatDarculaLaf.class.getName() ) );
// add uncategorized bundled themes
categories.put( themes.size(), "IntelliJ Themes" );

View File

@@ -0,0 +1,67 @@
/*
* 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.demo.intellijthemes;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
/**
* This tool updates all IntelliJ themes listed in themes.json by downloading
* them from the source code repositories.
*
* @author Karl Tauber
*/
public class IJThemesUpdater
{
public static void main( String[] args ) {
IJThemesManager themesManager = new IJThemesManager();
themesManager.loadBundledThemes();
for( IJThemeInfo ti : themesManager.bundledThemes ) {
if( ti.sourceCodeUrl == null || ti.sourceCodePath == null )
continue;
String fromUrl = ti.sourceCodeUrl + "/" + ti.sourceCodePath;
if( fromUrl.contains( "github.com" ) )
fromUrl += "?raw=true";
else if( fromUrl.contains( "gitlab.com" ) )
fromUrl = fromUrl.replace( "/blob/", "/raw/" );
String toPath = "src/main/resources/com/formdev/flatlaf/demo/intellijthemes/" + ti.resourceName;
download( fromUrl, toPath );
}
}
private static void download( String fromUrl, String toPath ) {
System.out.println( "Download " + fromUrl );
Path out = new File( toPath ).toPath();
try {
URL url = new URL( fromUrl.replace( " ", "%20" ) );
URLConnection con = url.openConnection();
Files.copy( con.getInputStream(), out, StandardCopyOption.REPLACE_EXISTING );
} catch( IOException ex ) {
ex.printStackTrace();
}
}
}