You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.9 KiB
101 lines
2.9 KiB
package com.fr.design.mainframe; |
|
|
|
import com.fr.base.io.BaseBook; |
|
import com.fr.base.theme.FineColorGather; |
|
import com.fr.base.theme.FineColorManager; |
|
import com.fr.base.theme.FineColorSynchronizer; |
|
import com.fr.base.theme.TemplateThemeCompatible; |
|
import com.fr.file.FILE; |
|
import com.fr.form.main.Form; |
|
import com.fr.stable.CoreConstants; |
|
import com.fr.stable.StringUtils; |
|
|
|
import java.util.ArrayList; |
|
import java.util.List; |
|
import org.jetbrains.annotations.NotNull; |
|
import org.jetbrains.annotations.Nullable; |
|
|
|
public final class JTemplateFactory { |
|
private static final List<App<?>> ALL_APP = new ArrayList<App<?>>(); |
|
|
|
private JTemplateFactory() { |
|
} |
|
|
|
/** |
|
* 生成设计器编辑模板对象 |
|
* |
|
* @param file 包含了模板名称,类型以及内容的文件 |
|
* @return 设计器编辑的模板对象 |
|
*/ |
|
public static JTemplate<?, ?> createJTemplate(@NotNull FILE file) { |
|
|
|
String fileName = file.getName(); |
|
int indexOfLastDot = fileName.lastIndexOf(CoreConstants.DOT); |
|
if (indexOfLastDot < 0) { |
|
return null; |
|
} |
|
String fileExtension = fileName.substring(indexOfLastDot + 1); |
|
for (App<?> app : ALL_APP) { |
|
String[] defaultAppExtensions = app.defaultExtensions(); |
|
for (String defaultAppExtension : defaultAppExtensions) { |
|
if (defaultAppExtension.equalsIgnoreCase(fileExtension)) { |
|
return app.openTemplate(file); |
|
} |
|
} |
|
} |
|
return null; |
|
} |
|
|
|
@Nullable |
|
public static <T extends BaseBook> T asIOFile(@NotNull FILE file, String fileNameOrSuffix) { |
|
|
|
if (StringUtils.isEmpty(fileNameOrSuffix)) { |
|
return null; |
|
} |
|
|
|
int indexOfLastDot = fileNameOrSuffix.lastIndexOf(CoreConstants.DOT); |
|
if (indexOfLastDot < 0) { |
|
return null; |
|
} |
|
String fileExtension = fileNameOrSuffix.substring(indexOfLastDot + 1); |
|
for (App<?> app : ALL_APP) { |
|
String[] defaultAppExtensions = app.defaultExtensions(); |
|
for (String defaultAppExtension : defaultAppExtensions) { |
|
if (defaultAppExtension.equalsIgnoreCase(fileExtension)) { |
|
BaseBook bb = app.asIOFile(file, false); |
|
if (bb != null) { |
|
return (T) bb; |
|
} |
|
} |
|
} |
|
} |
|
return null; |
|
} |
|
|
|
@Nullable |
|
public static <T extends BaseBook> T asIOFile(@NotNull FILE file) { |
|
return asIOFile(file, file.getName()); |
|
} |
|
|
|
|
|
|
|
/** |
|
* 注册app. |
|
* |
|
* @param app 注册app. |
|
*/ |
|
public static void register(App<?> app) { |
|
if (app != null) { |
|
ALL_APP.add(app); |
|
} |
|
} |
|
|
|
public static void remove(App<?> app) { |
|
if (app != null) { |
|
ALL_APP.remove(app); |
|
} |
|
} |
|
|
|
public static boolean isAvailable() { |
|
return !ALL_APP.isEmpty(); |
|
}} |