├── .gitignore ├── .hgignore ├── LICENSE-2.0.txt ├── README.MD ├── build.xml ├── manifest.mf ├── nbproject ├── build-impl.xml ├── genfiles.properties ├── platform.properties ├── project.properties └── project.xml └── src ├── de └── markiewb │ └── netbeans │ └── plugin │ └── showpathintitle │ ├── Bundle.properties │ ├── Installer.java │ ├── PathUtil.java │ ├── ProjectGroupUtil.java │ ├── ShowPathInTitleOptions.java │ ├── StringUtils.java │ ├── TitleBuilder.java │ └── options │ ├── Bundle.properties │ ├── ShowpathintitleOptionsPanelController.java │ ├── ShowpathintitlePanel.form │ └── ShowpathintitlePanel.java └── test └── resources └── example.png /.gitignore: -------------------------------------------------------------------------------- 1 | /nbproject/private/ 2 | /build/ -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | \.orig$ 2 | \.orig\..*$ 3 | \.chg\..*$ 4 | \.rej$ 5 | \.conflict\~$ 6 | -------------------------------------------------------------------------------- /LICENSE-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 |
2 |

Looking for maintainers, who want to take over the development!

3 |
4 | 5 | show-path-in-title-netbeans-module 6 | ================================== 7 | 8 | It shows the current project group, project name, path of the current file/node/editor and IDE version in the titlebar of NetBeans. 9 | It can be configured using an option panel. 10 | 11 | See http://plugins.netbeans.org/plugin/42000/show-path-in-title 12 | This implements the feature request from http://netbeans.org/bugzilla/show_bug.cgi?id=159722 13 | 14 | 15 | 16 |

17 | Updates in 3.0.0 18 |

21 | 22 |

23 | Updates in 2.2.0 24 |

28 | 29 | Updates in 2.1.0 30 | 36 | 37 | Updates in 2.0.1 38 | 42 | 43 | Updates in 1.3.1 44 | 48 | 49 | Updates in 1.3.0 50 | 54 | 55 | Updates in 1.2.1 56 | 59 | 60 | Updates in 1.2 61 | 66 |

67 |

Provide defects, request for enhancements and feedback at https://github.com/markiewb/show-path-in-title-netbeans-module/issues

68 |

Compatible to >=NB 8.0

69 |

Legal disclaimer: Code is licensed under Apache 2.0.

70 |

71 | 72 |

73 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Builds, tests, and runs the project de.markiewb.netbeans.plugin.showpathintitle. 7 | 8 | 9 | -------------------------------------------------------------------------------- /manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | OpenIDE-Module: de.markiewb.netbeans.plugin.showpathintitle 3 | OpenIDE-Module-Install: de/markiewb/netbeans/plugin/showpathintitle/Installer.class 4 | OpenIDE-Module-Localizing-Bundle: de/markiewb/netbeans/plugin/showpathintitle/Bundle.properties 5 | OpenIDE-Module-Specification-Version: 3.0.0 6 | 7 | -------------------------------------------------------------------------------- /nbproject/build-impl.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=92838d08 2 | build.xml.script.CRC32=1a0d03e7 3 | build.xml.stylesheet.CRC32=15ca8a54@2.75.1 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=92838d08 7 | nbproject/build-impl.xml.script.CRC32=68dab639 8 | nbproject/build-impl.xml.stylesheet.CRC32=49aa68b0@2.75.1 9 | -------------------------------------------------------------------------------- /nbproject/platform.properties: -------------------------------------------------------------------------------- 1 | cluster.path=\ 2 | ${nbplatform.active.dir}/apisupport:\ 3 | ${nbplatform.active.dir}/harness:\ 4 | ${nbplatform.active.dir}/ide:\ 5 | ${nbplatform.active.dir}/java:\ 6 | ${nbplatform.active.dir}/java:\ 7 | ${nbplatform.active.dir}/nb:\ 8 | ${nbplatform.active.dir}/platform:\ 9 | ${nbplatform.active.dir}/profiler:\ 10 | ${nbplatform.active.dir}/websvccommon 11 | nbjdk.active=default 12 | nbplatform.active=default 13 | -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | javac.source=1.6 2 | javac.compilerargs=-Xlint -Xlint:-serial 3 | license.file=LICENSE-2.0.txt 4 | nbm.homepage=http://code.google.com/p/show-path-in-title-netbeans-module/ 5 | nbm.module.author=Benno Markiewicz / markiewb@netbeans.org 6 | keystore=nbproject/private/keystore 7 | nbm_alias=myself 8 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.apisupport.project 4 | 5 | 6 | de.markiewb.netbeans.plugin.showpathintitle 7 | 8 | 9 | 10 | org.netbeans.modules.editor.lib2 11 | 12 | 13 | 14 | 1 15 | 1.28.1.2 16 | 17 | 18 | 19 | org.netbeans.modules.options.api 20 | 21 | 22 | 23 | 1 24 | 1.18.1 25 | 26 | 27 | 28 | org.netbeans.modules.projectapi 29 | 30 | 31 | 32 | 1 33 | 1.31.1 34 | 35 | 36 | 37 | org.openide.awt 38 | 39 | 40 | 41 | 7.23.1 42 | 43 | 44 | 45 | org.openide.filesystems 46 | 47 | 48 | 49 | 7.38.2 50 | 51 | 52 | 53 | org.openide.loaders 54 | 55 | 56 | 57 | 7.16.1 58 | 59 | 60 | 61 | org.openide.modules 62 | 63 | 64 | 65 | 7.17.1 66 | 67 | 68 | 69 | org.openide.nodes 70 | 71 | 72 | 73 | 7.16.1 74 | 75 | 76 | 77 | org.openide.text 78 | 79 | 80 | 81 | 6.30.1 82 | 83 | 84 | 85 | org.openide.util 86 | 87 | 88 | 89 | 8.6.1 90 | 91 | 92 | 93 | org.openide.util.lookup 94 | 95 | 96 | 97 | 8.3.1 98 | 99 | 100 | 101 | org.openide.util.ui 102 | 103 | 104 | 105 | 9.11.1 106 | 107 | 108 | 109 | org.openide.windows 110 | 111 | 112 | 113 | 6.33.1 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /src/de/markiewb/netbeans/plugin/showpathintitle/Bundle.properties: -------------------------------------------------------------------------------- 1 | OpenIDE-Module-Display-Category=Editing 2 | OpenIDE-Module-Long-Description=\ 3 | It shows the current project group, project name, path of the current file/node/editor and IDE version in the titlebar of NetBeans.\n\ 4 | It can be configured using an option panel.\n\n\ 5 | See http://plugins.netbeans.org/plugin/42000/show-path-in-title\nThis implements the feature request from http://netbeans.org/bugzilla/show_bug.cgi?\ 7 | id=159722\n\n\n\n\n

