diff --git a/.classpath b/.classpath index e461bea..3178f7b 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,12 @@ - - - - - - + + + + + + + + + + + + diff --git a/.project b/.project index c1c4f42..48ebb36 100644 --- a/.project +++ b/.project @@ -1,17 +1,17 @@ - - - MCData - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - + + + MCData + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/resources/META-INF/services/org.jd.gui.spi.ContainerFactory b/resources/META-INF/services/org.jd.gui.spi.ContainerFactory new file mode 100644 index 0000000..de09b74 --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.ContainerFactory @@ -0,0 +1,7 @@ +# Order is important : 'GenericContainerFactoryProvider' must be the last +org.jd.gui.service.container.KarContainerFactoryProvider +org.jd.gui.service.container.JavaModuleContainerFactoryProvider +org.jd.gui.service.container.EarContainerFactoryProvider +org.jd.gui.service.container.WarContainerFactoryProvider +org.jd.gui.service.container.JarContainerFactoryProvider +org.jd.gui.service.container.GenericContainerFactoryProvider diff --git a/resources/META-INF/services/org.jd.gui.spi.ContextualActionsFactory b/resources/META-INF/services/org.jd.gui.spi.ContextualActionsFactory new file mode 100644 index 0000000..f2a8242 --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.ContextualActionsFactory @@ -0,0 +1 @@ +org.jd.gui.service.actions.CopyQualifiedNameContextualActionsFactory diff --git a/resources/META-INF/services/org.jd.gui.spi.FileLoader b/resources/META-INF/services/org.jd.gui.spi.FileLoader new file mode 100644 index 0000000..8c2851b --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.FileLoader @@ -0,0 +1,10 @@ +org.jd.gui.service.fileloader.AarFileLoaderProvider +org.jd.gui.service.fileloader.ClassFileLoaderProvider +org.jd.gui.service.fileloader.EarFileLoaderProvider +org.jd.gui.service.fileloader.JarFileLoaderProvider +org.jd.gui.service.fileloader.JavaFileLoaderProvider +org.jd.gui.service.fileloader.JavaModuleFileLoaderProvider +org.jd.gui.service.fileloader.KarFileLoaderProvider +org.jd.gui.service.fileloader.LogFileLoaderProvider +org.jd.gui.service.fileloader.WarFileLoaderProvider +org.jd.gui.service.fileloader.ZipFileLoaderProvider diff --git a/resources/META-INF/services/org.jd.gui.spi.Indexer b/resources/META-INF/services/org.jd.gui.spi.Indexer new file mode 100644 index 0000000..73259c4 --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.Indexer @@ -0,0 +1,12 @@ +org.jd.gui.service.indexer.DirectoryIndexerProvider +org.jd.gui.service.indexer.ClassFileIndexerProvider +org.jd.gui.service.indexer.EjbJarXmlFileIndexerProvider +org.jd.gui.service.indexer.JavaFileIndexerProvider +org.jd.gui.service.indexer.JavaModuleFileIndexerProvider +org.jd.gui.service.indexer.JavaModuleInfoFileIndexerProvider +org.jd.gui.service.indexer.MetainfServiceFileIndexerProvider +org.jd.gui.service.indexer.TextFileIndexerProvider +org.jd.gui.service.indexer.WebXmlFileIndexerProvider +org.jd.gui.service.indexer.ZipFileIndexerProvider +org.jd.gui.service.indexer.XmlBasedFileIndexerProvider +org.jd.gui.service.indexer.XmlFileIndexerProvider diff --git a/resources/META-INF/services/org.jd.gui.spi.PanelFactory b/resources/META-INF/services/org.jd.gui.spi.PanelFactory new file mode 100644 index 0000000..91df551 --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.PanelFactory @@ -0,0 +1 @@ +org.jd.gui.service.mainpanel.ContainerPanelFactoryProvider diff --git a/resources/META-INF/services/org.jd.gui.spi.PasteHandler b/resources/META-INF/services/org.jd.gui.spi.PasteHandler new file mode 100644 index 0000000..b6d3e57 --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.PasteHandler @@ -0,0 +1 @@ +org.jd.gui.service.pastehandler.LogPasteHandler diff --git a/resources/META-INF/services/org.jd.gui.spi.PreferencesPanel b/resources/META-INF/services/org.jd.gui.spi.PreferencesPanel new file mode 100644 index 0000000..9ea918f --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.PreferencesPanel @@ -0,0 +1,7 @@ +org.jd.gui.service.preferencespanel.UISingleInstancePreferencesProvider +org.jd.gui.service.preferencespanel.UITabsPreferencesProvider +org.jd.gui.service.preferencespanel.DirectoryIndexerPreferencesProvider +org.jd.gui.service.preferencespanel.ClassFileSaverPreferencesProvider +org.jd.gui.service.preferencespanel.ClassFileDecompilerPreferencesProvider +org.jd.gui.service.preferencespanel.ViewerPreferencesProvider +org.jd.gui.service.preferencespanel.MavenOrgSourceLoaderPreferencesProvider diff --git a/resources/META-INF/services/org.jd.gui.spi.SourceLoader b/resources/META-INF/services/org.jd.gui.spi.SourceLoader new file mode 100644 index 0000000..d9ed447 --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.SourceLoader @@ -0,0 +1 @@ +org.jd.gui.service.sourceloader.MavenOrgSourceLoaderProvider diff --git a/resources/META-INF/services/org.jd.gui.spi.SourceSaver b/resources/META-INF/services/org.jd.gui.spi.SourceSaver new file mode 100644 index 0000000..f2e0eb6 --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.SourceSaver @@ -0,0 +1,5 @@ +org.jd.gui.service.sourcesaver.ClassFileSourceSaverProvider +org.jd.gui.service.sourcesaver.DirectorySourceSaverProvider +org.jd.gui.service.sourcesaver.FileSourceSaverProvider +org.jd.gui.service.sourcesaver.PackageSourceSaverProvider +org.jd.gui.service.sourcesaver.ZipFileSourceSaverProvider diff --git a/resources/META-INF/services/org.jd.gui.spi.TreeNodeFactory b/resources/META-INF/services/org.jd.gui.spi.TreeNodeFactory new file mode 100644 index 0000000..6f02a5f --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.TreeNodeFactory @@ -0,0 +1,34 @@ +org.jd.gui.service.treenode.ClassesDirectoryTreeNodeFactoryProvider +org.jd.gui.service.treenode.ClassFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.CssFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.DirectoryTreeNodeFactoryProvider +org.jd.gui.service.treenode.DtdFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.EarFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.EjbJarXmlFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.FileTreeNodeFactoryProvider +org.jd.gui.service.treenode.HtmlFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.JarFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.JavaFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.JavascriptFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.JavaModuleFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.JavaModulePackageTreeNodeFactoryProvider +org.jd.gui.service.treenode.JsonFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.JspFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.KarFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.ManifestFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.MetainfDirectoryTreeNodeFactoryProvider +org.jd.gui.service.treenode.MetainfServiceFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.ModuleInfoFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.PackageTreeNodeFactoryProvider +org.jd.gui.service.treenode.PropertiesFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.SqlFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.SpiFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.TextFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.WarFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.WarPackageTreeNodeFactoryProvider +org.jd.gui.service.treenode.WebinfLibDirectoryTreeNodeFactoryProvider +org.jd.gui.service.treenode.WebXmlFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.XmlBasedFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.XmlFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.ZipFileTreeNodeFactoryProvider +org.jd.gui.service.treenode.ImageFileTreeNodeFactoryProvider \ No newline at end of file diff --git a/resources/META-INF/services/org.jd.gui.spi.TypeFactory b/resources/META-INF/services/org.jd.gui.spi.TypeFactory new file mode 100644 index 0000000..31797b0 --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.TypeFactory @@ -0,0 +1,2 @@ +org.jd.gui.service.type.ClassFileTypeFactoryProvider +org.jd.gui.service.type.JavaFileTypeFactoryProvider diff --git a/resources/META-INF/services/org.jd.gui.spi.UriLoader b/resources/META-INF/services/org.jd.gui.spi.UriLoader new file mode 100644 index 0000000..8a74f94 --- /dev/null +++ b/resources/META-INF/services/org.jd.gui.spi.UriLoader @@ -0,0 +1 @@ +org.jd.gui.service.uriloader.FileUriLoaderProvider diff --git a/resources/org/jd/gui/images/abstract_ovr.png b/resources/org/jd/gui/images/abstract_ovr.png new file mode 100644 index 0000000..658b8fd Binary files /dev/null and b/resources/org/jd/gui/images/abstract_ovr.png differ diff --git a/resources/org/jd/gui/images/annotation_obj.png b/resources/org/jd/gui/images/annotation_obj.png new file mode 100644 index 0000000..38d5eab Binary files /dev/null and b/resources/org/jd/gui/images/annotation_obj.png differ diff --git a/resources/org/jd/gui/images/archivefolder_obj.png b/resources/org/jd/gui/images/archivefolder_obj.png new file mode 100644 index 0000000..8d653f6 Binary files /dev/null and b/resources/org/jd/gui/images/archivefolder_obj.png differ diff --git a/resources/org/jd/gui/images/ascii_obj.png b/resources/org/jd/gui/images/ascii_obj.png new file mode 100644 index 0000000..4e9dc38 Binary files /dev/null and b/resources/org/jd/gui/images/ascii_obj.png differ diff --git a/resources/org/jd/gui/images/backward_nav.png b/resources/org/jd/gui/images/backward_nav.png new file mode 100644 index 0000000..8b022d1 Binary files /dev/null and b/resources/org/jd/gui/images/backward_nav.png differ diff --git a/resources/org/jd/gui/images/class_default_obj.png b/resources/org/jd/gui/images/class_default_obj.png new file mode 100644 index 0000000..078a164 Binary files /dev/null and b/resources/org/jd/gui/images/class_default_obj.png differ diff --git a/resources/org/jd/gui/images/class_obj.png b/resources/org/jd/gui/images/class_obj.png new file mode 100644 index 0000000..b58c84c Binary files /dev/null and b/resources/org/jd/gui/images/class_obj.png differ diff --git a/resources/org/jd/gui/images/class_private_obj.png b/resources/org/jd/gui/images/class_private_obj.png new file mode 100644 index 0000000..ab22985 Binary files /dev/null and b/resources/org/jd/gui/images/class_private_obj.png differ diff --git a/resources/org/jd/gui/images/class_protected_obj.png b/resources/org/jd/gui/images/class_protected_obj.png new file mode 100644 index 0000000..678aa32 Binary files /dev/null and b/resources/org/jd/gui/images/class_protected_obj.png differ diff --git a/resources/org/jd/gui/images/classf_obj.png b/resources/org/jd/gui/images/classf_obj.png new file mode 100644 index 0000000..6393f81 Binary files /dev/null and b/resources/org/jd/gui/images/classf_obj.png differ diff --git a/resources/org/jd/gui/images/close.gif b/resources/org/jd/gui/images/close.gif new file mode 100644 index 0000000..17b7573 Binary files /dev/null and b/resources/org/jd/gui/images/close.gif differ diff --git a/resources/org/jd/gui/images/close_active.gif b/resources/org/jd/gui/images/close_active.gif new file mode 100644 index 0000000..8816521 Binary files /dev/null and b/resources/org/jd/gui/images/close_active.gif differ diff --git a/resources/org/jd/gui/images/constr_ovr.png b/resources/org/jd/gui/images/constr_ovr.png new file mode 100644 index 0000000..65964a9 Binary files /dev/null and b/resources/org/jd/gui/images/constr_ovr.png differ diff --git a/resources/org/jd/gui/images/copy.png b/resources/org/jd/gui/images/copy.png new file mode 100644 index 0000000..bb5451c Binary files /dev/null and b/resources/org/jd/gui/images/copy.png differ diff --git a/resources/org/jd/gui/images/cpyqual_menu.png b/resources/org/jd/gui/images/cpyqual_menu.png new file mode 100644 index 0000000..fab5842 Binary files /dev/null and b/resources/org/jd/gui/images/cpyqual_menu.png differ diff --git a/resources/org/jd/gui/images/css_obj.png b/resources/org/jd/gui/images/css_obj.png new file mode 100644 index 0000000..4caa409 Binary files /dev/null and b/resources/org/jd/gui/images/css_obj.png differ diff --git a/resources/org/jd/gui/images/dtd_obj.gif b/resources/org/jd/gui/images/dtd_obj.gif new file mode 100644 index 0000000..64ee536 Binary files /dev/null and b/resources/org/jd/gui/images/dtd_obj.gif differ diff --git a/resources/org/jd/gui/images/ear_obj.gif b/resources/org/jd/gui/images/ear_obj.gif new file mode 100644 index 0000000..4468d66 Binary files /dev/null and b/resources/org/jd/gui/images/ear_obj.gif differ diff --git a/resources/org/jd/gui/images/ejbmodule_obj.gif b/resources/org/jd/gui/images/ejbmodule_obj.gif new file mode 100644 index 0000000..f8b5c0a Binary files /dev/null and b/resources/org/jd/gui/images/ejbmodule_obj.gif differ diff --git a/resources/org/jd/gui/images/enum_obj.png b/resources/org/jd/gui/images/enum_obj.png new file mode 100644 index 0000000..a9ecedf Binary files /dev/null and b/resources/org/jd/gui/images/enum_obj.png differ diff --git a/resources/org/jd/gui/images/field_default_obj.png b/resources/org/jd/gui/images/field_default_obj.png new file mode 100644 index 0000000..becfe6b Binary files /dev/null and b/resources/org/jd/gui/images/field_default_obj.png differ diff --git a/resources/org/jd/gui/images/field_private_obj.png b/resources/org/jd/gui/images/field_private_obj.png new file mode 100644 index 0000000..d3fa87d Binary files /dev/null and b/resources/org/jd/gui/images/field_private_obj.png differ diff --git a/resources/org/jd/gui/images/field_protected_obj.png b/resources/org/jd/gui/images/field_protected_obj.png new file mode 100644 index 0000000..dc80489 Binary files /dev/null and b/resources/org/jd/gui/images/field_protected_obj.png differ diff --git a/resources/org/jd/gui/images/field_public_obj.png b/resources/org/jd/gui/images/field_public_obj.png new file mode 100644 index 0000000..40a5ef1 Binary files /dev/null and b/resources/org/jd/gui/images/field_public_obj.png differ diff --git a/resources/org/jd/gui/images/file-image.gif b/resources/org/jd/gui/images/file-image.gif new file mode 100644 index 0000000..07e2598 Binary files /dev/null and b/resources/org/jd/gui/images/file-image.gif differ diff --git a/resources/org/jd/gui/images/file_plain_obj.png b/resources/org/jd/gui/images/file_plain_obj.png new file mode 100644 index 0000000..735dd02 Binary files /dev/null and b/resources/org/jd/gui/images/file_plain_obj.png differ diff --git a/resources/org/jd/gui/images/final_ovr.png b/resources/org/jd/gui/images/final_ovr.png new file mode 100644 index 0000000..f20a9c1 Binary files /dev/null and b/resources/org/jd/gui/images/final_ovr.png differ diff --git a/resources/org/jd/gui/images/folder.gif b/resources/org/jd/gui/images/folder.gif new file mode 100644 index 0000000..42e027c Binary files /dev/null and b/resources/org/jd/gui/images/folder.gif differ diff --git a/resources/org/jd/gui/images/folder_open.png b/resources/org/jd/gui/images/folder_open.png new file mode 100644 index 0000000..9759da4 Binary files /dev/null and b/resources/org/jd/gui/images/folder_open.png differ diff --git a/resources/org/jd/gui/images/forward_nav.png b/resources/org/jd/gui/images/forward_nav.png new file mode 100644 index 0000000..a6afdee Binary files /dev/null and b/resources/org/jd/gui/images/forward_nav.png differ diff --git a/resources/org/jd/gui/images/generate_class.png b/resources/org/jd/gui/images/generate_class.png new file mode 100644 index 0000000..904ee07 Binary files /dev/null and b/resources/org/jd/gui/images/generate_class.png differ diff --git a/resources/org/jd/gui/images/generate_int.png b/resources/org/jd/gui/images/generate_int.png new file mode 100644 index 0000000..82a5d80 Binary files /dev/null and b/resources/org/jd/gui/images/generate_int.png differ diff --git a/resources/org/jd/gui/images/html_obj.gif b/resources/org/jd/gui/images/html_obj.gif new file mode 100644 index 0000000..53e7dbd Binary files /dev/null and b/resources/org/jd/gui/images/html_obj.gif differ diff --git a/resources/org/jd/gui/images/inf_obj.png b/resources/org/jd/gui/images/inf_obj.png new file mode 100644 index 0000000..f9f9c42 Binary files /dev/null and b/resources/org/jd/gui/images/inf_obj.png differ diff --git a/resources/org/jd/gui/images/int_default_obj.png b/resources/org/jd/gui/images/int_default_obj.png new file mode 100644 index 0000000..35241b0 Binary files /dev/null and b/resources/org/jd/gui/images/int_default_obj.png differ diff --git a/resources/org/jd/gui/images/int_obj.png b/resources/org/jd/gui/images/int_obj.png new file mode 100644 index 0000000..745cdea Binary files /dev/null and b/resources/org/jd/gui/images/int_obj.png differ diff --git a/resources/org/jd/gui/images/int_private_obj.png b/resources/org/jd/gui/images/int_private_obj.png new file mode 100644 index 0000000..f36c8b5 Binary files /dev/null and b/resources/org/jd/gui/images/int_private_obj.png differ diff --git a/resources/org/jd/gui/images/int_protected_obj.png b/resources/org/jd/gui/images/int_protected_obj.png new file mode 100644 index 0000000..5e5639d Binary files /dev/null and b/resources/org/jd/gui/images/int_protected_obj.png differ diff --git a/resources/org/jd/gui/images/jar_obj.png b/resources/org/jd/gui/images/jar_obj.png new file mode 100644 index 0000000..6124fd2 Binary files /dev/null and b/resources/org/jd/gui/images/jar_obj.png differ diff --git a/resources/org/jd/gui/images/java_obj.png b/resources/org/jd/gui/images/java_obj.png new file mode 100644 index 0000000..dceae72 Binary files /dev/null and b/resources/org/jd/gui/images/java_obj.png differ diff --git a/resources/org/jd/gui/images/jcu_obj.png b/resources/org/jd/gui/images/jcu_obj.png new file mode 100644 index 0000000..dceae72 Binary files /dev/null and b/resources/org/jd/gui/images/jcu_obj.png differ diff --git a/resources/org/jd/gui/images/jd_icon_128.png b/resources/org/jd/gui/images/jd_icon_128.png new file mode 100644 index 0000000..b29e5a9 Binary files /dev/null and b/resources/org/jd/gui/images/jd_icon_128.png differ diff --git a/resources/org/jd/gui/images/jd_icon_32.png b/resources/org/jd/gui/images/jd_icon_32.png new file mode 100644 index 0000000..2d5cfab Binary files /dev/null and b/resources/org/jd/gui/images/jd_icon_32.png differ diff --git a/resources/org/jd/gui/images/jd_icon_64.png b/resources/org/jd/gui/images/jd_icon_64.png new file mode 100644 index 0000000..2e457df Binary files /dev/null and b/resources/org/jd/gui/images/jd_icon_64.png differ diff --git a/resources/org/jd/gui/images/js_obj.png b/resources/org/jd/gui/images/js_obj.png new file mode 100644 index 0000000..6f6fa6a Binary files /dev/null and b/resources/org/jd/gui/images/js_obj.png differ diff --git a/resources/org/jd/gui/images/manifest_obj.png b/resources/org/jd/gui/images/manifest_obj.png new file mode 100644 index 0000000..8ec970c Binary files /dev/null and b/resources/org/jd/gui/images/manifest_obj.png differ diff --git a/resources/org/jd/gui/images/methdef_obj.png b/resources/org/jd/gui/images/methdef_obj.png new file mode 100644 index 0000000..a4131b9 Binary files /dev/null and b/resources/org/jd/gui/images/methdef_obj.png differ diff --git a/resources/org/jd/gui/images/methpri_obj.png b/resources/org/jd/gui/images/methpri_obj.png new file mode 100644 index 0000000..57dbb76 Binary files /dev/null and b/resources/org/jd/gui/images/methpri_obj.png differ diff --git a/resources/org/jd/gui/images/methpro_obj.png b/resources/org/jd/gui/images/methpro_obj.png new file mode 100644 index 0000000..3e4c0d7 Binary files /dev/null and b/resources/org/jd/gui/images/methpro_obj.png differ diff --git a/resources/org/jd/gui/images/methpub_obj.png b/resources/org/jd/gui/images/methpub_obj.png new file mode 100644 index 0000000..3004195 Binary files /dev/null and b/resources/org/jd/gui/images/methpub_obj.png differ diff --git a/resources/org/jd/gui/images/minus.png b/resources/org/jd/gui/images/minus.png new file mode 100644 index 0000000..df26d9e Binary files /dev/null and b/resources/org/jd/gui/images/minus.png differ diff --git a/resources/org/jd/gui/images/module_obj.png b/resources/org/jd/gui/images/module_obj.png new file mode 100644 index 0000000..300adac Binary files /dev/null and b/resources/org/jd/gui/images/module_obj.png differ diff --git a/resources/org/jd/gui/images/next_nav.png b/resources/org/jd/gui/images/next_nav.png new file mode 100644 index 0000000..0328357 Binary files /dev/null and b/resources/org/jd/gui/images/next_nav.png differ diff --git a/resources/org/jd/gui/images/open.png b/resources/org/jd/gui/images/open.png new file mode 100644 index 0000000..0430baa Binary files /dev/null and b/resources/org/jd/gui/images/open.png differ diff --git a/resources/org/jd/gui/images/open_type.png b/resources/org/jd/gui/images/open_type.png new file mode 100644 index 0000000..f0ba8f8 Binary files /dev/null and b/resources/org/jd/gui/images/open_type.png differ diff --git a/resources/org/jd/gui/images/package_obj.png b/resources/org/jd/gui/images/package_obj.png new file mode 100644 index 0000000..922c435 Binary files /dev/null and b/resources/org/jd/gui/images/package_obj.png differ diff --git a/resources/org/jd/gui/images/packagefolder_obj.png b/resources/org/jd/gui/images/packagefolder_obj.png new file mode 100644 index 0000000..93053b7 Binary files /dev/null and b/resources/org/jd/gui/images/packagefolder_obj.png differ diff --git a/resources/org/jd/gui/images/packd_obj.png b/resources/org/jd/gui/images/packd_obj.png new file mode 100644 index 0000000..aa7b6a6 Binary files /dev/null and b/resources/org/jd/gui/images/packd_obj.png differ diff --git a/resources/org/jd/gui/images/paste.png b/resources/org/jd/gui/images/paste.png new file mode 100644 index 0000000..b66e9dd Binary files /dev/null and b/resources/org/jd/gui/images/paste.png differ diff --git a/resources/org/jd/gui/images/plus.png b/resources/org/jd/gui/images/plus.png new file mode 100644 index 0000000..744f799 Binary files /dev/null and b/resources/org/jd/gui/images/plus.png differ diff --git a/resources/org/jd/gui/images/preferences.png b/resources/org/jd/gui/images/preferences.png new file mode 100644 index 0000000..1c23d0e Binary files /dev/null and b/resources/org/jd/gui/images/preferences.png differ diff --git a/resources/org/jd/gui/images/prev_nav.png b/resources/org/jd/gui/images/prev_nav.png new file mode 100644 index 0000000..830c2c9 Binary files /dev/null and b/resources/org/jd/gui/images/prev_nav.png differ diff --git a/resources/org/jd/gui/images/save.png b/resources/org/jd/gui/images/save.png new file mode 100644 index 0000000..5f0fb5b Binary files /dev/null and b/resources/org/jd/gui/images/save.png differ diff --git a/resources/org/jd/gui/images/save_all.png b/resources/org/jd/gui/images/save_all.png new file mode 100644 index 0000000..eeea6be Binary files /dev/null and b/resources/org/jd/gui/images/save_all.png differ diff --git a/resources/org/jd/gui/images/search_src.png b/resources/org/jd/gui/images/search_src.png new file mode 100644 index 0000000..c549447 Binary files /dev/null and b/resources/org/jd/gui/images/search_src.png differ diff --git a/resources/org/jd/gui/images/sql_obj.png b/resources/org/jd/gui/images/sql_obj.png new file mode 100644 index 0000000..1bbf8b1 Binary files /dev/null and b/resources/org/jd/gui/images/sql_obj.png differ diff --git a/resources/org/jd/gui/images/static_ovr.png b/resources/org/jd/gui/images/static_ovr.png new file mode 100644 index 0000000..3c721da Binary files /dev/null and b/resources/org/jd/gui/images/static_ovr.png differ diff --git a/resources/org/jd/gui/images/th_showqualified.png b/resources/org/jd/gui/images/th_showqualified.png new file mode 100644 index 0000000..702c329 Binary files /dev/null and b/resources/org/jd/gui/images/th_showqualified.png differ diff --git a/resources/org/jd/gui/images/war_obj.gif b/resources/org/jd/gui/images/war_obj.gif new file mode 100644 index 0000000..31ecb7a Binary files /dev/null and b/resources/org/jd/gui/images/war_obj.gif differ diff --git a/resources/org/jd/gui/images/xml_obj.gif b/resources/org/jd/gui/images/xml_obj.gif new file mode 100644 index 0000000..4083e21 Binary files /dev/null and b/resources/org/jd/gui/images/xml_obj.gif differ diff --git a/resources/org/jd/gui/images/zip_obj.png b/resources/org/jd/gui/images/zip_obj.png new file mode 100644 index 0000000..af4d58f Binary files /dev/null and b/resources/org/jd/gui/images/zip_obj.png differ diff --git a/src/com/jacoco/mcdata/DownloadLatestVersion.java b/src/com/jacoco/mcdata/DownloadLatestVersion.java new file mode 100644 index 0000000..b97c894 --- /dev/null +++ b/src/com/jacoco/mcdata/DownloadLatestVersion.java @@ -0,0 +1,39 @@ +package com.jacoco.mcdata; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +public class DownloadLatestVersion { + + public static void main(String[] args) throws Exception { + URL manifestUrl = new URL("https://launchermeta.mojang.com/mc/game/version_manifest_v2.json"); + JSONObject jo1 = (JSONObject) JSONValue.parse(new InputStreamReader(manifestUrl.openStream())); + JSONObject version = (JSONObject) ((JSONArray) jo1.get("versions")).get(0); + String id = version.get("id").toString(); + URL url = new URL(version.get("url").toString());; + File versionsDir = new File(Utils.getMinecraftDir(), "versions"); + File versionDir = new File(versionsDir, id); + versionDir.mkdirs(); + + JSONObject jo2 = (JSONObject) JSONValue.parse(new InputStreamReader(url.openStream())); + PrintWriter writer = new PrintWriter(new File(versionDir, id + ".json")); + writer.write(jo2.toString()); + writer.close(); + + URL jarUrl = new URL(((JSONObject) ((JSONObject) jo2.get("downloads")).get("client")).get("url").toString()); + ReadableByteChannel channel = Channels.newChannel(jarUrl.openStream()); + FileOutputStream outStream = new FileOutputStream(new File(versionDir, id + ".jar")); + outStream.getChannel().transferFrom(channel, 0, Long.MAX_VALUE); + outStream.close(); + channel.close(); + } +} diff --git a/src/com/jacoco/mcdata/Gui.java b/src/com/jacoco/mcdata/Gui.java index 43f4031..677a7b3 100644 --- a/src/com/jacoco/mcdata/Gui.java +++ b/src/com/jacoco/mcdata/Gui.java @@ -1,294 +1,83 @@ -package com.jacoco.mcdata; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.FileDialog; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.nio.file.Path; -import java.nio.file.Paths; - -import javax.swing.JButton; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import org.jd.gui.JDGui; - -import com.jacoco.mcdata.files.Config; -import com.jacoco.mcdata.files.Deobfuscation; - -import cuchaz.enigma.EnigmaProfile; -import cuchaz.enigma.translation.mapping.serde.MappingFormat; - -public class Gui { - - private JFrame gui; - private JPanel initPanel; - private BorderLayout layout; - - private Config cfg; - private Theme theme; - private Deobfuscation deobf; - - private Color background; - private Color text; - private Color button; - - private JLabel versionChooserLabel; - private JTextField versionChooser; - - private JLabel exportPathLable; - private JTextField exportPath; - - private JDGui jd; - - private JButton thm; - - private JButton exportJar; - - private JButton cls; - - public Gui(Theme theme, Config cfg) { - - this.theme = theme; - this.cfg = cfg; - this.deobf = new Deobfuscation(this, EnigmaProfile.EMPTY, MappingFormat.PROGUARD); - - this.background = this.theme.getBg(); - this.text = this.theme.getText(); - this.button = this.theme.getBtn(); - - this.gui = new JFrame("MCData"); - this.initPanel = new JPanel(); - - // coordinates - int sizeX = 600; - int sizeY = 225; - - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - int centerX = screenSize.width / 2 - sizeX / 2; - int centerY = screenSize.height / 2 - sizeY / 2 - 25; - - this.layout = new BorderLayout(); - gui.setLayout(this.layout); - - gui.setLocation(centerX, centerY); - gui.setSize(sizeX, sizeY); - - // add the init panel - initPanel.setLayout(null); - initPanel.setBackground(this.background); - - /* - * version chooser - */ - - // label - versionChooserLabel = new JLabel("Choose Version Folder"); - versionChooserLabel.setForeground(text); - versionChooserLabel.setLocation(initPanel.getWidth() / 12, initPanel.getHeight() / 4 - 20); - versionChooserLabel.setSize(500, 20); - initPanel.add(versionChooserLabel); - - // text field - versionChooser = new JTextField("Choose Folder"); - versionChooser.setBounds(initPanel.getWidth() / 12, initPanel.getHeight() / 4, initPanel.getWidth() / 6 * 5, 30); - versionChooser.setForeground(text); - versionChooser.setBackground(background); - initPanel.add(versionChooser); - versionChooser.addMouseListener(new MouseAdapter() { - - public void mouseClicked(MouseEvent e) { - FileDialog fd = new FileDialog(gui, "Choose Folder", FileDialog.LOAD); - fd.setVisible(true); - Path path = Paths.get(fd.getDirectory()); - versionChooser.setText(path.toString()); - - Versions.add(new Version(path)); - } - }); - - /* - * export path - */ - - // label - exportPathLable = new JLabel("Choose Export Folder"); - exportPathLable.setForeground(text); - exportPathLable.setLocation(initPanel.getWidth() / 12, initPanel.getHeight() / 2 - 20); - exportPathLable.setSize(500, 20); - initPanel.add(exportPathLable); - - // text field - exportPath = new JTextField(cfg.getExportPath().toString()); - exportPath.setBounds(initPanel.getWidth() / 12, initPanel.getHeight() / 2, initPanel.getWidth() / 6 * 4, 30); - exportPath.setForeground(text); - exportPath.setBackground(background); - initPanel.add(exportPath); - exportPath.addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent e) { - JFileChooser fd = new JFileChooser("Choose Folder"); - fd.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - fd.showOpenDialog(initPanel); - exportPath.setText(fd.getSelectedFile().toString()); - cfg.setExportPath(fd.getSelectedFile().toString()); - } - }); - - // jd-gui - jd = new JDGui(); - - // jar export button - exportJar = new JButton("Export"); - exportJar.setBounds(initPanel.getWidth() / 3 - 10, initPanel.getHeight() / 7 * 5, initPanel.getWidth()/6, 30); - exportJar.setForeground(text); - exportJar.setBackground(button); - initPanel.add(exportJar); - exportJar.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - cfg.setExportPath(exportPath.getText()); - Path exportPath = cfg.getExportPath(); - deobf.addOnFinishEvent(() -> { - jd.loadFile(exportPath.resolve(Versions.getLatest().getExportedJar()).toFile()); - }); - deobf.export(exportPath, Versions.getLatest()); - } - }); - - // close button - cls = new JButton("Close"); - cls.setBounds(initPanel.getWidth() / 2 + 10, initPanel.getHeight() / 7 * 5, initPanel.getWidth()/6, 30); - cls.setForeground(text); - cls.setBackground(button); - initPanel.add(cls); - cls.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) { - onClose(); - } - }); - - // theme - thm = new JButton(this.theme.getName()); - thm.setBounds(initPanel.getWidth() / 4 * 3, initPanel.getHeight() / 2, initPanel.getWidth()/6, 30); - thm.setForeground(text); - thm.setBackground(button); - initPanel.add(thm); - thm.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) { - Theme theme; - - String light = "Light Mode"; - String dark = "Dark Mode"; - - switch (thm.getText()) { - case "Light Mode": - thm.setText(dark); - cfg.setTheme(dark); - theme = Theme.DARK; - setTheme(theme); - updateColors(); - break; - - case "Dark Mode": - thm.setText(light); - cfg.setTheme(light); - theme = Theme.LIGHT; - setTheme(theme); - updateColors(); - break; - } - } - }); - - // make application work - gui.setBackground(background); - gui.addWindowListener(new WindowAdapter() { - public void windowClosed(WindowEvent e) { - onClose(); - } - }); - gui.setDefaultCloseOperation(3); - gui.setVisible(true); - - initPanel.addComponentListener(new ComponentAdapter() { - public void componentResized(ComponentEvent e) { - cls.setBounds(initPanel.getWidth() / 2 + 10, initPanel.getHeight() / 7 * 5, initPanel.getWidth()/6, 30); - - exportJar.setBounds(initPanel.getWidth() / 3 - 10, initPanel.getHeight() / 7 * 5, initPanel.getWidth()/6, 30); - - versionChooser.setBounds(initPanel.getWidth() / 12, initPanel.getHeight() / 4, initPanel.getWidth() / 6 * 5, 30); - - versionChooserLabel.setLocation(initPanel.getWidth() / 12, initPanel.getHeight() / 4 - 20); - versionChooserLabel.setSize(500, 20); - - exportPath.setBounds(initPanel.getWidth() / 12, initPanel.getHeight() / 2, initPanel.getWidth() / 6 * 4, 30); - - exportPathLable.setLocation(initPanel.getWidth() / 12, initPanel.getHeight() / 2 - 20); - exportPathLable.setSize(500, 20); - - thm.setBounds(initPanel.getWidth() / 4 * 3, initPanel.getHeight() / 2, initPanel.getWidth()/6, 30); - } - }); - - gui.add(initPanel); - } - - private void setTheme(Theme theme) { - this.theme = theme; - } - - private void updateColors() { - this.background = this.theme.getBg(); - this.text = this.theme.getText(); - this.button = this.theme.getBtn(); - - cls.setForeground(text); - cls.setBackground(button); - - versionChooserLabel.setForeground(text); - versionChooserLabel.setBackground(background); - - versionChooser.setForeground(text); - versionChooser.setBackground(background); - - exportPathLable.setForeground(text); - exportPathLable.setBackground(background); - - exportPath.setForeground(text); - exportPath.setBackground(background); - - exportJar.setForeground(text); - exportJar.setBackground(button); - - thm.setForeground(text); - thm.setBackground(button); - - initPanel.setBackground(background); - } - - private void onClose() { - this.cfg.setExportPath(exportPath.getText()); - System.exit(0); - } - - public JFrame getFrame() { - return this.gui; - } -} +package com.jacoco.mcdata; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Toolkit; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JFrame; +import javax.swing.JPanel; + +import com.jacoco.mcdata.controller.ActionsController; +import com.jacoco.mcdata.controller.InitializationController; +import com.jacoco.mcdata.controller.JDController; +import com.jacoco.mcdata.files.Config; +import com.jacoco.mcdata.files.Deobfuscation; +import com.jacoco.mcdata.view.View; + +import cuchaz.enigma.EnigmaProfile; +import cuchaz.enigma.translation.mapping.serde.MappingFormat; + +public class Gui { + + private JFrame frame; + private BorderLayout layout; + + private Deobfuscation deobf; + + private List views = new ArrayList(); + + public Gui(Config cfg) { + Theme theme = cfg.getTheme(); + this.deobf = new Deobfuscation(MappingFormat.PROGUARD, EnigmaProfile.EMPTY); + + this.frame = new JFrame("MCData"); + + // coordinates + Dimension size = new Dimension(1000, 800); + + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + int centerX = screenSize.width / 2 - size.width / 2; + int centerY = screenSize.height / 2 - size.height / 2 - 25; + + this.layout = new BorderLayout(); + frame.setLayout(this.layout); + + frame.setLocation(centerX, centerY); + frame.setSize(size); + frame.setMinimumSize(size); + frame.setBackground(theme.getBg()); + + Dimension prefSize = new Dimension(200, 0); + JPanel west = new JPanel(); + JPanel east = new JPanel(); + west.setPreferredSize(prefSize); + east.setPreferredSize(prefSize); + west.setBackground(theme.getBg()); + east.setBackground(theme.getBg()); + + InitializationController initController = new InitializationController(cfg, this.views); + addView(initController.getView(), BorderLayout.NORTH); + frame.add(west, BorderLayout.WEST); + JDController jdController = new JDController(cfg); + addView(jdController.getView(), BorderLayout.CENTER); + frame.add(east, BorderLayout.EAST); + ActionsController actionsController = new ActionsController(initController, jdController, cfg, deobf, this::onClose); + addView(actionsController.getView(), BorderLayout.SOUTH); + frame.setVisible(true); + } + + private void onClose() { + System.exit(0); + } + + public void addView(View view, String constraint) { + views.add(view); + this.frame.add(view.getPanel(), constraint); + } + + public JFrame getFrame() { + return this.frame; + } +} \ No newline at end of file diff --git a/src/com/jacoco/mcdata/Main.java b/src/com/jacoco/mcdata/Main.java index 9163e7e..5c9151e 100644 --- a/src/com/jacoco/mcdata/Main.java +++ b/src/com/jacoco/mcdata/Main.java @@ -1,33 +1,19 @@ -package com.jacoco.mcdata; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -import com.jacoco.mcdata.files.Config; - -public class Main { - - private static Path tmpDir; - private static Config cfg; - private static Gui gui; - - public static void main(String[] args) throws IOException { - tmpDir = Files.createTempDirectory("MCData_"); - tmpDir.toFile().deleteOnExit(); - cfg = new Config(); - gui = new Gui(cfg.getTheme(), cfg); - } - - public static Path getTmpDir() { - return tmpDir; - } - - public static Config getCfg() { - return cfg; - } - - public static Gui getGui() { - return gui; - } -} +package com.jacoco.mcdata; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import com.jacoco.mcdata.files.Config; + +public class Main { + + public static Path tmpDir; + + public static void main(String[] args) throws IOException { + tmpDir = Files.createTempDirectory("MCData_"); + tmpDir.toFile().deleteOnExit(); + Config cfg = new Config(); + new Gui(cfg); + } +} \ No newline at end of file diff --git a/src/com/jacoco/mcdata/Theme.java b/src/com/jacoco/mcdata/Theme.java index ef35e83..a5907b1 100644 --- a/src/com/jacoco/mcdata/Theme.java +++ b/src/com/jacoco/mcdata/Theme.java @@ -1,55 +1,55 @@ -package com.jacoco.mcdata; - -import java.awt.Color; - -public enum Theme { - LIGHT("Light Mode", new Color(254, 254, 254), new Color(0, 0, 0)), - DARK("Dark Mode", new Color(0, 0, 50), new Color(254, 254, 254)); - - private String name; - private Color bg; - private Color text; - private Color btn; - - Theme(String name, Color bg, Color text) { - this.name = name; - this.bg = bg; - this.text = text; - - int r = this.bg.getRed(), g = this.bg.getGreen(), b = this.bg.getBlue(); - int chg = 50; - - if (r >= 100) { - btn = new Color(r - chg, g - chg, b - chg); - } else if (r <= 100) { - btn = new Color(r + chg, g + chg, b - 20 + chg); - } - } - - public static Theme getThemeFromName(String name) { - switch(name) { - case "Light Mode": - return Theme.LIGHT; - case "Dark Mode": - return Theme.LIGHT; - default: - return Theme.LIGHT; - } - } - - public String getName() { - return this.name; - } - - public Color getBg() { - return this.bg; - } - - public Color getText() { - return this.text; - } - - public Color getBtn() { - return this.btn; - } +package com.jacoco.mcdata; + +import java.awt.Color; + +public enum Theme { + LIGHT("Light Mode", new Color(254, 254, 254), new Color(0, 0, 0)), + DARK("Dark Mode", new Color(0, 0, 50), new Color(254, 254, 254)); + + private String name; + private Color bg; + private Color text; + private Color btn; + + Theme(String name, Color bg, Color text) { + this.name = name; + this.bg = bg; + this.text = text; + + int r = this.bg.getRed(), g = this.bg.getGreen(), b = this.bg.getBlue(); + int chg = 50; + + if (r >= 100) { + btn = new Color(r - chg, g - chg, b - chg); + } else if (r <= 100) { + btn = new Color(r + chg, g + chg, b - 20 + chg); + } + } + + public static Theme getThemeFromName(String name) { + switch(name) { + case "Light Mode": + return Theme.LIGHT; + case "Dark Mode": + return Theme.LIGHT; + default: + return Theme.LIGHT; + } + } + + public String getName() { + return this.name; + } + + public Color getBg() { + return this.bg; + } + + public Color getText() { + return this.text; + } + + public Color getBtn() { + return this.btn; + } } \ No newline at end of file diff --git a/src/com/jacoco/mcdata/Utils.java b/src/com/jacoco/mcdata/Utils.java new file mode 100644 index 0000000..512c7b3 --- /dev/null +++ b/src/com/jacoco/mcdata/Utils.java @@ -0,0 +1,90 @@ +package com.jacoco.mcdata; + +import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; + +import org.jd.gui.service.platform.PlatformService; + +public class Utils { + + private static List jsonSpecials = Arrays.asList('"', '\\', '/', 'b', 'f', 'n', 'r', 't'); + + public static String prettyPrint(String json) { + StringReader reader = new StringReader(json); + StringBuilder builder = new StringBuilder(); + int depth = 0; + + try { + Character c = ' '; + while((c = (char) reader.read()) < 255 && c > 0) { + switch(c) { + case '"': + boolean isString = true; + while(isString) { + builder.append(c); + c = (char) reader.read(); + if(c.equals('\\')) { + builder.append(c); + if(!jsonSpecials.contains(c = (char) reader.read())) + builder.append('\\'); + } else if(c.equals('"')) { + builder.append(c); + isString = false; + } + } + break; + case '{': + case '[': + builder.append(c); + builder.append("\n"); + for(int i = 0; i < depth+1; i++) builder.append("\t"); + depth++; + break; + case '}': + case ']': + Character lastChar = builder.charAt(builder.length()-1); + if(lastChar.equals('\t')) { + builder.deleteCharAt(builder.length()-1); + } else { + builder.append("\n"); + for(int i = 0; i < depth-1; i++) builder.append("\t"); + } + builder.append(c); + depth--; + break; + case ',': + builder.append(c); + builder.append("\n"); + for(int i = 0; i < depth; i++) builder.append("\t"); + break; + case ':': + builder.append(c); builder.append(' '); + break; + default: + builder.append(c); + break; + } + } + } catch (IOException e) { + return null; + } + + return builder.toString(); + } + + public static File getMinecraftDir() { + String workingDirectory; + if (PlatformService.getInstance().isWindows()) { + workingDirectory = System.getenv("AppData"); + } else { + workingDirectory = System.getProperty("user.home"); + if(PlatformService.getInstance().isMac()) + workingDirectory += "/Library/Application Support"; + } + return Paths.get(workingDirectory).resolve(".minecraft").toFile(); + } +} diff --git a/src/com/jacoco/mcdata/controller/ActionsController.java b/src/com/jacoco/mcdata/controller/ActionsController.java new file mode 100644 index 0000000..02928ca --- /dev/null +++ b/src/com/jacoco/mcdata/controller/ActionsController.java @@ -0,0 +1,43 @@ +package com.jacoco.mcdata.controller; + +import java.awt.event.ActionListener; +import java.nio.file.Path; + +import com.jacoco.mcdata.files.Config; +import com.jacoco.mcdata.files.Deobfuscation; +import com.jacoco.mcdata.version.Versions; +import com.jacoco.mcdata.view.ActionsView; + +public class ActionsController { + + private InitializationController initController; + private JDController jdController; + private Config cfg; + private Deobfuscation deobf; + private Runnable close; + + private ActionsView view; + + public ActionsController(InitializationController initController, JDController jdController, Config cfg, Deobfuscation deobf, Runnable close) { + this.initController = initController; + this.jdController = jdController; + this.cfg = cfg; + this.deobf = deobf; + this.close = close; + + this.view = new ActionsView(cfg, exportListener, e -> this.close.run()); + } + + public ActionsView getView() { + return this.view; + } + + private ActionListener exportListener = e -> { + cfg.setExportPath(initController.getExportPath()); + Path exportPath = cfg.getExportPath(); + deobf.addOnFinishEvent(() -> { + jdController.loadFile(exportPath.resolve(Versions.getLatest().getExportedJar()).toFile()); + }); + deobf.export(exportPath, Versions.getLatest()); + }; +} diff --git a/src/com/jacoco/mcdata/controller/InitializationController.java b/src/com/jacoco/mcdata/controller/InitializationController.java new file mode 100644 index 0000000..1d48a2b --- /dev/null +++ b/src/com/jacoco/mcdata/controller/InitializationController.java @@ -0,0 +1,112 @@ +package com.jacoco.mcdata.controller; + +import java.awt.FileDialog; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; + +import com.jacoco.mcdata.Theme; +import com.jacoco.mcdata.files.Config; +import com.jacoco.mcdata.version.Version; +import com.jacoco.mcdata.version.Versions; +import com.jacoco.mcdata.view.InitializationView; +import com.jacoco.mcdata.view.View; + +public class InitializationController { + + private Config cfg; + + private InitializationView view; + private JPanel panel; + private List components; + + private List views; + + public InitializationController(Config cfg, List views) { + this.cfg = cfg; + this.views = views; + + this.view = new InitializationView( + cfg, + chooseVersion, + selectExportPath, + this::themeAction + ); + + Runtime.getRuntime().addShutdownHook(new Thread(() -> cfg.setExportPath(((JTextField) view.getComponents().get(3)).getText()))); + + this.panel = view.getPanel(); + this.components = view.getComponents(); + } + + public InitializationView getView() { + return this.view; + } + + public String getExportPath() { + return ((JTextField) this.components.get(3)).getText(); + } + + private MouseAdapter chooseVersion = new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + try { + FileDialog fd = new FileDialog(new JFrame(), "Choose Folder"); + fd.setVisible(true); + Path path = Paths.get(fd.getDirectory()); + ((JTextField) e.getComponent()).setText(path.toString()); + Versions.add(new Version(path)); + } catch (NullPointerException ex) {} + } + }; + + private MouseAdapter selectExportPath = new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + try { + JFileChooser fd = null; + LookAndFeel previousLF = UIManager.getLookAndFeel(); + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + fd = new JFileChooser("Choose File"); + UIManager.setLookAndFeel(previousLF); + } catch (IllegalAccessException | UnsupportedLookAndFeelException | InstantiationException | ClassNotFoundException ex) {} + fd.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + fd.showOpenDialog(panel); + ((JTextField) e.getComponent()).setText(fd.getSelectedFile().toString()); + cfg.setExportPath(fd.getSelectedFile().toString()); + } catch (NullPointerException ex) {} + } + }; + + private void themeAction(ActionEvent e) { + JButton btn = (JButton) e.getSource(); + + String light = Theme.LIGHT.getName(); + String dark = Theme.DARK.getName(); + + switch(((JButton) e.getSource()).getText()) { + case "Light Mode": + btn.setText(dark); + cfg.setTheme(dark); + for(View guiView : this.views) guiView.updateTheme(Theme.DARK); + break; + case "Dark Mode": + btn.setText(light); + cfg.setTheme(light); + for(View guiView : this.views) guiView.updateTheme(Theme.LIGHT); + break; + } + } +} diff --git a/src/com/jacoco/mcdata/controller/JDController.java b/src/com/jacoco/mcdata/controller/JDController.java new file mode 100644 index 0000000..6329984 --- /dev/null +++ b/src/com/jacoco/mcdata/controller/JDController.java @@ -0,0 +1,33 @@ +package com.jacoco.mcdata.controller; + +import java.io.File; +import java.util.List; + +import org.jd.gui.JDGui; + +import com.jacoco.mcdata.files.Config; +import com.jacoco.mcdata.view.JDView; + +public class JDController { + + private JDView view; + private JDGui jd; + + public JDController(Config cfg) { + this.view = new JDView(cfg.getTheme()); + this.jd = new JDGui(view.getPanel(), cfg); + jd.show(); + } + + public JDView getView() { + return this.view; + } + + public void loadFile(File file) { + this.jd.loadFile(file); + } + + public void loadFiles(List files) { + this.jd.loadFiles(files); + } +} diff --git a/src/com/jacoco/mcdata/files/Config.java b/src/com/jacoco/mcdata/files/Config.java index 03eb3b6..78f005b 100644 --- a/src/com/jacoco/mcdata/files/Config.java +++ b/src/com/jacoco/mcdata/files/Config.java @@ -1,110 +1,131 @@ -package com.jacoco.mcdata.files; - -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; - -import com.jacoco.mcdata.Theme; - -public class Config { - - private String fn = "Config.json"; - - private JSONObject jo; - - private Path sourcesPath; - private File cfg; - - private Theme thm; - private String theme; - private Path export; - - public Config() { - this.sourcesPath = Paths.get(ClassLoader.getSystemClassLoader().getResource(".").getPath().substring(1)).resolve("Sources"); - this.cfg = this.sourcesPath.resolve(fn).toFile(); - - try { - - if(!cfg.exists()) { - Files.createDirectories(this.sourcesPath); - this.export = this.sourcesPath.resolve("Export"); - Files.createDirectories(this.export); - setupConfig(this.cfg); - this.thm = Theme.LIGHT; - } else { - this.jo = (JSONObject) JSONValue.parse(new FileReader(this.cfg)); - this.theme = jo.get("theme").toString(); - - try{ - export = Paths.get(jo.get("Export Path").toString()); - } catch (NullPointerException e) { - export = this.sourcesPath.resolve("Export"); - } - - switch(this.theme) { - case "Light Mode" : this.thm = Theme.LIGHT; - break; - case "Dark Mode" : this.thm = Theme.DARK; - break; - } - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - @SuppressWarnings("unchecked") - private void setupConfig(File path) throws IOException { - // create Config.json - this.jo = new JSONObject(); - - jo.put("theme", "Light Mode"); - jo.put("Export Path", this.export.toString()); - - FileWriter writer = new FileWriter(cfg); - writer.write(jo.toJSONString()); - writer.close(); - } - - public Path getExportPath() { - return this.export; - } - - public Theme getTheme() { - return this.thm; - } - - @SuppressWarnings("unchecked") - public void setExportPath(String path) { - try { - this.export = Paths.get(path); - this.jo.replace("Export Path", path); - FileWriter writer = new FileWriter(this.cfg); - writer.write(this.jo.toJSONString()); - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - } - - @SuppressWarnings("unchecked") - public void setTheme(String color) { - try { - this.thm = Theme.getThemeFromName(color); - this.jo.replace("theme", color); - FileWriter writer = new FileWriter(this.cfg); - writer.write(this.jo.toJSONString()); - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } -} +package com.jacoco.mcdata.files; + +import java.io.File; +import java.io.FileReader; +import java.io.PrintWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +import com.jacoco.mcdata.Utils; +import com.jacoco.mcdata.Theme; + +public class Config { + + private final String fn = "Config.json"; + + private JSONObject jo; + + private Path sourcesPath; + private File cfg; + + private Theme thm; + private String theme; + private Path export; + + public Config() { + this.sourcesPath = Paths.get(ClassLoader.getSystemClassLoader().getResource(".").getPath().substring(1)).resolve("Sources"); + this.cfg = this.sourcesPath.resolve(fn).toFile(); + + try { + if(!cfg.exists()) { + Files.createDirectories(this.sourcesPath); + this.export = this.sourcesPath.resolve("Export"); + Files.createDirectories(this.export); + setupConfig(this.cfg); + this.thm = Theme.LIGHT; + } else { + this.jo = (JSONObject) JSONValue.parse(new FileReader(this.cfg)); + this.theme = jo.get("theme").toString(); + + try{ + export = Paths.get(jo.get("exportPath").toString()); + } catch (NullPointerException e) { + export = this.sourcesPath.resolve("Export"); + } + + switch(this.theme) { + case "Light Mode" : this.thm = Theme.LIGHT; + break; + case "Dark Mode" : this.thm = Theme.DARK; + break; + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("unchecked") + private void setupConfig(File path) throws IOException { + this.jo = new JSONObject(); + + jo.put("theme", "Light Mode"); + jo.put("exportPath", this.export.toString()); + jo.put("jd", null); + + PrintWriter writer = new PrintWriter(cfg); + writer.write(Utils.prettyPrint(jo.toJSONString())); + writer.close(); + } + + public Path getSourcesPath() { + return this.sourcesPath; + } + + public Path getExportPath() { + return this.export; + } + + public Theme getTheme() { + return this.thm; + } + + public JSONObject getJD() { + return (JSONObject) this.jo.get("jd"); + } + + @SuppressWarnings("unchecked") + public void setExportPath(String path) { + try { + this.export = Paths.get(path); + this.jo.replace("exportPath", path); + PrintWriter writer = new PrintWriter(this.cfg); + writer.write(Utils.prettyPrint(this.jo.toJSONString())); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + @SuppressWarnings("unchecked") + public void setTheme(String color) { + try { + this.thm = Theme.getThemeFromName(color); + this.jo.replace("theme", color); + PrintWriter writer = new PrintWriter(this.cfg); + writer.write(Utils.prettyPrint(this.jo.toJSONString())); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("unchecked") + public void saveJDConfig(JSONObject jo) { + try { + this.jo.replace("jd", jo); + PrintWriter writer; + writer = new PrintWriter(this.cfg); + writer.write(Utils.prettyPrint(this.jo.toJSONString())); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/com/jacoco/mcdata/files/Deobfuscation.java b/src/com/jacoco/mcdata/files/Deobfuscation.java index f343525..15d7722 100644 --- a/src/com/jacoco/mcdata/files/Deobfuscation.java +++ b/src/com/jacoco/mcdata/files/Deobfuscation.java @@ -1,153 +1,146 @@ -package com.jacoco.mcdata.files; - -import java.awt.BorderLayout; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.nio.file.Path; -import java.util.concurrent.CompletableFuture; - -import javax.swing.BorderFactory; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JProgressBar; - -import com.jacoco.mcdata.Gui; -import com.jacoco.mcdata.Main; -import com.jacoco.mcdata.Version; - -import cuchaz.enigma.Enigma; -import cuchaz.enigma.EnigmaProfile; -import cuchaz.enigma.EnigmaProject; -import cuchaz.enigma.ProgressListener; -import cuchaz.enigma.gui.dialog.ProgressDialog.ProgressRunnable; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.mapping.serde.MappingFormat; -import cuchaz.enigma.translation.mapping.tree.EntryTree; -import cuchaz.enigma.utils.Utils; - -public class Deobfuscation { - - private Gui gui; - - private Enigma enigma; - private EnigmaProject project; - - private MappingFormat format; - private ProgressDialog pd; - - private Runnable onFinish; - - public Deobfuscation(Gui gui, EnigmaProfile profile, MappingFormat format) { - this.gui = gui; - this.enigma = Enigma.builder().setProfile(profile).build(); - this.format = format; - this.pd = new ProgressDialog(); - } - - public void export(Path exportPath, Version version) { - version.setExportedJar(exportPath.resolve(version.getName() + ".jar")); - - pd.runOffThread(progress -> { - pd.frame.setTitle("Exporting Jar 1/4"); - project = enigma.openJar(version.getOriginalJar(), progress); - - pd.frame.setTitle("Exporting Jar 2/4"); - Path downloadedMap = version.getObfuscationMap().downloadFile(Main.getTmpDir(), progress); - - pd.frame.setTitle("Exporting Jar 3/4"); - EntryTree mappings = format.read(downloadedMap, progress, null); - project.setMappings(mappings); - - EnigmaProject.JarExport jar = project.exportRemappedJar(progress); - pd.frame.setTitle("Exporting Jar 4/4"); - jar.write(version.getExportedJar(), progress); - }); - } - - public void addOnFinishEvent(Runnable runnable) { - this.onFinish = runnable; - } - - class ProgressDialog implements ProgressListener, AutoCloseable { - private JFrame frame = new JFrame(String.format("Progress", new Object[] { "Enigma" })); - - private JLabel labelTitle; - - private JLabel labelText; - - private JProgressBar progress; - - public void setup(JFrame parent) { - Container pane = this.frame.getContentPane(); - FlowLayout layout = new FlowLayout(); - layout.setAlignment(0); - pane.setLayout(layout); - this.labelTitle = new JLabel(); - pane.add(this.labelTitle); - JPanel panel = new JPanel(); - pane.add(panel); - panel.setLayout(new BorderLayout()); - this.labelText = Utils.unboldLabel(new JLabel()); - this.progress = new JProgressBar(); - this.labelText.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); - panel.add(this.labelText, "North"); - panel.add(this.progress, "Center"); - panel.setPreferredSize(new Dimension(360, 50)); - pane.doLayout(); - this.frame.setSize(400, 120); - this.frame.setResizable(false); - this.frame.setLocationRelativeTo(parent); - this.frame.setVisible(true); - this.frame.setDefaultCloseOperation(0); - } - - public CompletableFuture runOffThread(ProgressRunnable runnable) { - OnExport onExport = new OnExport() { - public Void run() { - try (ProgressDialog progress = ProgressDialog.this) { - progress.setup(gui.getFrame()); - runnable.run(progress); - } catch (Exception ex) { - throw new Error(ex); - } - return null; - } - - public Void finish(Void arg) { - onFinish.run(); - return null; - } - }; - - CompletableFuture future = CompletableFuture.supplyAsync(onExport::run); - future.thenApplyAsync(onExport::finish); - - return future; - } - - public void close() { - this.frame.dispose(); - } - - public void init(int totalWork, String title) { - this.labelTitle.setText(title); - this.progress.setMinimum(0); - this.progress.setMaximum(totalWork); - this.progress.setValue(0); - } - - public void step(int numDone, String message) { - this.labelText.setText(message); - if (numDone != -1) { - this.progress.setValue(numDone); - this.progress.setIndeterminate(false); - } else { - this.progress.setIndeterminate(true); - } - this.frame.validate(); - this.frame.repaint(); - } - } -} +package com.jacoco.mcdata.files; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.nio.file.Path; +import java.util.concurrent.CompletableFuture; + +import javax.swing.BorderFactory; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; + +import com.jacoco.mcdata.Main; +import com.jacoco.mcdata.version.Version; + +import cuchaz.enigma.Enigma; +import cuchaz.enigma.EnigmaProfile; +import cuchaz.enigma.EnigmaProject; +import cuchaz.enigma.ProgressListener; +import cuchaz.enigma.gui.dialog.ProgressDialog.ProgressRunnable; +import cuchaz.enigma.translation.mapping.EntryMapping; +import cuchaz.enigma.translation.mapping.serde.MappingFormat; +import cuchaz.enigma.translation.mapping.tree.EntryTree; +import cuchaz.enigma.utils.Utils; + +public class Deobfuscation { + + private Enigma enigma; + private MappingFormat format; + private Runnable onFinish; + + public Deobfuscation(MappingFormat format, EnigmaProfile profile) { + this.enigma = Enigma.builder().setProfile(profile).build(); + this.format = format; + } + + public void export(Path exportPath, Version version) { + version.setExportedJar(exportPath.resolve(version.getName() + ".jar")); + + try (ProgressDialog pd = new ProgressDialog()) { + pd.runOffThread(progress -> { + pd.frame.setTitle("Exporting Jar 1/4"); + EnigmaProject project = enigma.openJar(version.getOriginalJar(), progress); + + pd.frame.setTitle("Exporting Jar 2/4"); + Path downloadedMap = version.getObfuscationMap().downloadFile(Main.tmpDir, progress); + + pd.frame.setTitle("Exporting Jar 3/4"); + EntryTree mappings = format.read(downloadedMap, progress, null); + project.setMappings(mappings); + + EnigmaProject.JarExport jar = project.exportRemappedJar(progress); + pd.frame.setTitle("Exporting Jar 4/4"); + jar.write(version.getExportedJar(), progress); + }); + } + } + + public void addOnFinishEvent(Runnable runnable) { + this.onFinish = runnable; + } + + class ProgressDialog implements ProgressListener, AutoCloseable { + private JFrame frame = new JFrame(String.format("Progress", new Object[] { "Enigma" })); + + private JLabel labelTitle; + + private JLabel labelText; + + private JProgressBar progress; + + public void setup() { + Container pane = this.frame.getContentPane(); + FlowLayout layout = new FlowLayout(); + layout.setAlignment(0); + pane.setLayout(layout); + this.labelTitle = new JLabel(); + pane.add(this.labelTitle); + JPanel panel = new JPanel(); + pane.add(panel); + panel.setLayout(new BorderLayout()); + this.labelText = Utils.unboldLabel(new JLabel()); + this.progress = new JProgressBar(); + this.labelText.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); + panel.add(this.labelText, "North"); + panel.add(this.progress, "Center"); + panel.setPreferredSize(new Dimension(360, 50)); + pane.doLayout(); + this.frame.setSize(400, 120); + this.frame.setResizable(false); + this.frame.setLocationRelativeTo(null); + this.frame.setVisible(true); + this.frame.setDefaultCloseOperation(0); + } + + public CompletableFuture runOffThread(ProgressRunnable runnable) { + OnExport onExport = new OnExport() { + public Void run() { + try (ProgressDialog progress = ProgressDialog.this) { + progress.setup(); + runnable.run(progress); + } catch (Exception ex) { + throw new Error(ex); + } + return null; + } + + public Void finish(Void arg) { + onFinish.run(); + return null; + } + }; + + CompletableFuture future = CompletableFuture.supplyAsync(onExport::run); + future.thenApplyAsync(onExport::finish); + + return future; + } + + public void close() { + this.frame.dispose(); + } + + public void init(int totalWork, String title) { + this.labelTitle.setText(title); + this.progress.setMinimum(0); + this.progress.setMaximum(totalWork); + this.progress.setValue(0); + } + + public void step(int numDone, String message) { + this.labelText.setText(message); + if (numDone != -1) { + this.progress.setValue(numDone); + this.progress.setIndeterminate(false); + } else { + this.progress.setIndeterminate(true); + } + this.frame.validate(); + this.frame.repaint(); + } + } +} diff --git a/src/com/jacoco/mcdata/files/ObfuscationMap.java b/src/com/jacoco/mcdata/files/ObfuscationMap.java index 983470f..289a533 100644 --- a/src/com/jacoco/mcdata/files/ObfuscationMap.java +++ b/src/com/jacoco/mcdata/files/ObfuscationMap.java @@ -1,67 +1,67 @@ -package com.jacoco.mcdata.files; - -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; -import java.nio.file.Files; -import java.nio.file.Path; - -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; - -import com.jacoco.mcdata.Versions; - -import cuchaz.enigma.ProgressListener; - -public class ObfuscationMap { - - private Path fileMap; - private URL mapurl; - - public ObfuscationMap(Path path) { - try { - JSONObject jo = (JSONObject) ((JSONObject) ((JSONObject) - JSONValue.parse(new FileReader(path.toString()))).get("downloads")).get("client_mappings"); - this.mapurl = new URL(jo.get("url").toString()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public Path downloadFile(Path tmpDir, ProgressListener progress) { - try { - progress.init(3, "Downloading Obfuscation Map as a Temp File"); - - progress.step(1, "Creating Temp File"); - fileMap = Files.createTempFile(tmpDir, Versions.getLatest().getName() + "_", ".txt"); - fileMap.toFile().deleteOnExit(); - - progress.step(2, "Connecting to URL"); - ReadableByteChannel rbc = Channels.newChannel(mapurl.openStream()); - progress.step(3, "Writing File"); - FileOutputStream fos = new FileOutputStream(fileMap.toFile()); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - return this.fileMap; - } - - public Path getFile() throws FileNotFoundException { - if(this.fileMap.toFile().exists()) - return this.fileMap; - else - throw new FileNotFoundException(); - } - - public URL getURL() { - return this.mapurl; - } -} +package com.jacoco.mcdata.files; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +import com.jacoco.mcdata.version.Versions; + +import cuchaz.enigma.ProgressListener; + +public class ObfuscationMap { + + private Path fileMap; + private URL mapurl; + + public ObfuscationMap(Path path) { + try { + JSONObject jo = (JSONObject) ((JSONObject) ((JSONObject) + JSONValue.parse(new FileReader(path.toString()))).get("downloads")).get("client_mappings"); + this.mapurl = new URL(jo.get("url").toString()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public Path downloadFile(Path tmpDir, ProgressListener progress) { + try { + progress.init(3, "Downloading Obfuscation Map as a Temp File"); + + progress.step(1, "Creating Temp File"); + fileMap = Files.createTempFile(tmpDir, Versions.getLatest().getName() + "_", ".txt"); + fileMap.toFile().deleteOnExit(); + + progress.step(2, "Connecting to URL"); + ReadableByteChannel rbc = Channels.newChannel(mapurl.openStream()); + progress.step(3, "Writing File"); + FileOutputStream fos = new FileOutputStream(fileMap.toFile()); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + return this.fileMap; + } + + public Path getFile() throws FileNotFoundException { + if(this.fileMap.toFile().exists()) + return this.fileMap; + else + throw new FileNotFoundException(); + } + + public URL getURL() { + return this.mapurl; + } +} \ No newline at end of file diff --git a/src/com/jacoco/mcdata/files/OnExport.java b/src/com/jacoco/mcdata/files/OnExport.java index 7eb3275..a7a193d 100644 --- a/src/com/jacoco/mcdata/files/OnExport.java +++ b/src/com/jacoco/mcdata/files/OnExport.java @@ -1,7 +1,7 @@ -package com.jacoco.mcdata.files; - -public interface OnExport { - public Void run(); - - public Void finish(Void arg); -} +package com.jacoco.mcdata.files; + +public interface OnExport { + public Void run(); + + public Void finish(Void arg); +} diff --git a/src/com/jacoco/mcdata/Version.java b/src/com/jacoco/mcdata/version/Version.java similarity index 92% rename from src/com/jacoco/mcdata/Version.java rename to src/com/jacoco/mcdata/version/Version.java index 1a74916..0ce79da 100644 --- a/src/com/jacoco/mcdata/Version.java +++ b/src/com/jacoco/mcdata/version/Version.java @@ -1,61 +1,61 @@ -package com.jacoco.mcdata; - -import java.nio.file.Path; - -import com.jacoco.mcdata.files.ObfuscationMap; - -public class Version { - - private String name; - private Path oJar; - private Path eJar; - private Path json; - private ObfuscationMap obfuscationMap; - - public Version(Path path) { - this.name = path.getFileName().toString(); - this.oJar = path.resolve(name + ".jar"); - this.json = path.resolve(name + ".json"); - this.obfuscationMap = new ObfuscationMap(this.json); - } - - public String getName() { - return name; - } - - public Path getOriginalJar() { - return oJar; - } - - public Path getExportedJar() { - return eJar; - } - - public Path getJson() { - return json; - } - - public ObfuscationMap getObfuscationMap() { - return obfuscationMap; - } - - public void setName(String name) { - this.name = name; - } - - public void setOriginalJar(Path oJar) { - this.oJar = oJar; - } - - public void setExportedJar(Path eJar) { - this.eJar = eJar; - } - - public void setJson(Path json) { - this.json = json; - } - - public void setObfuscationMap(ObfuscationMap obfuscationMap) { - this.obfuscationMap = obfuscationMap; - } -} +package com.jacoco.mcdata.version; + +import java.nio.file.Path; + +import com.jacoco.mcdata.files.ObfuscationMap; + +public class Version { + + private String name; + private Path oJar; + private Path eJar; + private Path json; + private ObfuscationMap obfuscationMap; + + public Version(Path path) { + this.name = path.getFileName().toString(); + this.oJar = path.resolve(name + ".jar"); + this.json = path.resolve(name + ".json"); + this.obfuscationMap = new ObfuscationMap(this.json); + } + + public String getName() { + return name; + } + + public Path getOriginalJar() { + return oJar; + } + + public Path getExportedJar() { + return eJar; + } + + public Path getJson() { + return json; + } + + public ObfuscationMap getObfuscationMap() { + return obfuscationMap; + } + + public void setName(String name) { + this.name = name; + } + + public void setOriginalJar(Path oJar) { + this.oJar = oJar; + } + + public void setExportedJar(Path eJar) { + this.eJar = eJar; + } + + public void setJson(Path json) { + this.json = json; + } + + public void setObfuscationMap(ObfuscationMap obfuscationMap) { + this.obfuscationMap = obfuscationMap; + } +} diff --git a/src/com/jacoco/mcdata/Versions.java b/src/com/jacoco/mcdata/version/Versions.java similarity index 90% rename from src/com/jacoco/mcdata/Versions.java rename to src/com/jacoco/mcdata/version/Versions.java index 932433c..03fc675 100644 --- a/src/com/jacoco/mcdata/Versions.java +++ b/src/com/jacoco/mcdata/version/Versions.java @@ -1,31 +1,31 @@ -package com.jacoco.mcdata; - -import java.util.ArrayList; -import java.util.List; - -public class Versions { - - private Versions() {} - - private static List versions = new ArrayList(); - - public static List getVersions() { - return versions; - } - - public static Version getLatest() { - return versions.get(versions.size()-1); - } - - public static void add(Version version) { - versions.add(version); - } - - public static void remove(Version version) { - versions.remove(version); - } - - public static void clear() { - versions.clear(); - } -} +package com.jacoco.mcdata.version; + +import java.util.ArrayList; +import java.util.List; + +public class Versions { + + private Versions() {} + + private static List versions = new ArrayList(); + + public static List getVersions() { + return versions; + } + + public static Version getLatest() { + return versions.get(versions.size()-1); + } + + public static void add(Version version) { + versions.add(version); + } + + public static void remove(Version version) { + versions.remove(version); + } + + public static void clear() { + versions.clear(); + } +} diff --git a/src/com/jacoco/mcdata/view/ActionsView.java b/src/com/jacoco/mcdata/view/ActionsView.java new file mode 100644 index 0000000..07f5da0 --- /dev/null +++ b/src/com/jacoco/mcdata/view/ActionsView.java @@ -0,0 +1,61 @@ +package com.jacoco.mcdata.view; + +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JPanel; + +import com.jacoco.mcdata.Theme; +import com.jacoco.mcdata.files.Config; + +public class ActionsView extends View { + + private JPanel panel; + private Theme theme; + private List components = new ArrayList(); + + public ActionsView( + Config cfg, + ActionListener exportListener, + ActionListener closeListener) { + this.theme = cfg.getTheme(); + this.panel = new JPanel(); + + Dimension buttonSize = new Dimension(100, 40); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets(0, 50, 0, 50); + constraints.fill = GridBagConstraints.NONE; + panel.setLayout(new GridBagLayout()); + panel.setPreferredSize(new Dimension(0, 100)); + applyTheme(panel, theme, NORMAL); + + JButton export = new JButton("Export"); + export.setPreferredSize(buttonSize); + applyTheme(export, theme, BUTTON); + panel.add(export, constraints); + export.addActionListener(exportListener); + components.add(export); + + JButton close = new JButton("Close"); + close.setPreferredSize(buttonSize); + applyTheme(close, theme, BUTTON); + panel.add(close, constraints); + close.addActionListener(closeListener); + components.add(close); + } + + public JPanel getPanel() { + return panel; + } + + public List getComponents() { + return components; + } +} diff --git a/src/com/jacoco/mcdata/view/InitializationView.java b/src/com/jacoco/mcdata/view/InitializationView.java new file mode 100644 index 0000000..967b9c5 --- /dev/null +++ b/src/com/jacoco/mcdata/view/InitializationView.java @@ -0,0 +1,95 @@ +package com.jacoco.mcdata.view; + +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import com.jacoco.mcdata.Theme; +import com.jacoco.mcdata.files.Config; + +public class InitializationView extends View { + + private List components = new ArrayList(); + + private JPanel panel; + + private JTextField versionChooser; + private JLabel versionChooserLabel; + + private JTextField exportPath; + private JLabel exportPathLabel; + + private JButton thm; + + private Theme theme; + + public InitializationView( + Config cfg, + MouseAdapter chooseVersion, + MouseAdapter selectExportPath, + ActionListener themeAction) { + this.theme = cfg.getTheme(); + this.panel = new JPanel(); + + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets(5, 0, 0, 0); + panel.setLayout(new GridBagLayout()); + panel.setPreferredSize(new Dimension(0, 150)); + applyTheme(panel, theme, NORMAL); + + versionChooserLabel = new JLabel("Choose Version Folder"); + applyTheme(versionChooserLabel, theme, NORMAL); + versionChooserLabel.setPreferredSize(new Dimension(400, 10)); + panel.add(versionChooserLabel, constraints); + components.add(versionChooserLabel); + + versionChooser = new JTextField("Choose Folder"); + applyTheme(versionChooser, theme, NORMAL); + versionChooser.setPreferredSize(new Dimension(400, 30)); + constraints.gridy = 1; + panel.add(versionChooser, constraints); + versionChooser.addMouseListener(chooseVersion); + components.add(versionChooser); + + exportPathLabel = new JLabel("Choose Export Folder"); + applyTheme(exportPathLabel, theme, NORMAL); + exportPathLabel.setPreferredSize(new Dimension(400, 10)); + constraints.gridy = 2; + panel.add(exportPathLabel, constraints); + components.add(exportPathLabel); + + exportPath = new JTextField(cfg.getExportPath().toString()); + applyTheme(exportPath, theme, NORMAL); + exportPath.setPreferredSize(new Dimension(400, 30)); + constraints.gridy = 3; + panel.add(exportPath, constraints); + exportPath.addMouseListener(selectExportPath); + components.add(exportPath); + + thm = new JButton(this.theme.getName()); + applyTheme(thm, theme, BUTTON); + thm.setPreferredSize(new Dimension(100, 30)); + panel.add(thm, constraints); + thm.addActionListener(themeAction); + components.add(thm); + } + + public List getComponents() { + return this.components; + } + + public JPanel getPanel() { + return this.panel; + } +} diff --git a/src/com/jacoco/mcdata/view/JDView.java b/src/com/jacoco/mcdata/view/JDView.java new file mode 100644 index 0000000..6457724 --- /dev/null +++ b/src/com/jacoco/mcdata/view/JDView.java @@ -0,0 +1,29 @@ +package com.jacoco.mcdata.view; + +import java.awt.BorderLayout; +import java.util.Collections; +import java.util.List; + +import javax.swing.JComponent; +import javax.swing.JPanel; + +import com.jacoco.mcdata.Theme; + +public class JDView extends View { + + private JPanel panel; + + public JDView(Theme thm) { + this.panel = new JPanel(); + panel.setLayout(new BorderLayout()); + applyTheme(panel, thm, NORMAL); + } + + public JPanel getPanel() { + return this.panel; + } + + public List getComponents() { + return Collections.emptyList(); + } +} diff --git a/src/com/jacoco/mcdata/view/View.java b/src/com/jacoco/mcdata/view/View.java new file mode 100644 index 0000000..b6f83a2 --- /dev/null +++ b/src/com/jacoco/mcdata/view/View.java @@ -0,0 +1,48 @@ +package com.jacoco.mcdata.view; + +import java.awt.Color; +import java.util.List; + +import javax.swing.JComponent; +import javax.swing.JPanel; + +import com.jacoco.mcdata.Theme; + +public abstract class View { + + public abstract JPanel getPanel(); + public abstract List getComponents(); + + protected final String NORMAL = "normal"; + protected final String BUTTON = "button"; + + public void updateTheme(Theme theme) { + Color text = theme.getText(); + Color background = theme.getBg(); + Color button = theme.getBtn(); + getComponents().forEach(e -> { + switch(e.getName()) { + case NORMAL: + e.setForeground(text); + e.setBackground(background); + break; + case BUTTON: + e.setForeground(text); + e.setBackground(button); + break; + } + }); + } + + protected void applyTheme(JComponent component, Theme theme, String type) { + Color text = theme.getText(); + Color background = theme.getBg(); + Color button = theme.getBtn(); + component.setForeground(text); + if(type.equals(NORMAL)) + component.setBackground(background); + else if(type.equals(BUTTON)) + component.setBackground(button); + component.setName(type); + } +} \ No newline at end of file diff --git a/src/org/jd/gui/Constants.java b/src/org/jd/gui/Constants.java index 75d5cdd..d842f81 100644 --- a/src/org/jd/gui/Constants.java +++ b/src/org/jd/gui/Constants.java @@ -16,8 +16,6 @@ public class Constants { public static final int MINIMAL_WIDTH = 500; public static final int MINIMAL_HEIGHT = 160; - public static final String CONFIG_FILENAME = "jd-gui.cfg"; - public static final int MAX_RECENT_FILES = 10; public static final int RECENT_FILE_MAX_LENGTH = 200; } diff --git a/src/org/jd/gui/JDGui.java b/src/org/jd/gui/JDGui.java index 94308c0..b2cfa25 100644 --- a/src/org/jd/gui/JDGui.java +++ b/src/org/jd/gui/JDGui.java @@ -8,68 +8,54 @@ package org.jd.gui; import java.io.File; -import java.util.ArrayList; import java.util.Collections; import java.util.List; +import javax.swing.JPanel; import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; import org.jd.gui.controller.MainController; import org.jd.gui.model.configuration.Configuration; -import org.jd.gui.service.configuration.ConfigurationPersister; -import org.jd.gui.service.configuration.ConfigurationPersisterService; -import org.jd.gui.util.exception.ExceptionUtil; +import org.jd.gui.service.ConfigurationPersister; + +import com.jacoco.mcdata.files.Config; public class JDGui { protected MainController controller; + protected JPanel parent; + protected Configuration configuration; - public JDGui() { + public JDGui(JPanel parent, Config cfg) { + this.parent = parent; // Load preferences - ConfigurationPersister persister = ConfigurationPersisterService.getInstance().get(); - Configuration configuration = persister.load(); + ConfigurationPersister persister = new ConfigurationPersister(cfg); + this.configuration = persister.load(); Runtime.getRuntime().addShutdownHook(new Thread(() -> persister.save(configuration))); - - // Create SwingBuilder, set look and feel - try { - UIManager.setLookAndFeel(configuration.getLookAndFeel()); - } catch (Exception e) { - configuration.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - try { - UIManager.setLookAndFeel(configuration.getLookAndFeel()); - } catch (Exception ee) { - assert ExceptionUtil.printStackTrace(ee); - } - } - - // Create main controller and show main frame - controller = new MainController(configuration); - controller.show(); + } + + public void show() { + new Thread( + () -> { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException + | UnsupportedLookAndFeelException e) { + e.printStackTrace(); + } + // Create main controller and show main frame + controller = new MainController(parent, configuration); + controller.show(Collections.emptyList()); + }, + "JD-Gui" + ).start(); } public void loadFile(File file) { controller.openFile(file); } - - protected static boolean checkHelpFlag(String[] args) { - if (args != null) { - for (String arg : args) { - if ("-h".equals(arg)) { - return true; - } - } - } - return false; - } - - protected static List newList(String[] paths) { - if (paths == null) { - return Collections.emptyList(); - } else { - ArrayList files = new ArrayList<>(paths.length); - for (String path : paths) { - files.add(new File(path)); - } - return files; - } - } + + public void loadFiles(List files) { + controller.openFiles(files); + } } diff --git a/src/org/jd/gui/controller/MainController.java b/src/org/jd/gui/controller/MainController.java index bcc458a..a70aa60 100644 --- a/src/org/jd/gui/controller/MainController.java +++ b/src/org/jd/gui/controller/MainController.java @@ -7,6 +7,7 @@ package org.jd.gui.controller; +import java.awt.Component; import java.awt.Desktop; import java.awt.Frame; import java.awt.Point; @@ -36,8 +37,10 @@ import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.JFrame; +import javax.swing.JInternalFrame; import javax.swing.JLayer; import javax.swing.JOptionPane; +import javax.swing.JPanel; import javax.swing.TransferHandler; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileSystemView; @@ -89,6 +92,8 @@ public class MainController implements API { protected Configuration configuration; protected MainView mainView; + protected List files = new ArrayList<>(); + protected JPanel internalContainer; protected GoToController goToController; protected OpenTypeController openTypeController; @@ -105,8 +110,8 @@ public class MainController implements API { protected ScheduledExecutorService executor = Executors.newScheduledThreadPool(2); protected ArrayList containerChangeListeners = new ArrayList<>(); - @SuppressWarnings("unchecked") - public MainController(Configuration configuration) { + public MainController(JPanel internalContainer, Configuration configuration) { + this.internalContainer = internalContainer; this.configuration = configuration; SwingUtil.invokeLater(() -> { @@ -116,8 +121,14 @@ public MainController(Configuration configuration) { } // Create main frame - mainView = new MainView( - configuration, this, history, + mainView = createView(MainView.INTERNAL); + }); + } + + @SuppressWarnings("unchecked") + protected MainView createView(int boundedness) { + return new MainView( + boundedness, configuration, this, history, e -> onOpen(), e -> onClose(), e -> onSaveSource(), @@ -144,16 +155,20 @@ public MainController(Configuration configuration) { e -> onAbout(), () -> panelClosed(), page -> onCurrentPageChanged((JComponent)page), - file -> openFile((File)file)); - }); - } + file -> openFile((File)file), + comp -> onPanelClosed((Component) comp), + () -> onWindowClose()); + } // --- Show GUI --- // @SuppressWarnings("unchecked") - public void show() { + public void show(List files) { SwingUtil.invokeLater(() -> { // Show main frame mainView.show(configuration.getMainWindowLocation(), configuration.getMainWindowSize(), configuration.isMainWindowMaximize()); + if (!files.isEmpty()) { + openFiles(files); + } }); // Background initializations @@ -166,29 +181,32 @@ public void show() { TreeNodeFactoryService.getInstance(); TypeFactoryService.getInstance(); - SwingUtil.invokeLater(() -> { - // Populate recent files menu - mainView.updateRecentFilesMenu(configuration.getRecentFiles()); - // Background controller creation - JFrame mainFrame = mainView.getMainFrame(); - saveAllSourcesController = new SaveAllSourcesController(MainController.this, mainFrame); - containerChangeListeners.add(openTypeController = new OpenTypeController(MainController.this, executor, mainFrame)); - containerChangeListeners.add(openTypeHierarchyController = new OpenTypeHierarchyController(MainController.this, executor, mainFrame)); - goToController = new GoToController(configuration, mainFrame); - containerChangeListeners.add(searchInConstantPoolsController = new SearchInConstantPoolsController(MainController.this, executor, mainFrame)); - preferencesController = new PreferencesController(configuration, mainFrame, PreferencesPanelService.getInstance().getProviders()); - selectLocationController = new SelectLocationController(MainController.this, mainFrame); - aboutController = new AboutController(mainFrame); - sourceLoaderService = new SourceLoaderService(); - // Add listeners - mainFrame.addComponentListener(new MainFrameListener(configuration)); - // Set drop files transfer handler - mainFrame.setTransferHandler(new FilesTransferHandler()); - // Background class loading - new JFileChooser().addChoosableFileFilter(new FileNameExtensionFilter("", "dummy")); - FileSystemView.getFileSystemView().isFileSystemRoot(new File("dummy")); - new JLayer(); - }); + // Populate recent files menu + mainView.updateRecentFilesMenu(configuration.getRecentFiles()); + // Background controller creation + JFrame mainFrame = null; + Component tempMainFrame = mainView.getMainFrame(); + if(tempMainFrame instanceof JFrame) + mainFrame = (JFrame) tempMainFrame; + else if(tempMainFrame instanceof JInternalFrame) + internalContainer.add(mainView.getMainFrame()); + saveAllSourcesController = new SaveAllSourcesController(MainController.this, mainFrame); + containerChangeListeners.add(openTypeController = new OpenTypeController(MainController.this, executor, mainFrame)); + containerChangeListeners.add(openTypeHierarchyController = new OpenTypeHierarchyController(MainController.this, executor, mainFrame)); + goToController = new GoToController(configuration, mainFrame); + containerChangeListeners.add(searchInConstantPoolsController = new SearchInConstantPoolsController(MainController.this, executor, mainFrame)); + preferencesController = new PreferencesController(configuration, mainFrame, PreferencesPanelService.getInstance().getProviders()); + selectLocationController = new SelectLocationController(MainController.this, mainFrame); + aboutController = new AboutController(mainFrame); + sourceLoaderService = new SourceLoaderService(); + // Add listeners + mainFrame.addComponentListener(new MainFrameListener(configuration)); + // Set drop files transfer handler + mainFrame.setTransferHandler(new FilesTransferHandler()); + // Background class loading + new JFileChooser().addChoosableFileFilter(new FileNameExtensionFilter("", "dummy")); + FileSystemView.getFileSystemView().isFileSystemRoot(new File("dummy")); + new JLayer(); }, 400, TimeUnit.MILLISECONDS); PasteHandlerService.getInstance(); @@ -238,7 +256,7 @@ protected void onClose() { protected void onSaveSource() { if (currentPage instanceof ContentSavable) { JFileChooser chooser = new JFileChooser(); - JFrame mainFrame = mainView.getMainFrame(); + Component mainFrame = mainView.getMainFrame(); chooser.setSelectedFile(new File(configuration.getRecentSaveDirectory(), ((ContentSavable)currentPage).getFileName())); @@ -276,7 +294,7 @@ protected void onSaveAllSources() { if (currentPanel instanceof SourcesSavable) { SourcesSavable sourcesSavable = (SourcesSavable)currentPanel; JFileChooser chooser = new JFileChooser(); - JFrame mainFrame = mainView.getMainFrame(); + Component mainFrame = mainView.getMainFrame(); chooser.setSelectedFile(new File(configuration.getRecentSaveDirectory(), sourcesSavable.getSourceFileName())); @@ -483,6 +501,8 @@ public void openFiles(List files) { if (errors.isEmpty()) { for (File file : files) { if (openURI(file.toURI())) { + if(!this.files.contains(file)) + this.files.add(file); configuration.addRecentFile(file); mainView.updateRecentFilesMenu(configuration.getRecentFiles()); } @@ -506,6 +526,27 @@ public void openFiles(List files) { JOptionPane.showMessageDialog(mainView.getMainFrame(), messages.toString(), "Error", JOptionPane.ERROR_MESSAGE); } } + + public void onWindowClose() { + Component comp = mainView.getMainFrame(); + if(comp instanceof JFrame) + this.mainView = createView(MainView.INTERNAL); + else if(comp instanceof JInternalFrame) + this.mainView = createView(MainView.EXTERNAL); + SwingUtil.invokeLater(() -> { + // Show main frame + Component newComp = mainView.getMainFrame(); + if(newComp instanceof JFrame) + mainView.show(configuration.getMainWindowLocation(), configuration.getMainWindowSize(), configuration.isMainWindowMaximize()); + else if(newComp instanceof JInternalFrame) { + internalContainer.add(newComp); + newComp.setVisible(true); + } + if (!files.isEmpty()) { + openFiles(files); + } + }); + } // --- Drop files transfer handler --- // protected class FilesTransferHandler extends TransferHandler { @@ -536,32 +577,40 @@ protected class MainFrameListener extends ComponentAdapter { public MainFrameListener(Configuration configuration) { this.configuration = configuration; } + + public String printstuff() { + return "stuff"; + } @Override public void componentMoved(ComponentEvent e) { - JFrame mainFrame = mainView.getMainFrame(); - - if ((mainFrame.getExtendedState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH) { - configuration.setMainWindowMaximize(true); - } else { - configuration.setMainWindowLocation(mainFrame.getLocation()); - configuration.setMainWindowMaximize(false); - } + Component mainFrame = mainView.getMainFrame(); + if(mainFrame instanceof JFrame) + if ((((JFrame) mainFrame).getExtendedState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH) { + configuration.setMainWindowMaximize(true); + } else { + configuration.setMainWindowLocation(mainFrame.getLocation()); + configuration.setMainWindowMaximize(false); + } } @Override public void componentResized(ComponentEvent e) { - JFrame mainFrame = mainView.getMainFrame(); - - if ((mainFrame.getExtendedState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH) { - configuration.setMainWindowMaximize(true); - } else { - configuration.setMainWindowSize(mainFrame.getSize()); - configuration.setMainWindowMaximize(false); - } + Component mainFrame = mainView.getMainFrame(); + if(mainFrame instanceof JFrame) + if ((((JFrame) mainFrame).getExtendedState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH) { + configuration.setMainWindowMaximize(true); + } else { + configuration.setMainWindowSize(mainFrame.getSize()); + configuration.setMainWindowMaximize(false); + } } } + public void onPanelClosed(Component component) { + files.remove(new File(component.getName())); + } + protected void panelClosed() { SwingUtil.invokeLater(() -> { // Fire 'indexesChanged' event diff --git a/src/org/jd/gui/service/ConfigurationPersister.java b/src/org/jd/gui/service/ConfigurationPersister.java new file mode 100644 index 0000000..6737d72 --- /dev/null +++ b/src/org/jd/gui/service/ConfigurationPersister.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2008-2019 Emmanuel Dupuy. + * This project is distributed under the GPLv3 license. + * This is a Copyleft license that gives the user the right to use, + * copy and modify the code freely for non-commercial purposes. + */ + +package org.jd.gui.service; + +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Toolkit; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; +import java.util.jar.Manifest; + +import org.jd.gui.Constants; +import org.jd.gui.model.configuration.Configuration; +import org.jd.gui.util.exception.ExceptionUtil; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; + +import com.jacoco.mcdata.files.Config; + +public class ConfigurationPersister { + protected static final String ERROR_BACKGROUND_COLOR = "JdGuiPreferences.errorBackgroundColor"; + protected static final String JD_CORE_VERSION = "JdGuiPreferences.jdCoreVersion"; + + protected Config cfg; + + public ConfigurationPersister(Config cfg) { + this.cfg = cfg; + } + + public Configuration load() { + // Default values + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + + int w = (screenSize.width>Constants.DEFAULT_WIDTH) ? Constants.DEFAULT_WIDTH : screenSize.width; + int h = (screenSize.height>Constants.DEFAULT_HEIGHT) ? Constants.DEFAULT_HEIGHT : screenSize.height; + int x = (screenSize.width-w)/2; + int y = (screenSize.height-h)/2; + + Configuration config = new Configuration(); + config.setMainWindowLocation(new Point(x, y)); + config.setMainWindowSize(new Dimension(w, h)); + config.setMainWindowMaximize(false); + + File recentSaveDirectory = new File(System.getProperty("user.dir")); + + config.setRecentLoadDirectory(recentSaveDirectory); + config.setRecentSaveDirectory(recentSaveDirectory); + + JSONObject jo = cfg.getJD(); + if(jo != null) { + JSONObject gui = (JSONObject) jo.get("gui"); + JSONObject mainWindow = (JSONObject) gui.get("mainWindow"); + JSONObject location = (JSONObject) mainWindow.get("location"); + Point loc = new Point(Integer.parseInt(location.get("x").toString()), Integer.parseInt(location.get("y").toString())); + config.setMainWindowLocation(loc); + JSONObject size = (JSONObject) mainWindow.get("size"); + Dimension dim = new Dimension(Integer.parseInt(size.get("w").toString()), Integer.parseInt(size.get("h").toString())); + config.setMainWindowSize(dim); + config.setMainWindowMaximize(Boolean.valueOf(mainWindow.get("maximize").toString())); + JSONArray recentFilePaths = (JSONArray) jo.get("recentFilePaths"); + List recentFiles = new ArrayList(); + for(Object o : recentFilePaths) { + recentFiles.add(new File(o.toString())); + } + config.setRecentFiles(recentFiles); + JSONObject recentDirectories = (JSONObject) jo.get("recentDirectories"); + config.setRecentLoadDirectory(new File(recentDirectories.get("loadPath").toString())); + config.setRecentSaveDirectory(new File(recentDirectories.get("savePath").toString()));; + JSONObject preferences = (JSONObject) jo.get("preferences"); + for(Object o : preferences.keySet()) { + String key = o.toString(); + config.getPreferences().put(key, preferences.get(key).toString()); + } + } + + if (!config.getPreferences().containsKey(ERROR_BACKGROUND_COLOR)) { + config.getPreferences().put(ERROR_BACKGROUND_COLOR, "0xFF6666"); + } + + config.getPreferences().put(JD_CORE_VERSION, getJdCoreVersion()); + + return config; + } + + protected String getJdCoreVersion() { + try { + Enumeration enumeration = ConfigurationPersister.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); + + while (enumeration.hasMoreElements()) { + try (InputStream is = enumeration.nextElement().openStream()) { + String attribute = new Manifest(is).getMainAttributes().getValue("JD-Core-Version"); + if (attribute != null) { + return attribute; + } + } + } + } catch (IOException e) { + assert ExceptionUtil.printStackTrace(e); + } + + return "SNAPSHOT"; + } + + @SuppressWarnings("unchecked") + public void save(Configuration configuration) { + Point l = configuration.getMainWindowLocation(); + Dimension s = configuration.getMainWindowSize(); + + try { + JSONObject jd = new JSONObject(); + JSONObject gui = new JSONObject(); + JSONObject mainWindow = new JSONObject(); + JSONObject location = new JSONObject(); + location.put("x", String.valueOf(l.x)); + location.put("y", String.valueOf(l.y)); + mainWindow.put("location", location); + JSONObject size = new JSONObject(); + size.put("w", String.valueOf(s.width)); + size.put("h", String.valueOf(s.height)); + mainWindow.put("size", size); + mainWindow.put("maximize", String.valueOf(configuration.isMainWindowMaximize())); + gui.put("mainWindow", mainWindow); + jd.put("gui", gui); + JSONArray recentFilePaths = new JSONArray(); + for (File recentFile : configuration.getRecentFiles()) { + recentFilePaths.add(recentFile.toString()); + } + jd.put("recentFilePaths", recentFilePaths); + JSONObject recentDirectories = new JSONObject(); + recentDirectories.put("loadPath", configuration.getRecentLoadDirectory().getAbsolutePath()); + recentDirectories.put("savePath", configuration.getRecentSaveDirectory().getAbsolutePath()); + jd.put("recentDirectories", recentDirectories); + JSONObject preferences = new JSONObject(); + for (Map.Entry preference : configuration.getPreferences().entrySet()) { + preferences.put(preference.getKey(), preference.getValue()); + } + jd.put("preferences", preferences); + + cfg.saveJDConfig(jd); + } catch (Exception e) { + assert ExceptionUtil.printStackTrace(e); + } + } +} diff --git a/src/org/jd/gui/service/actions/CopyQualifiedNameContextualActionsFactory.java b/src/org/jd/gui/service/actions/CopyQualifiedNameContextualActionsFactory.java index 89eb680..2217484 100644 --- a/src/org/jd/gui/service/actions/CopyQualifiedNameContextualActionsFactory.java +++ b/src/org/jd/gui/service/actions/CopyQualifiedNameContextualActionsFactory.java @@ -27,7 +27,7 @@ public Collection make(API api, Container.Entry entry, String fragment) } public static class CopyQualifiedNameAction extends AbstractAction { - protected static final ImageIcon ICON = new ImageIcon(CopyQualifiedNameAction.class.getClassLoader().getResource("org/jd/gui/images/cpyqual_menu.png")); + protected static final ImageIcon ICON = new ImageIcon(CopyQualifiedNameAction.class.getResource("/org/jd/gui/images/cpyqual_menu.png")); protected API api; protected Container.Entry entry; diff --git a/src/org/jd/gui/service/configuration/ConfigurationPersister.java b/src/org/jd/gui/service/configuration/ConfigurationPersister.java deleted file mode 100644 index 40c1dcd..0000000 --- a/src/org/jd/gui/service/configuration/ConfigurationPersister.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2008-2019 Emmanuel Dupuy. - * This project is distributed under the GPLv3 license. - * This is a Copyleft license that gives the user the right to use, - * copy and modify the code freely for non-commercial purposes. - */ - -package org.jd.gui.service.configuration; - -import org.jd.gui.model.configuration.Configuration; - -public interface ConfigurationPersister { - Configuration load(); - - void save(Configuration configuration); -} diff --git a/src/org/jd/gui/service/configuration/ConfigurationPersisterService.java b/src/org/jd/gui/service/configuration/ConfigurationPersisterService.java deleted file mode 100644 index fb4ba71..0000000 --- a/src/org/jd/gui/service/configuration/ConfigurationPersisterService.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2008-2019 Emmanuel Dupuy. - * This project is distributed under the GPLv3 license. - * This is a Copyleft license that gives the user the right to use, - * copy and modify the code freely for non-commercial purposes. - */ - -package org.jd.gui.service.configuration; - -public class ConfigurationPersisterService { - protected static final ConfigurationPersisterService CONFIGURATION_PERSISTER_SERVICE = new ConfigurationPersisterService(); - - protected ConfigurationPersister provider = new ConfigurationXmlPersisterProvider(); - - public static ConfigurationPersisterService getInstance() { return CONFIGURATION_PERSISTER_SERVICE; } - - protected ConfigurationPersisterService() {} - - public ConfigurationPersister get() { - return provider; - } -} diff --git a/src/org/jd/gui/service/configuration/ConfigurationXmlPersisterProvider.java b/src/org/jd/gui/service/configuration/ConfigurationXmlPersisterProvider.java deleted file mode 100644 index 3e9bee2..0000000 --- a/src/org/jd/gui/service/configuration/ConfigurationXmlPersisterProvider.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (c) 2008-2019 Emmanuel Dupuy. - * This project is distributed under the GPLv3 license. - * This is a Copyleft license that gives the user the right to use, - * copy and modify the code freely for non-commercial purposes. - */ - -package org.jd.gui.service.configuration; - -import org.jd.gui.Constants; -import org.jd.gui.model.configuration.Configuration; -import org.jd.gui.service.platform.PlatformService; -import org.jd.gui.util.exception.ExceptionUtil; - -import javax.swing.*; -import javax.xml.stream.*; -import java.awt.*; -import java.io.*; -import java.net.URL; -import java.util.*; -import java.util.List; -import java.util.jar.Manifest; - -public class ConfigurationXmlPersisterProvider implements ConfigurationPersister { - protected static final String ERROR_BACKGROUND_COLOR = "JdGuiPreferences.errorBackgroundColor"; - protected static final String JD_CORE_VERSION = "JdGuiPreferences.jdCoreVersion"; - - protected static final File FILE = getConfigFile(); - - protected static File getConfigFile() { - String configFilePath = System.getProperty(Constants.CONFIG_FILENAME); - - if (configFilePath != null) { - File configFile = new File(configFilePath); - if (configFile.exists()) { - return configFile; - } - } - - if (PlatformService.getInstance().isLinux()) { - // See: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html - String xdgConfigHome = System.getenv("XDG_CONFIG_HOME"); - if (xdgConfigHome != null) { - File xdgConfigHomeFile = new File(xdgConfigHome); - if (xdgConfigHomeFile.exists()) { - return new File(xdgConfigHomeFile, Constants.CONFIG_FILENAME); - } - } - - File userConfigFile = new File(System.getProperty("user.home"), ".config"); - if (userConfigFile.exists()) { - return new File(userConfigFile, Constants.CONFIG_FILENAME); - } - } else if (PlatformService.getInstance().isWindows()) { - // See: http://blogs.msdn.com/b/patricka/archive/2010/03/18/where-should-i-store-my-data-and-configuration-files-if-i-target-multiple-os-versions.aspx - String roamingConfigHome = System.getenv("APPDATA"); - if (roamingConfigHome != null) { - File roamingConfigHomeFile = new File(roamingConfigHome); - if (roamingConfigHomeFile.exists()) { - return new File(roamingConfigHomeFile, Constants.CONFIG_FILENAME); - } - } - } - - return new File(Constants.CONFIG_FILENAME); - } - - @Override - public Configuration load() { - // Default values - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - - int w = (screenSize.width>Constants.DEFAULT_WIDTH) ? Constants.DEFAULT_WIDTH : screenSize.width; - int h = (screenSize.height>Constants.DEFAULT_HEIGHT) ? Constants.DEFAULT_HEIGHT : screenSize.height; - int x = (screenSize.width-w)/2; - int y = (screenSize.height-h)/2; - - Configuration config = new Configuration(); - config.setMainWindowLocation(new Point(x, y)); - config.setMainWindowSize(new Dimension(w, h)); - config.setMainWindowMaximize(false); - - String defaultLaf = System.getProperty("swing.defaultlaf"); - - config.setLookAndFeel((defaultLaf != null) ? defaultLaf : UIManager.getSystemLookAndFeelClassName()); - - File recentSaveDirectory = new File(System.getProperty("user.dir")); - - config.setRecentLoadDirectory(recentSaveDirectory); - config.setRecentSaveDirectory(recentSaveDirectory); - - if (FILE.exists()) { - try (FileInputStream fis = new FileInputStream(FILE)) { - XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(fis); - - // Load values - String name = ""; - Stack names = new Stack<>(); - List recentFiles = new ArrayList<>(); - boolean maximize = false; - Map preferences = config.getPreferences(); - - while (reader.hasNext()) { - switch (reader.next()) { - case XMLStreamConstants.START_ELEMENT: - names.push(name); - name += '/' + reader.getLocalName(); - switch (name) { - case "/configuration/gui/mainWindow/location": - x = Integer.parseInt(reader.getAttributeValue(null, "x")); - y = Integer.parseInt(reader.getAttributeValue(null, "y")); - break; - case "/configuration/gui/mainWindow/size": - w = Integer.parseInt(reader.getAttributeValue(null, "w")); - h = Integer.parseInt(reader.getAttributeValue(null, "h")); - break; - } - break; - case XMLStreamConstants.END_ELEMENT: - name = names.pop(); - break; - case XMLStreamConstants.CHARACTERS: - switch (name) { - case "/configuration/recentFilePaths/filePath": - File file = new File(reader.getText().trim()); - if (file.exists()) { - recentFiles.add(file); - } - break; - case "/configuration/recentDirectories/loadPath": - file = new File(reader.getText().trim()); - if (file.exists()) { - config.setRecentLoadDirectory(file); - } - break; - case "/configuration/recentDirectories/savePath": - file = new File(reader.getText().trim()); - if (file.exists()) { - config.setRecentSaveDirectory(file); - } - break; - case "/configuration/gui/lookAndFeel": - config.setLookAndFeel(reader.getText().trim()); - break; - case "/configuration/gui/mainWindow/maximize": - maximize = Boolean.parseBoolean(reader.getText().trim()); - break; - default: - if (name.startsWith("/configuration/preferences/")) { - String key = name.substring("/configuration/preferences/".length()); - preferences.put(key, reader.getText().trim()); - } - break; - } - break; - } - } - - if (recentFiles.size() > Constants.MAX_RECENT_FILES) { - // Truncate - recentFiles = recentFiles.subList(0, Constants.MAX_RECENT_FILES); - } - config.setRecentFiles(recentFiles); - - if ((x >= 0) && (y >= 0) && (x + w < screenSize.width) && (y + h < screenSize.height)) { - // Update preferences - config.setMainWindowLocation(new Point(x, y)); - config.setMainWindowSize(new Dimension(w, h)); - config.setMainWindowMaximize(maximize); - } - - reader.close(); - } catch (Exception e) { - assert ExceptionUtil.printStackTrace(e); - } - } - - if (! config.getPreferences().containsKey(ERROR_BACKGROUND_COLOR)) { - config.getPreferences().put(ERROR_BACKGROUND_COLOR, "0xFF6666"); - } - - config.getPreferences().put(JD_CORE_VERSION, getJdCoreVersion()); - - return config; - } - - protected String getJdCoreVersion() { - try { - Enumeration enumeration = ConfigurationXmlPersisterProvider.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); - - while (enumeration.hasMoreElements()) { - try (InputStream is = enumeration.nextElement().openStream()) { - String attribute = new Manifest(is).getMainAttributes().getValue("JD-Core-Version"); - if (attribute != null) { - return attribute; - } - } - } - } catch (IOException e) { - assert ExceptionUtil.printStackTrace(e); - } - - return "SNAPSHOT"; - } - - @Override - public void save(Configuration configuration) { - Point l = configuration.getMainWindowLocation(); - Dimension s = configuration.getMainWindowSize(); - - try (FileOutputStream fos = new FileOutputStream(FILE)) { - XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fos); - - // Save values - writer.writeStartDocument(); - writer.writeCharacters("\n"); - writer.writeStartElement("configuration"); - writer.writeCharacters("\n\t"); - - writer.writeStartElement("gui"); - writer.writeCharacters("\n\t\t"); - writer.writeStartElement("mainWindow"); - writer.writeCharacters("\n\t\t\t"); - writer.writeStartElement("location"); - writer.writeAttribute("x", String.valueOf(l.x)); - writer.writeAttribute("y", String.valueOf(l.y)); - writer.writeEndElement(); - writer.writeCharacters("\n\t\t\t"); - writer.writeStartElement("size"); - writer.writeAttribute("w", String.valueOf(s.width)); - writer.writeAttribute("h", String.valueOf(s.height)); - writer.writeEndElement(); - writer.writeCharacters("\n\t\t\t"); - writer.writeStartElement("maximize"); - writer.writeCharacters(String.valueOf(configuration.isMainWindowMaximize())); - writer.writeEndElement(); - writer.writeCharacters("\n\t\t"); - writer.writeEndElement(); - writer.writeCharacters("\n\t\t"); - writer.writeStartElement("lookAndFeel"); - writer.writeCharacters(configuration.getLookAndFeel()); - writer.writeEndElement(); - writer.writeCharacters("\n\t"); - writer.writeEndElement(); - writer.writeCharacters("\n\t"); - - writer.writeStartElement("recentFilePaths"); - - for (File recentFile : configuration.getRecentFiles()) { - writer.writeCharacters("\n\t\t"); - writer.writeStartElement("filePath"); - writer.writeCharacters(recentFile.getAbsolutePath()); - writer.writeEndElement(); - } - - writer.writeCharacters("\n\t"); - writer.writeEndElement(); - writer.writeCharacters("\n\t"); - - writer.writeStartElement("recentDirectories"); - writer.writeCharacters("\n\t\t"); - writer.writeStartElement("loadPath"); - writer.writeCharacters(configuration.getRecentLoadDirectory().getAbsolutePath()); - writer.writeEndElement(); - writer.writeCharacters("\n\t\t"); - writer.writeStartElement("savePath"); - writer.writeCharacters(configuration.getRecentSaveDirectory().getAbsolutePath()); - writer.writeEndElement(); - writer.writeCharacters("\n\t"); - writer.writeEndElement(); - writer.writeCharacters("\n\t"); - - writer.writeStartElement("preferences"); - - for (Map.Entry preference : configuration.getPreferences().entrySet()) { - writer.writeCharacters("\n\t\t"); - writer.writeStartElement(preference.getKey()); - writer.writeCharacters(preference.getValue()); - writer.writeEndElement(); - } - - writer.writeCharacters("\n\t"); - writer.writeEndElement(); - writer.writeCharacters("\n"); - - writer.writeEndElement(); - writer.writeEndDocument(); - writer.close(); - } catch (Exception e) { - assert ExceptionUtil.printStackTrace(e); - } - } -} diff --git a/src/org/jd/gui/service/treenode/DtdFileTreeNodeFactoryProvider.java b/src/org/jd/gui/service/treenode/DtdFileTreeNodeFactoryProvider.java index db19551..b71dda9 100644 --- a/src/org/jd/gui/service/treenode/DtdFileTreeNodeFactoryProvider.java +++ b/src/org/jd/gui/service/treenode/DtdFileTreeNodeFactoryProvider.java @@ -19,7 +19,7 @@ import java.io.File; public class DtdFileTreeNodeFactoryProvider extends TextFileTreeNodeFactoryProvider { - protected static final ImageIcon ICON = new ImageIcon(DtdFileTreeNodeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/dtd_obj.gif")); + protected static final ImageIcon ICON = new ImageIcon(DtdFileTreeNodeFactoryProvider.class.getResource("/org/jd/gui/images/dtd_obj.gif")); @Override public String[] getSelectors() { return appendSelectors("*:file:*.dtd"); } diff --git a/src/org/jd/gui/service/type/AbstractTypeFactoryProvider.java b/src/org/jd/gui/service/type/AbstractTypeFactoryProvider.java index 2847a06..08a73c7 100644 --- a/src/org/jd/gui/service/type/AbstractTypeFactoryProvider.java +++ b/src/org/jd/gui/service/type/AbstractTypeFactoryProvider.java @@ -346,32 +346,32 @@ protected static ImageIcon[] mergeIcons(ImageIcon[] backgrounds, ImageIcon overl return result; } - protected static final ImageIcon ABSTRACT_OVERLAY_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/abstract_ovr.png")); - protected static final ImageIcon FINAL_OVERLAY_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/final_ovr.png")); - protected static final ImageIcon STATIC_OVERLAY_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/static_ovr.png")); - - protected static final ImageIcon CLASS_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/class_default_obj.png")); - protected static final ImageIcon PUBLIC_CLASS_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/class_obj.png")); - protected static final ImageIcon PROTECTED_CLASS_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/class_protected_obj.png")); - protected static final ImageIcon PRIVATE_CLASS_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/class_private_obj.png")); - - protected static final ImageIcon INTERFACE_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/int_default_obj.png")); - protected static final ImageIcon PUBLIC_INTERFACE_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/int_obj.png")); - protected static final ImageIcon PROTECTED_INTERFACE_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/int_protected_obj.png")); - protected static final ImageIcon PRIVATE_INTERFACE_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/int_private_obj.png")); - - protected static final ImageIcon ANNOTATION_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/annotation_obj.png")); - protected static final ImageIcon ENUM_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/enum_obj.png")); - - protected static final ImageIcon FIELD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/field_default_obj.png")); - protected static final ImageIcon PUBLIC_FIELD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/field_public_obj.png")); - protected static final ImageIcon PROTECTED_FIELD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/field_protected_obj.png")); - protected static final ImageIcon PRIVATE_FIELD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/field_private_obj.png")); - - protected static final ImageIcon METHOD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/methdef_obj.png")); - protected static final ImageIcon PUBLIC_METHOD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/methpub_obj.png")); - protected static final ImageIcon PROTECTED_METHOD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/methpro_obj.png")); - protected static final ImageIcon PRIVATE_METHOD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/methpri_obj.png")); + protected static final ImageIcon ABSTRACT_OVERLAY_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/abstract_ovr.png")); + protected static final ImageIcon FINAL_OVERLAY_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/final_ovr.png")); + protected static final ImageIcon STATIC_OVERLAY_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/static_ovr.png")); + + protected static final ImageIcon CLASS_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/class_default_obj.png")); + protected static final ImageIcon PUBLIC_CLASS_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/class_obj.png")); + protected static final ImageIcon PROTECTED_CLASS_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/class_protected_obj.png")); + protected static final ImageIcon PRIVATE_CLASS_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/class_private_obj.png")); + + protected static final ImageIcon INTERFACE_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/int_default_obj.png")); + protected static final ImageIcon PUBLIC_INTERFACE_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/int_obj.png")); + protected static final ImageIcon PROTECTED_INTERFACE_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/int_protected_obj.png")); + protected static final ImageIcon PRIVATE_INTERFACE_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/int_private_obj.png")); + + protected static final ImageIcon ANNOTATION_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/annotation_obj.png")); + protected static final ImageIcon ENUM_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/enum_obj.png")); + + protected static final ImageIcon FIELD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/field_default_obj.png")); + protected static final ImageIcon PUBLIC_FIELD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/field_public_obj.png")); + protected static final ImageIcon PROTECTED_FIELD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/field_protected_obj.png")); + protected static final ImageIcon PRIVATE_FIELD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/field_private_obj.png")); + + protected static final ImageIcon METHOD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/methdef_obj.png")); + protected static final ImageIcon PUBLIC_METHOD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/methpub_obj.png")); + protected static final ImageIcon PROTECTED_METHOD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/methpro_obj.png")); + protected static final ImageIcon PRIVATE_METHOD_ICON = new ImageIcon(ClassFileTypeFactoryProvider.class.getResource("/org/jd/gui/images/methpri_obj.png")); // Default icon set protected static final ImageIcon[] DEFAULT_CLASS_ICONS = { diff --git a/src/org/jd/gui/view/AboutView.java b/src/org/jd/gui/view/AboutView.java index b7792c3..23f7786 100644 --- a/src/org/jd/gui/view/AboutView.java +++ b/src/org/jd/gui/view/AboutView.java @@ -43,7 +43,7 @@ public AboutView(JFrame mainFrame) { subpanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); subpanel.setBackground(Color.WHITE); subpanel.setLayout(new BorderLayout()); - JLabel logo = new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().getImage("resources/org/jd/gui/images/jd_icon_64.png"))); + JLabel logo = new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().getImage(AboutView.class.getResource("/org/jd/gui/images/jd_icon_64.png")))); logo.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); subpanel.add(logo, BorderLayout.WEST); Box subvbox = Box.createVerticalBox(); diff --git a/src/org/jd/gui/view/MainView.java b/src/org/jd/gui/view/MainView.java index dcb5704..2908eb9 100644 --- a/src/org/jd/gui/view/MainView.java +++ b/src/org/jd/gui/view/MainView.java @@ -7,28 +7,22 @@ package org.jd.gui.view; -import org.jd.gui.Constants; -import org.jd.gui.api.API; -import org.jd.gui.api.feature.*; -import org.jd.gui.model.configuration.Configuration; -import org.jd.gui.model.history.History; -import org.jd.gui.service.platform.PlatformService; -import org.jd.gui.util.exception.ExceptionUtil; -import org.jd.gui.view.component.IconButton; -import org.jd.gui.view.component.panel.MainTabbedPanel; - -import javax.imageio.ImageIO; -import javax.swing.*; -import javax.swing.border.Border; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import java.awt.*; +import static org.jd.gui.util.swing.SwingUtil.invokeLater; +import static org.jd.gui.util.swing.SwingUtil.newAction; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Desktop; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Toolkit; import java.awt.event.ActionListener; import java.awt.event.InputEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.io.File; import java.io.IOException; import java.net.URI; @@ -37,13 +31,63 @@ import java.util.Map; import java.util.function.Consumer; -import static org.jd.gui.util.swing.SwingUtil.*; +import javax.imageio.ImageIO; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.DefaultComboBoxModel; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.JToolBar; +import javax.swing.KeyStroke; +import javax.swing.border.Border; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; + +import org.jd.gui.Constants; +import org.jd.gui.api.API; +import org.jd.gui.api.feature.ContentCopyable; +import org.jd.gui.api.feature.ContentSavable; +import org.jd.gui.api.feature.ContentSearchable; +import org.jd.gui.api.feature.ContentSelectable; +import org.jd.gui.api.feature.FocusedTypeGettable; +import org.jd.gui.api.feature.LineNumberNavigable; +import org.jd.gui.api.feature.PageChangeListener; +import org.jd.gui.api.feature.PageClosable; +import org.jd.gui.api.feature.PreferencesChangeListener; +import org.jd.gui.api.feature.SourcesSavable; +import org.jd.gui.api.feature.UriGettable; +import org.jd.gui.api.feature.UriOpenable; +import org.jd.gui.model.configuration.Configuration; +import org.jd.gui.model.history.History; +import org.jd.gui.service.platform.PlatformService; +import org.jd.gui.util.exception.ExceptionUtil; +import org.jd.gui.view.component.IconButton; +import org.jd.gui.view.component.panel.MainTabbedPanel; @SuppressWarnings({"hiding", "unchecked", "rawtypes"}) public class MainView implements UriOpenable, PreferencesChangeListener { - protected History history; + public static final int EXTERNAL = 0; + public static final int INTERNAL = 1; + + protected History history; protected Consumer openFilesCallback; - protected JFrame mainFrame; + protected Component mainFrame; protected JMenu recentFiles = new JMenu("Recent Files"); protected Action closeAction; protected Action openTypeAction; @@ -57,7 +101,7 @@ public class MainView implements UriOpenable protected Color findErrorBackgroundColor; public MainView( - Configuration configuration, API api, History history, + int boundedness, Configuration configuration, API api, History history, ActionListener openActionListener, ActionListener closeActionListener, ActionListener saveActionListener, @@ -84,19 +128,36 @@ public MainView( ActionListener aboutActionListener, Runnable panelClosedCallback, Consumer currentPageChangedCallback, - Consumer openFilesCallback) { + Consumer openFilesCallback, + Consumer mainPanelCloseEvent, + Runnable windowCloseAction) { this.history = history; this.openFilesCallback = openFilesCallback; // Build GUI invokeLater(() -> { - try { - mainFrame = new JFrame("Java Decompiler"); - mainFrame.setIconImages(Arrays.asList(ImageIO.read(MainView.class.getResource("/org/jd/gui/images/jd_icon_32.png")), ImageIO.read(MainView.class.getResource("/org/jd/gui/images/jd_icon_64.png")), ImageIO.read(MainView.class.getResource("/org/jd/gui/images/jd_icon_128.png")))); - mainFrame.setMinimumSize(new Dimension(Constants.MINIMAL_WIDTH, Constants.MINIMAL_HEIGHT)); - mainFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - } catch (IOException e1) { - e1.printStackTrace(); - } + if(boundedness == EXTERNAL) { + try { + mainFrame = new JFrame("Java Decompiler"); + ((JFrame) mainFrame).setIconImages(Arrays.asList(ImageIO.read(MainView.class.getResource("/org/jd/gui/images/jd_icon_32.png")), ImageIO.read(MainView.class.getResource("/org/jd/gui/images/jd_icon_64.png")), ImageIO.read(MainView.class.getResource("/org/jd/gui/images/jd_icon_128.png")))); + ((JFrame) mainFrame).addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + windowCloseAction.run(); + } + }); + } catch (IOException e1) { + e1.printStackTrace(); + } + } else if(boundedness == INTERNAL) { + mainFrame = new JInternalFrame("Java Decompiler"); + ((JInternalFrame) mainFrame).setFrameIcon(new ImageIcon(MainView.class.getResource("/org/jd/gui/images/jd_icon_32.png"))); + ((JInternalFrame) mainFrame).setClosable(true); + ((JInternalFrame) mainFrame).addInternalFrameListener(new InternalFrameAdapter() { + public void internalFrameClosing(InternalFrameEvent e) { + windowCloseAction.run(); + } + }); + } + mainFrame.setMinimumSize(new Dimension(Constants.MINIMAL_WIDTH, Constants.MINIMAL_HEIGHT)); // Find panel // Action findNextAction = newAction("Next", new ImageIcon(MainView.class.getResource("/org/jd/gui/images/next_nav.png")), true, findNextActionListener); @@ -249,7 +310,10 @@ public void keyReleased(KeyEvent e) { menu.addSeparator(); menu.add(aboutAction).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); } - mainFrame.setJMenuBar(menuBar); + if(boundedness == EXTERNAL) + ((JFrame) mainFrame).setJMenuBar(menuBar); + else if(boundedness == INTERNAL) + ((JInternalFrame) mainFrame).setJMenuBar(menuBar); // Icon bar // JPanel panel = new JPanel(); @@ -266,7 +330,7 @@ public void keyReleased(KeyEvent e) { toolBar.add(new IconButton(forwardAction)); panel.add(toolBar, BorderLayout.PAGE_START); - mainTabbedPanel = new MainTabbedPanel(api); + mainTabbedPanel = new MainTabbedPanel(api, mainPanelCloseEvent); mainTabbedPanel.getPageChangedListeners().add(new PageChangeListener() { protected JComponent currentPage = null; @@ -279,7 +343,10 @@ public void keyReleased(KeyEvent e) { invokeLater(() -> { if (page == null) { // Update title - mainFrame.setTitle("Java Decompiler"); + if(boundedness == EXTERNAL) + ((JFrame) mainFrame).setTitle("Java Decompiler"); + else if(boundedness == INTERNAL) + ((JInternalFrame) mainFrame).setTitle("Java Decompiler"); // Update menu saveAction.setEnabled(false); copyAction.setEnabled(false); @@ -293,7 +360,10 @@ public void keyReleased(KeyEvent e) { String path = page.getUri().getPath(); int index = path.lastIndexOf('/'); String name = (index == -1) ? path : path.substring(index + 1); - mainFrame.setTitle((name != null) ? name + " - Java Decompiler" : "Java Decompiler"); + if(boundedness == EXTERNAL) + ((JFrame) mainFrame).setTitle((name != null) ? name + " - Java Decompiler" : "Java Decompiler"); + else if(boundedness == INTERNAL) + ((JInternalFrame) mainFrame).setTitle((name != null) ? name + " - Java Decompiler" : "Java Decompiler"); // Update history history.add(page.getUri()); // Update history actions @@ -338,7 +408,10 @@ public void stateChanged(ChangeEvent e) { panel.add(mainTabbedPanel, BorderLayout.CENTER); panel.add(findPanel, BorderLayout.PAGE_END); - mainFrame.add(panel); + if(boundedness == EXTERNAL) + ((JFrame) mainFrame).add(panel); + else if(boundedness == INTERNAL) + ((JInternalFrame) mainFrame).add(panel); }); } @@ -347,12 +420,13 @@ public void show(Point location, Dimension size, boolean maximize) { // Set position, resize and show mainFrame.setLocation(location); mainFrame.setSize(size); - mainFrame.setExtendedState(maximize ? JFrame.MAXIMIZED_BOTH : 0); + if(mainFrame instanceof JFrame) + ((JFrame) mainFrame).setExtendedState(maximize ? JFrame.MAXIMIZED_BOTH : 0); mainFrame.setVisible(true); }); } - public JFrame getMainFrame() { + public Component getMainFrame() { return mainFrame; } diff --git a/src/org/jd/gui/view/OpenTypeHierarchyView.java b/src/org/jd/gui/view/OpenTypeHierarchyView.java index 650773d..74e5722 100644 --- a/src/org/jd/gui/view/OpenTypeHierarchyView.java +++ b/src/org/jd/gui/view/OpenTypeHierarchyView.java @@ -31,8 +31,8 @@ import java.util.concurrent.Future; public class OpenTypeHierarchyView { - protected static final ImageIcon ROOT_CLASS_ICON = new ImageIcon("resources/org/jd/gui/images/generate_class.png"); - protected static final ImageIcon ROOT_INTERFACE_ICON = new ImageIcon("resources/org/jd/gui/images/generate_int.png"); + protected static final ImageIcon ROOT_CLASS_ICON = new ImageIcon(OpenTypeHierarchyView.class.getResource("/org/jd/gui/images/generate_class.png")); + protected static final ImageIcon ROOT_INTERFACE_ICON = new ImageIcon(OpenTypeHierarchyView.class.getResource("/org/jd/gui/images/generate_int.png")); protected static final TreeNodeComparator TREE_NODE_COMPARATOR = new TreeNodeComparator(); diff --git a/src/org/jd/gui/view/component/AbstractTextPage.java b/src/org/jd/gui/view/component/AbstractTextPage.java index 88cc749..2580857 100644 --- a/src/org/jd/gui/view/component/AbstractTextPage.java +++ b/src/org/jd/gui/view/component/AbstractTextPage.java @@ -33,8 +33,8 @@ public class AbstractTextPage extends JPanel implements LineNumberNavigable, ContentSearchable, UriOpenable, PreferencesChangeListener { protected static final String FONT_SIZE_KEY = "ViewerPreferences.fontSize"; - protected static final ImageIcon COLLAPSED_ICON = new ImageIcon(AbstractTextPage.class.getClassLoader().getResource("org/jd/gui/images/plus.png")); - protected static final ImageIcon EXPANDED_ICON = new ImageIcon(AbstractTextPage.class.getClassLoader().getResource("org/jd/gui/images/minus.png")); + protected static final ImageIcon COLLAPSED_ICON = new ImageIcon(AbstractTextPage.class.getResource("/org/jd/gui/images/plus.png")); + protected static final ImageIcon EXPANDED_ICON = new ImageIcon(AbstractTextPage.class.getResource("/org/jd/gui/images/minus.png")); protected static final Color DOUBLE_CLICK_HIGHLIGHT_COLOR = new Color(0x66ff66); protected static final Color SEARCH_HIGHLIGHT_COLOR = new Color(0xffff66); diff --git a/src/org/jd/gui/view/component/panel/MainTabbedPanel.java b/src/org/jd/gui/view/component/panel/MainTabbedPanel.java index 4305e2e..2c90dde 100644 --- a/src/org/jd/gui/view/component/panel/MainTabbedPanel.java +++ b/src/org/jd/gui/view/component/panel/MainTabbedPanel.java @@ -17,15 +17,18 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.Consumer; @SuppressWarnings("unchecked") public class MainTabbedPanel extends TabbedPanel implements UriOpenable, PreferencesChangeListener, PageChangeListener { protected ArrayList pageChangedListeners = new ArrayList<>(); // Flag to prevent the event cascades protected boolean pageChangedListenersEnabled = true; + protected Consumer panelCloseEvent; - public MainTabbedPanel(API api) { + public MainTabbedPanel(API api, Consumer panelCloseEvent) { super(api); + this.panelCloseEvent = panelCloseEvent; } @Override @@ -135,6 +138,12 @@ public List getPages() { public ArrayList getPageChangedListeners() { return pageChangedListeners; } + + @Override + public void removeComponent(Component component) { + panelCloseEvent.accept(component); + super.removeComponent(component); + } // --- URIOpener --- // @Override diff --git a/src/org/jd/gui/view/component/panel/TabbedPanel.java b/src/org/jd/gui/view/component/panel/TabbedPanel.java index bb90c19..263afe0 100644 --- a/src/org/jd/gui/view/component/panel/TabbedPanel.java +++ b/src/org/jd/gui/view/component/panel/TabbedPanel.java @@ -23,8 +23,8 @@ import java.util.Map; public class TabbedPanel extends JPanel implements PreferencesChangeListener { - protected static final ImageIcon CLOSE_ICON = new ImageIcon("resources/org/jd/gui/images/close.gif"); - protected static final ImageIcon CLOSE_ACTIVE_ICON = new ImageIcon("resources/org/jd/gui/images/close_active.gif"); + protected static final ImageIcon CLOSE_ICON = new ImageIcon(TabbedPanel.class.getResource("/org/jd/gui/images/close.gif")); + protected static final ImageIcon CLOSE_ACTIVE_ICON = new ImageIcon(TabbedPanel.class.getResource("/org/jd/gui/images/close_active.gif")); protected static final String TAB_LAYOUT = "UITabsPreferencesProvider.singleLineTabs";