\nUpdates in 3.0.0\n

\n\n

\n

Provide defects, request for enhancements and feedback at https://github.com/markiewb/show-path-in-title-netbeans-module/issues

\n

Compatible to >=NB 8.0

\n

Legal disclaimer: Code is licensed under Apache 2.0.\ 8 |

\n

\n\n

10 | OpenIDE-Module-Name=Show path in titlebar 11 | OpenIDE-Module-Short-Description=It shows the current project group, project name, path of the current file/node/editor and IDE version in the titlebar of NetBeans. 12 | -------------------------------------------------------------------------------- /src/de/markiewb/netbeans/plugin/showpathintitle/Installer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 markiewb 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package de.markiewb.netbeans.plugin.showpathintitle; 17 | 18 | import static de.markiewb.netbeans.plugin.showpathintitle.StringUtils.defaultIfEmpty; 19 | import static org.openide.windows.TopComponent.Registry.*; 20 | 21 | import java.beans.PropertyChangeEvent; 22 | import java.beans.PropertyChangeListener; 23 | import java.util.prefs.PreferenceChangeEvent; 24 | import java.util.prefs.PreferenceChangeListener; 25 | import java.util.prefs.Preferences; 26 | 27 | import org.openide.modules.ModuleInstall; 28 | import org.openide.nodes.Node; 29 | import org.openide.util.NbPreferences; 30 | import org.openide.windows.TopComponent; 31 | import org.openide.windows.WindowManager; 32 | 33 | /** 34 | * Shows the path of the current editor or node in the title of the main window. 35 | * Additionally it shows . It can be configured 37 | * using {@link ShowPathInTitleOptions). 38 | * 39 | * https://github.com/markiewb/show-path-in-title-netbeans-module 40 | * 41 | * @author markiewb 42 | */ 43 | public class Installer extends ModuleInstall implements PreferenceChangeListener, PropertyChangeListener { 44 | 45 | private static final long serialVersionUID = -2422104143131463778L; 46 | private Preferences pref = NbPreferences.forModule(ShowPathInTitleOptions.class); 47 | private String previousTitle; 48 | 49 | private void updateTitle(final TopComponent editor, final Node[] selectedNodes) { 50 | // on change set the title 51 | WindowManager.getDefault().invokeWhenUIReady(new Runnable() { 52 | @Override 53 | public void run() { 54 | ShowPathInTitleOptions options = ShowPathInTitleOptions.loadFrom(pref); 55 | TitleBuilder path = new PathUtil().getPath(options, editor, selectedNodes); 56 | WindowManager.getDefault().getMainWindow().setTitle(defaultIfEmpty(path.build(options), previousTitle)); 57 | } 58 | }); 59 | } 60 | 61 | @Override 62 | public void uninstalled() { 63 | //remove the listeners 64 | TopComponent.getRegistry().removePropertyChangeListener(this); 65 | pref.removePreferenceChangeListener(this); 66 | //reset to original title 67 | WindowManager.getDefault().getMainWindow().setTitle(previousTitle); 68 | } 69 | 70 | @Override 71 | public void restored() { 72 | final PropertyChangeListener listenerA = this; 73 | final PreferenceChangeListener listenerB = this; 74 | WindowManager.getDefault().invokeWhenUIReady(new Runnable() { 75 | @Override 76 | public void run() { 77 | // code to be invoked when system UI is ready 78 | 79 | //backup original title 80 | previousTitle = WindowManager.getDefault().getMainWindow().getTitle(); 81 | 82 | TopComponent.getRegistry().addPropertyChangeListener(listenerA); 83 | pref.addPreferenceChangeListener(listenerB); 84 | 85 | // initial setting of title - emulate configuration change 86 | preferenceChange(null); 87 | } 88 | }); 89 | } 90 | 91 | @Override 92 | public void preferenceChange(PreferenceChangeEvent evt) { 93 | TopComponent.Registry registry = TopComponent.getRegistry(); 94 | updateTitle(registry.getActivated(), registry.getActivatedNodes()); 95 | } 96 | 97 | @Override 98 | public void propertyChange(PropertyChangeEvent evt) { 99 | String propertyName = evt.getPropertyName(); 100 | Object newValue = evt.getNewValue(); 101 | if (evt.getSource() instanceof TopComponent.Registry) { 102 | TopComponent.Registry registry = (TopComponent.Registry) evt.getSource(); 103 | 104 | ShowPathInTitleOptions options = ShowPathInTitleOptions.loadFrom(pref); 105 | if (options.useEditorAsReference && PROP_ACTIVATED.equals(propertyName)) { 106 | updateTitle((TopComponent) newValue, registry.getActivatedNodes()); 107 | } else if (options.useNodeAsReference && PROP_ACTIVATED_NODES.equals(propertyName)) { 108 | updateTitle(registry.getActivated(), (org.openide.nodes.Node[]) newValue); 109 | } 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/de/markiewb/netbeans/plugin/showpathintitle/PathUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2016 markiewb 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package de.markiewb.netbeans.plugin.showpathintitle; 17 | 18 | import org.netbeans.api.project.FileOwnerQuery; 19 | import org.netbeans.api.project.Project; 20 | import org.netbeans.api.project.ProjectInformation; 21 | import org.netbeans.api.project.ProjectUtils; 22 | import org.openide.filesystems.FileObject; 23 | import org.openide.filesystems.FileUtil; 24 | import org.openide.loaders.DataObject; 25 | import org.openide.loaders.DataShadow; 26 | import org.openide.nodes.Node; 27 | import org.openide.util.Lookup; 28 | import org.openide.windows.Mode; 29 | import org.openide.windows.TopComponent; 30 | import org.openide.windows.WindowManager; 31 | 32 | /** 33 | * 34 | * @author markiewb 35 | */ 36 | class PathUtil { 37 | 38 | public TitleBuilder getPath(ShowPathInTitleOptions options, TopComponent editor, Node[] selectedNodes) { 39 | Node node = null; 40 | Lookup.Provider provider = null; 41 | if (options.useNodeAsReference) { 42 | if (null != selectedNodes && selectedNodes.length >= 2) { 43 | // cannot decide which node is more important, so leave it 44 | TitleBuilder b = new TitleBuilder(); 45 | b.setFileName("Multiple files selected"); 46 | return b; 47 | } 48 | provider = firstOrNull(selectedNodes); 49 | node = firstOrNull(selectedNodes); 50 | if (provider != null && null != provider.getLookup().lookup(DataObject.class)) { 51 | // pick a better lookup target, since Node doesn't necessarily 52 | // have a Project etc., at least we hope so 53 | provider = provider.getLookup().lookup(DataObject.class); 54 | } 55 | } else if (options.useEditorAsReference) { 56 | provider = getEditor(editor); 57 | node = provider.getLookup().lookup(Node.class); 58 | } 59 | 60 | if (null == provider) { 61 | return new TitleBuilder(); 62 | } 63 | 64 | DataObject dataObject = provider.getLookup().lookup(DataObject.class); 65 | Project project = provider.getLookup().lookup(Project.class); 66 | FileObject fileObject = provider.getLookup().lookup(FileObject.class); 67 | 68 | String projectName = null; 69 | String projectDir = null; 70 | String fileName = null; 71 | if (null != project) { 72 | projectName = getProjectName(project); 73 | projectDir = getProjectDirectory(project); 74 | } 75 | 76 | if (null != dataObject || null != fileObject) { 77 | 78 | final FileObject primaryFile; 79 | if (null != dataObject) { 80 | primaryFile = getFileObjectWithShadowSupport(dataObject); 81 | } else { 82 | primaryFile = fileObject; 83 | } 84 | Project owner = FileOwnerQuery.getOwner(primaryFile); 85 | if (owner != null) { 86 | ProjectInformation information = ProjectUtils.getInformation(owner); 87 | projectDir = getProjectDirectory(information); 88 | projectName = getProjectName(information); 89 | } 90 | 91 | if (null != primaryFile.getPath()) { 92 | fileName = primaryFile.getPath(); 93 | } 94 | 95 | // support selected items in jars 96 | if (null != FileUtil.getArchiveFile(primaryFile)) { 97 | String fullJARPath = FileUtil.getArchiveFile(primaryFile).getPath(); 98 | String archiveFileName = primaryFile.getPath(); 99 | boolean hasFileName = !StringUtils.isEmpty(archiveFileName); 100 | if (hasFileName) { 101 | fileName = fullJARPath + "/" + archiveFileName; 102 | } else { 103 | fileName = fullJARPath; 104 | } 105 | } 106 | } 107 | 108 | TitleBuilder builder = new TitleBuilder(); 109 | builder.setActiveProjectGroup(new ProjectGroupUtil().getActiveProjectGroup()); 110 | builder.setProjectName(projectName); 111 | builder.setProjectDir(projectDir); 112 | builder.setFileName(fileName); 113 | builder.setNodeDisplayName(null != node ? node.getDisplayName() : null); 114 | 115 | return builder; 116 | } 117 | 118 | private Lookup.Provider getEditor(TopComponent editor) { 119 | Lookup.Provider activeTC; 120 | WindowManager wm = WindowManager.getDefault(); 121 | boolean isEditor = editor != null && wm.isEditorTopComponent(editor); 122 | activeTC = isEditor ? editor : getCurrentEditor(); 123 | return activeTC; 124 | } 125 | 126 | private String getProjectDirectory(final ProjectInformation projectInformation) { 127 | return getProjectDirectory(projectInformation.getProject()); 128 | } 129 | 130 | private String getProjectDirectory(final Project project) { 131 | FileObject projectDirectory = project.getProjectDirectory(); 132 | return projectDirectory.getPath(); 133 | } 134 | 135 | private String getProjectName(final Project project) { 136 | return getProjectName(ProjectUtils.getInformation(project)); 137 | } 138 | 139 | private String getProjectName(final ProjectInformation projectInformation) { 140 | return projectInformation.getDisplayName(); 141 | } 142 | 143 | private FileObject getFileObjectWithShadowSupport(DataObject dataObject) { 144 | if (dataObject instanceof DataShadow) { 145 | DataShadow dataShadow = (DataShadow) dataObject; 146 | return dataShadow.getOriginal().getPrimaryFile(); 147 | } 148 | return dataObject.getPrimaryFile(); 149 | } 150 | 151 | /** 152 | * Gets the currently opened editor. 153 | */ 154 | private TopComponent getCurrentEditor() { 155 | WindowManager wm = WindowManager.getDefault(); 156 | Mode editor = wm.findMode("editor"); 157 | return editor.getSelectedTopComponent(); 158 | } 159 | 160 | private T firstOrNull(T[] array) { 161 | return array != null && array.length > 0 ? array[0] : null; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/de/markiewb/netbeans/plugin/showpathintitle/ProjectGroupUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 markiewb 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package de.markiewb.netbeans.plugin.showpathintitle; 17 | 18 | import java.util.prefs.BackingStoreException; 19 | import java.util.prefs.Preferences; 20 | import org.openide.util.Exceptions; 21 | import org.openide.util.NbPreferences; 22 | 23 | /** 24 | * 25 | * @author markiewb 26 | */ 27 | public class ProjectGroupUtil { 28 | 29 | /** 30 | * Preferences key for the active group ID. 31 | */ 32 | private static final String KEY_ACTIVE = "active"; // NOI18N 33 | /** 34 | * Preferences key for display name of group. 35 | */ 36 | protected static final String KEY_NAME = "name"; // NOI18N 37 | 38 | /** 39 | * Get the preference for the given node path. 40 | * 41 | * @param path configuration path like "org/netbeans/modules/projectui" 42 | * @return {@link Preferences} or null 43 | */ 44 | private Preferences getPreferences(String path) { 45 | try { 46 | if (NbPreferences.root().nodeExists(path)) { 47 | return NbPreferences.root().node(path); 48 | } 49 | } catch (BackingStoreException ex) { 50 | Exceptions.printStackTrace(ex); 51 | } 52 | return null; 53 | } 54 | 55 | /** 56 | * 57 | * @return name of the current project group or null 58 | */ 59 | public String getActiveProjectGroup() { 60 | Preferences groupNode = getPreferences("org/netbeans/modules/projectui/groups"); 61 | if (null != groupNode) { 62 | final String groupId = groupNode.get(KEY_ACTIVE, null); 63 | if (null != groupId) { 64 | final Preferences groupPref = getPreferences("org/netbeans/modules/projectui/groups" + "/" + groupId); 65 | if (null != groupPref) { 66 | final String activeProjectGroup = groupPref.get(KEY_NAME, null); 67 | return activeProjectGroup; 68 | } 69 | } 70 | } 71 | return null; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/de/markiewb/netbeans/plugin/showpathintitle/ShowPathInTitleOptions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 markiewb 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package de.markiewb.netbeans.plugin.showpathintitle; 17 | 18 | import java.util.prefs.BackingStoreException; 19 | import java.util.prefs.Preferences; 20 | import org.openide.util.Exceptions; 21 | import org.openide.util.NbPreferences; 22 | 23 | /** 24 | * Simple POJO for loading/saving options. Note: No setter/getter were 25 | * introduced for the ease of usage. It is a plain data holder. 26 | * 27 | * @author markiewb 28 | */ 29 | public class ShowPathInTitleOptions { 30 | 31 | private static boolean default_showProjectGroup = true; 32 | private static boolean default_showProjectName = true; 33 | private static boolean default_showFileName = true; 34 | private static boolean default_showIDEVersion = true; 35 | private static boolean default_showRelativeFilename = true; 36 | private static boolean default_useNodeAsReference = true; 37 | private static boolean default_useEditorAsReference = false; 38 | public static final String SHOWFILENAME = "showFileName"; 39 | public static final String SHOWIDEVERSION = "showIDEVersion"; 40 | public static final String SHOWPROJECTGROUP = "showProjectGroup"; 41 | public static final String SHOWPROJECTNAME = "showProjectName"; 42 | public static final String SHOWRELATIVEFILENAME = "showRelativeFilename"; 43 | public static final String USENODEASREFERENCE = "useNodeAsReference"; 44 | public static final String USEEDITORASREFERENCE = "useEditorAsReference"; 45 | 46 | private ShowPathInTitleOptions() { 47 | //NOP 48 | } 49 | 50 | public boolean showProjectGroup; 51 | public boolean showProjectName; 52 | public boolean showFileName; 53 | public boolean showIDEVersion; 54 | public boolean showRelativeFilename; 55 | public boolean useNodeAsReference; 56 | public boolean useEditorAsReference; 57 | 58 | public static ShowPathInTitleOptions loadFrom(Preferences pref) { 59 | 60 | ShowPathInTitleOptions options = new ShowPathInTitleOptions(); 61 | options.showProjectGroup = pref.getBoolean(SHOWPROJECTGROUP, default_showProjectGroup); 62 | options.showProjectName = pref.getBoolean(SHOWPROJECTNAME, default_showProjectName); 63 | options.showFileName = pref.getBoolean(SHOWFILENAME, default_showFileName); 64 | options.showIDEVersion = pref.getBoolean(SHOWIDEVERSION, default_showIDEVersion); 65 | options.showRelativeFilename = pref.getBoolean(SHOWRELATIVEFILENAME, default_showRelativeFilename); 66 | options.useNodeAsReference = pref.getBoolean(USENODEASREFERENCE, default_useNodeAsReference); 67 | options.useEditorAsReference = pref.getBoolean(USEEDITORASREFERENCE, default_useEditorAsReference); 68 | return options; 69 | } 70 | 71 | public void saveTo(Preferences pref) { 72 | pref.put("version", "2.0.0"); 73 | pref.putBoolean(SHOWPROJECTGROUP, showProjectGroup); 74 | pref.putBoolean(SHOWPROJECTNAME, showProjectName); 75 | pref.putBoolean(SHOWFILENAME, showFileName); 76 | pref.putBoolean(SHOWIDEVERSION, showIDEVersion); 77 | pref.putBoolean(SHOWRELATIVEFILENAME, showRelativeFilename); 78 | pref.putBoolean(USENODEASREFERENCE, useNodeAsReference); 79 | pref.putBoolean(USEEDITORASREFERENCE, useEditorAsReference); 80 | } 81 | 82 | public void reset() { 83 | showProjectGroup = default_showProjectGroup; 84 | showProjectName = default_showProjectName; 85 | showFileName = default_showFileName; 86 | showIDEVersion = default_showIDEVersion; 87 | showRelativeFilename = default_showRelativeFilename; 88 | useNodeAsReference = default_useNodeAsReference; 89 | useEditorAsReference = default_useEditorAsReference; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/de/markiewb/netbeans/plugin/showpathintitle/StringUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 markiewb 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package de.markiewb.netbeans.plugin.showpathintitle; 17 | 18 | /** 19 | * 20 | * @author markiewb 21 | */ 22 | public class StringUtils { 23 | 24 | /** 25 | * Returns the original string if not empty or not null. Else return the 26 | * given default. 27 | */ 28 | public static String defaultIfEmpty(String string, String defaultStr) { 29 | if (isEmpty(string)) { 30 | return defaultStr; 31 | } 32 | return string; 33 | } 34 | 35 | public static boolean isEmpty(String string) { 36 | return null == string || "".equals(string); 37 | } 38 | 39 | public static String join_nullignore(Iterable list, String separator) { 40 | boolean first = true; 41 | StringBuilder a = new StringBuilder(); 42 | for (String string : list) { 43 | if (isEmpty(string)) { 44 | continue; 45 | } 46 | if (!first) { 47 | a.append(separator); 48 | } 49 | a.append(string); 50 | first = false; 51 | } 52 | return a.toString(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/de/markiewb/netbeans/plugin/showpathintitle/TitleBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 markiewb 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package de.markiewb.netbeans.plugin.showpathintitle; 17 | 18 | import java.util.LinkedHashSet; 19 | import java.util.Set; 20 | 21 | /** 22 | * 23 | * @author markiewb 24 | */ 25 | class TitleBuilder { 26 | 27 | String activeProjectGroup; 28 | String fileName; 29 | String ideVersion; 30 | String nodeDisplayName; 31 | String projectDir; 32 | String projectName; 33 | 34 | public String build(ShowPathInTitleOptions options) { 35 | // create title 36 | Set list = new LinkedHashSet(); 37 | if (options.showProjectGroup) { 38 | list.add(activeProjectGroup); 39 | } 40 | if (options.showProjectName) { 41 | list.add(projectName); 42 | } 43 | 44 | if (options.showFileName) { 45 | // show relative path, when project dir is in selected path 46 | // show no relative path, when project dir equals selected path 47 | boolean isRelativePath = null != fileName && null != projectDir && fileName.startsWith(projectDir) 48 | && !fileName.equals(projectDir); 49 | if (options.showRelativeFilename && isRelativePath) { 50 | // create and use relative file name 51 | String reducedFileName = fileName.substring(projectDir.length()); 52 | fileName = reducedFileName; 53 | } 54 | 55 | if (null == fileName && null != projectDir) { 56 | // show projectDir as fallback 57 | fileName = projectDir; 58 | } 59 | if (null == fileName && null != nodeDisplayName) { 60 | // show node label as further fallback 61 | fileName = nodeDisplayName; 62 | } 63 | list.add(fileName); 64 | } 65 | if (options.showIDEVersion) { 66 | // version only available for netbeans >=7.1 67 | list.add(System.getProperty("netbeans.productversion")); 68 | } 69 | return StringUtils.join_nullignore(list, " - "); 70 | } 71 | 72 | public void setActiveProjectGroup(String activeProjectGroup) { 73 | this.activeProjectGroup = activeProjectGroup; 74 | } 75 | 76 | public void setFileName(String fileName) { 77 | this.fileName = fileName; 78 | } 79 | 80 | public void setIdeVersion(String ideVersion) { 81 | this.ideVersion = ideVersion; 82 | } 83 | 84 | public void setNodeDisplayName(String nodeDisplayName) { 85 | this.nodeDisplayName = nodeDisplayName; 86 | } 87 | 88 | public void setProjectDir(String projectDir) { 89 | this.projectDir = projectDir; 90 | } 91 | 92 | public void setProjectName(String projectName) { 93 | this.projectName = projectName; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/de/markiewb/netbeans/plugin/showpathintitle/options/Bundle.properties: -------------------------------------------------------------------------------- 1 | AdvancedOption_DisplayName_Showpathintitle=Show path in titlebar 2 | AdvancedOption_Keywords_Showpathintitle=path, filename, full filename, path, title, titlebar 3 | ShowpathintitlePanel.cbProjectName.text=Project &name 4 | ShowpathintitlePanel.cbPath.text=Full &Path 5 | ShowpathintitlePanel.cbVersion.text=NetBeans &version (only supported for NetBeans >=7.1) 6 | ShowpathintitlePanel.txtIntroduction.text=Check the items which will be displayed in the title of the main window: 7 | ShowpathintitlePanel.cbRelativePath.text=show path relative to project &directory (eclipse-like) 8 | ShowpathintitlePanel.btnReset.text=&Reset 9 | ShowpathintitlePanel.rbUseNodeAsReference.text=use &selected node as source for path 10 | ShowpathintitlePanel.rbUseEditorAsReference.text=use open &editor as source for path (eclipse-like) 11 | ShowpathintitlePanel.rbUseNodeAsReference.toolTipText=Switching nodes will change the displayed path. Even when the document behind the node is not opened. 12 | ShowpathintitlePanel.rbUseEditorAsReference.toolTipText=Switching between open editors will change the displayed path.\n 13 | ShowpathintitlePanel.cbProjectGroup.text=Project &group 14 | -------------------------------------------------------------------------------- /src/de/markiewb/netbeans/plugin/showpathintitle/options/ShowpathintitleOptionsPanelController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 markiewb 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package de.markiewb.netbeans.plugin.showpathintitle.options; 17 | 18 | import java.beans.PropertyChangeListener; 19 | import java.beans.PropertyChangeSupport; 20 | import javax.swing.JComponent; 21 | import org.netbeans.spi.options.OptionsPanelController; 22 | 23 | import org.openide.util.*; 24 | 25 | @OptionsPanelController.SubRegistration(location = "Appearance", 26 | displayName = "#AdvancedOption_DisplayName_Showpathintitle", 27 | keywords = "#AdvancedOption_Keywords_Showpathintitle", 28 | keywordsCategory = "Appearance/Showpathintitlebar", 29 | position = 50000 30 | ) 31 | public final class ShowpathintitleOptionsPanelController extends OptionsPanelController { 32 | 33 | private ShowpathintitlePanel panel; 34 | private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); 35 | private boolean changed; 36 | 37 | public void update() { 38 | getPanel().load(); 39 | changed = false; 40 | } 41 | 42 | public void applyChanges() { 43 | getPanel().store(); 44 | changed = false; 45 | } 46 | 47 | public void cancel() { 48 | // need not do anything special, if no changes have been persisted yet 49 | } 50 | 51 | public boolean isValid() { 52 | return getPanel().valid(); 53 | } 54 | 55 | public boolean isChanged() { 56 | return changed; 57 | } 58 | 59 | public HelpCtx getHelpCtx() { 60 | return null; // new HelpCtx("...ID") if you have a help set 61 | } 62 | 63 | public JComponent getComponent(Lookup masterLookup) { 64 | return getPanel(); 65 | } 66 | 67 | public void addPropertyChangeListener(PropertyChangeListener l) { 68 | pcs.addPropertyChangeListener(l); 69 | } 70 | 71 | public void removePropertyChangeListener(PropertyChangeListener l) { 72 | pcs.removePropertyChangeListener(l); 73 | } 74 | 75 | private ShowpathintitlePanel getPanel() { 76 | if (panel == null) { 77 | panel = new ShowpathintitlePanel(this); 78 | } 79 | return panel; 80 | } 81 | 82 | void changed() { 83 | if (!changed) { 84 | changed = true; 85 | pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); 86 | } 87 | pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/de/markiewb/netbeans/plugin/showpathintitle/options/ShowpathintitlePanel.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 |
170 | -------------------------------------------------------------------------------- /src/de/markiewb/netbeans/plugin/showpathintitle/options/ShowpathintitlePanel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 markiewb 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package de.markiewb.netbeans.plugin.showpathintitle.options; 17 | 18 | import de.markiewb.netbeans.plugin.showpathintitle.ShowPathInTitleOptions; 19 | import java.util.prefs.Preferences; 20 | import org.openide.util.NbPreferences; 21 | 22 | final class ShowpathintitlePanel extends javax.swing.JPanel { 23 | 24 | private final ShowpathintitleOptionsPanelController controller; 25 | private Preferences pref = NbPreferences.forModule(ShowPathInTitleOptions.class); 26 | private ShowPathInTitleOptions options; 27 | 28 | ShowpathintitlePanel(ShowpathintitleOptionsPanelController controller) { 29 | this.controller = controller; 30 | initComponents(); 31 | // TODO listen to changes in form fields and call controller.changed() 32 | } 33 | 34 | /** 35 | * This method is called from within the constructor to initialize the form. 36 | * WARNING: Do NOT modify this code. The content of this method is always 37 | * regenerated by the Form Editor. 38 | */ 39 | // //GEN-BEGIN:initComponents 40 | private void initComponents() { 41 | 42 | buttonGroup1 = new javax.swing.ButtonGroup(); 43 | txtIntroduction = new javax.swing.JLabel(); 44 | cbProjectName = new javax.swing.JCheckBox(); 45 | cbPath = new javax.swing.JCheckBox(); 46 | cbVersion = new javax.swing.JCheckBox(); 47 | btnReset = new javax.swing.JButton(); 48 | cbRelativePath = new javax.swing.JCheckBox(); 49 | rbUseEditorAsReference = new javax.swing.JRadioButton(); 50 | rbUseNodeAsReference = new javax.swing.JRadioButton(); 51 | cbProjectGroup = new javax.swing.JCheckBox(); 52 | 53 | org.openide.awt.Mnemonics.setLocalizedText(txtIntroduction, org.openide.util.NbBundle.getMessage(ShowpathintitlePanel.class, "ShowpathintitlePanel.txtIntroduction.text")); // NOI18N 54 | 55 | org.openide.awt.Mnemonics.setLocalizedText(cbProjectName, org.openide.util.NbBundle.getMessage(ShowpathintitlePanel.class, "ShowpathintitlePanel.cbProjectName.text")); // NOI18N 56 | 57 | org.openide.awt.Mnemonics.setLocalizedText(cbPath, org.openide.util.NbBundle.getMessage(ShowpathintitlePanel.class, "ShowpathintitlePanel.cbPath.text")); // NOI18N 58 | cbPath.addChangeListener(new javax.swing.event.ChangeListener() { 59 | public void stateChanged(javax.swing.event.ChangeEvent evt) { 60 | cbPathStateChanged(evt); 61 | } 62 | }); 63 | 64 | org.openide.awt.Mnemonics.setLocalizedText(cbVersion, org.openide.util.NbBundle.getMessage(ShowpathintitlePanel.class, "ShowpathintitlePanel.cbVersion.text")); // NOI18N 65 | 66 | org.openide.awt.Mnemonics.setLocalizedText(btnReset, org.openide.util.NbBundle.getMessage(ShowpathintitlePanel.class, "ShowpathintitlePanel.btnReset.text")); // NOI18N 67 | btnReset.addActionListener(new java.awt.event.ActionListener() { 68 | public void actionPerformed(java.awt.event.ActionEvent evt) { 69 | btnResetActionPerformed(evt); 70 | } 71 | }); 72 | 73 | org.openide.awt.Mnemonics.setLocalizedText(cbRelativePath, org.openide.util.NbBundle.getMessage(ShowpathintitlePanel.class, "ShowpathintitlePanel.cbRelativePath.text")); // NOI18N 74 | 75 | buttonGroup1.add(rbUseEditorAsReference); 76 | org.openide.awt.Mnemonics.setLocalizedText(rbUseEditorAsReference, org.openide.util.NbBundle.getMessage(ShowpathintitlePanel.class, "ShowpathintitlePanel.rbUseEditorAsReference.text")); // NOI18N 77 | rbUseEditorAsReference.setToolTipText(org.openide.util.NbBundle.getMessage(ShowpathintitlePanel.class, "ShowpathintitlePanel.rbUseEditorAsReference.toolTipText")); // NOI18N 78 | 79 | buttonGroup1.add(rbUseNodeAsReference); 80 | org.openide.awt.Mnemonics.setLocalizedText(rbUseNodeAsReference, org.openide.util.NbBundle.getMessage(ShowpathintitlePanel.class, "ShowpathintitlePanel.rbUseNodeAsReference.text")); // NOI18N 81 | rbUseNodeAsReference.setToolTipText(org.openide.util.NbBundle.getMessage(ShowpathintitlePanel.class, "ShowpathintitlePanel.rbUseNodeAsReference.toolTipText")); // NOI18N 82 | 83 | org.openide.awt.Mnemonics.setLocalizedText(cbProjectGroup, org.openide.util.NbBundle.getMessage(ShowpathintitlePanel.class, "ShowpathintitlePanel.cbProjectGroup.text")); // NOI18N 84 | 85 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); 86 | this.setLayout(layout); 87 | layout.setHorizontalGroup( 88 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 89 | .addGroup(layout.createSequentialGroup() 90 | .addContainerGap() 91 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 92 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 93 | .addGap(0, 0, Short.MAX_VALUE) 94 | .addComponent(btnReset)) 95 | .addGroup(layout.createSequentialGroup() 96 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 97 | .addComponent(cbProjectGroup) 98 | .addComponent(cbProjectName) 99 | .addComponent(cbPath) 100 | .addComponent(cbVersion) 101 | .addGroup(layout.createSequentialGroup() 102 | .addGap(21, 21, 21) 103 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 104 | .addComponent(rbUseNodeAsReference) 105 | .addComponent(cbRelativePath) 106 | .addComponent(rbUseEditorAsReference))) 107 | .addComponent(txtIntroduction)) 108 | .addGap(0, 31, Short.MAX_VALUE))) 109 | .addContainerGap()) 110 | ); 111 | layout.setVerticalGroup( 112 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 113 | .addGroup(layout.createSequentialGroup() 114 | .addContainerGap() 115 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 116 | .addGroup(layout.createSequentialGroup() 117 | .addComponent(txtIntroduction) 118 | .addGap(11, 11, 11) 119 | .addComponent(cbProjectGroup) 120 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 121 | .addComponent(cbProjectName) 122 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 123 | .addComponent(cbPath) 124 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 125 | .addComponent(cbRelativePath) 126 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 127 | .addComponent(rbUseNodeAsReference) 128 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 129 | .addComponent(rbUseEditorAsReference) 130 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 131 | .addComponent(cbVersion) 132 | .addGap(0, 54, Short.MAX_VALUE)) 133 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 134 | .addGap(0, 0, Short.MAX_VALUE) 135 | .addComponent(btnReset))) 136 | .addContainerGap()) 137 | ); 138 | }// //GEN-END:initComponents 139 | 140 | private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResetActionPerformed 141 | options.reset(); 142 | initUIFromOptions(); 143 | }//GEN-LAST:event_btnResetActionPerformed 144 | 145 | private void cbPathStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_cbPathStateChanged 146 | boolean selected = cbPath.isSelected(); 147 | 148 | //enable or disable dependend widgets 149 | cbRelativePath.setEnabled(selected); 150 | rbUseNodeAsReference.setEnabled(selected); 151 | rbUseEditorAsReference.setEnabled(selected); 152 | }//GEN-LAST:event_cbPathStateChanged 153 | 154 | void load() { 155 | options = ShowPathInTitleOptions.loadFrom(pref); 156 | initUIFromOptions(); 157 | } 158 | 159 | void store() { 160 | options.showProjectGroup = cbProjectGroup.isSelected(); 161 | options.showProjectName = cbProjectName.isSelected(); 162 | options.showFileName = cbPath.isSelected(); 163 | options.showIDEVersion = cbVersion.isSelected(); 164 | options.showRelativeFilename = cbRelativePath.isSelected(); 165 | options.useNodeAsReference = rbUseNodeAsReference.isSelected(); 166 | options.useEditorAsReference = rbUseEditorAsReference.isSelected(); 167 | options.saveTo(pref); 168 | } 169 | 170 | boolean valid() { 171 | // TODO check whether form is consistent and complete 172 | return true; 173 | } 174 | // Variables declaration - do not modify//GEN-BEGIN:variables 175 | private javax.swing.JButton btnReset; 176 | private javax.swing.ButtonGroup buttonGroup1; 177 | private javax.swing.JCheckBox cbPath; 178 | private javax.swing.JCheckBox cbProjectGroup; 179 | private javax.swing.JCheckBox cbProjectName; 180 | private javax.swing.JCheckBox cbRelativePath; 181 | private javax.swing.JCheckBox cbVersion; 182 | private javax.swing.JRadioButton rbUseEditorAsReference; 183 | private javax.swing.JRadioButton rbUseNodeAsReference; 184 | private javax.swing.JLabel txtIntroduction; 185 | // End of variables declaration//GEN-END:variables 186 | 187 | private void initUIFromOptions() { 188 | cbProjectGroup.setSelected(options.showProjectGroup); 189 | cbVersion.setSelected(options.showIDEVersion); 190 | cbProjectName.setSelected(options.showProjectName); 191 | cbPath.setSelected(options.showFileName); 192 | cbRelativePath.setSelected(options.showRelativeFilename); 193 | rbUseNodeAsReference.setSelected(options.useNodeAsReference); 194 | rbUseEditorAsReference.setSelected(options.useEditorAsReference); 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/test/resources/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Chris2011/show-path-in-title-netbeans-module/c725c9199eed4fdac88e341ec50d47fe44563589/src/test/resources/example.png --------------------------------------------------------------------------------