12 |
How to use the bookmarks add-on for Freeplane
13 |
Voir en français
14 |
32 |
33 | Define keyboard shortcuts
34 | The add-on doesn't define keyboard shortcuts by default (because they may overwrite your own custom shortcuts). But I recommend to bind some handy keyboards shortcuts to the add-on menu entries. This will make the add-on really convenient to use, because it was mainly designed to provide a fast map navigation with the keyboard.
35 | For example, here's my own shortcuts:
36 | Main commands
37 |
38 | - Add / Remove a bookmark: Ctrl-Maj-B
39 | - Toggle the bookmark: Ctrl-Maj-T
40 | - Jump to bookmark: Ctrl-Maj-J
41 |
42 | Other commands
43 |
44 | - Jump to previous bookmark: Ctrl-Maj-Up
45 | - Jump to next bookmark: Ctrl-Maj-Down
46 | - Links > Create link in bookmarked node: Ctrl-Maj-I ( "In" - inside the selected node )
47 | - Links > Create link to bookmarked node: Ctrl-Maj-O ( "Out" - outside the selected node )
48 |
49 | To define a keyboard shortcut in Freeplane, maintain the Ctrl key pressed and click a menu entry.
50 |
51 |
52 | 2 types of bookmarks
53 | The add-on let you create 2 types of bookmarks:
54 |
55 |
Standard bookmarks. A node with this kind of bookmark is a node with the purple icon. It is not different than any other node with an icon. The add-on use this icon to detect it.
56 |
Named bookmarks. A node with this kind of bookmark is a node with the green icon, and a "name". This name is in fact a single letter, digit, or any single key from the keyboard. This name allow quick access to the bookmark. Such a bookmark can be use, for example, to mark the most important nodes in the map.
57 |
58 | 
59 |
60 |
61 | Create a bookmark
62 | To create a bookmark in a node, select the node then use the Add / Remove a bookmark command.
63 | This open a dialog which show you the existing named bookmarks and the possible actions:
64 | 
65 |
66 | - Press space to create a standard bookmark
67 | - Type any other key on the keyboard to create a named bookmark
68 |
69 | 
70 | If you create a bookmark with a name that is already used elsewhere, the actual bookmark with this name is erased.
Example with the letter A:
71 | 
72 | Another way to create a standard bookmark is to use the Toggle the bookmark command:
73 | 
74 |
75 |
76 | Jump to a bookmark
77 | To jump to a bookmark, use the Jump to bookmark command.
78 | This open a dialog that let you pick the desired bookmark. You can select the bookmark with the keyboard or the mouse.
79 | 
80 | Use the key Tab to switch between standard bookmarks and named bookmarks.
81 | 
82 | You can jump to the previous/next bookmark with the commands Jump to previous bookmark and Jump to next bookmark:
83 | 
84 |
85 |
86 | Remove a bookmark
87 | To remove a bookmark, select its node, choose the Add / Remove a bookmark command and press the Backspace key:
88 | 
89 | You can also use the Toggle the bookmark command:
90 | 
91 |
92 |
93 | Make links
94 | In the selected node, you can create a regular Freeplane link that target any bookmarked node.
95 | Select the node where you want to create the link and use the Links > Create link to bookmarked node command. Then select the bookmark target of the link.
96 | For example, I want to create in a node a link to the node "Chapter 2":
97 | 
98 | Tip: you can use the same command to create a link to the node memorized with the Freeplane command Edit > Link > Set link anchor (Ctrl-M for me). In this case, press the Space key instead of picking a bookmark.
99 | For exemple, I want to create in a node a link to the node "Conclusion":
100 | 
101 | You may also want to create a link in a bookmarked node that target the selected node.
102 | In this case use the Links > Create link in bookmarked node command, then select the bookmarked node where to create the link.
103 | For example, I want to create in the node "Chapter 2" a link to another node:
104 | 
105 | Tip: again, you can create the link into the node memorized with the Freeplane command Edit > Link > Set link anchor by pressing the Space key.
106 |
107 |
108 | Other tools
109 |
110 | Convert bookmarks to or from Freeplane builtin bookmark icons
111 |
For non users of this add-on, Freeplane features an icon that could be use as a bookmark icon. The add-on doesn't make use of it, but it is possible to bookmark all the nodes that contain it. Use the Tools > Convert all regular FreePlane bookmark icons (star icon) to add-on bookmarks command to replace this icon by the add-on standard bookmark icon.
112 | 
113 | You can do the inverse operation with the Tools > Convert all bookmarks to regular FreePlane bookmark icons (star icon) command. This could be useful if someday you want to stop using this add-on and want to keep your bookmarks. Of course, you have to use this command before deinstall the add-on. Take care, this operation is not reversible and delete the bookmarks names.
114 |
115 |
116 | Update bookmarks from a previous version of the add-on
117 | If after an update of this add-on you've got an incorrect behavior, consider to use the command Tools > Fix named bookmarks created by an old version of the add-on. But don't worry to much: at the moment, the only persons who need this command are the persons who used the version 0.5.0-beta.
118 |
119 |
120 |
121 | Get more help
122 | Feel free to add your question to the dedicated discussion on the Freeplane forum.
123 | You can also share your concerns by opening an issue in github.
124 |
125 |
126 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/zips/doc/bookmarks/help_fr.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
Utilisation du module de Marque-pages pour Freeplane
13 |
Display in english
14 |
32 |
33 | Définir des raccourcis clavier
34 | Ce module ne définit pas de raccourcis claviers par défaut pour accéder à ses fonctionnalités (car ils pourraient remplacer vos raccourcis claviers existants). Je recommande de créer des raccourcis claviers bien choisis vers les différentes commandes du menu du module. Cela le rendra beaucoup plus pratique à utiliser, puisqu'il a été conçu dans l'idée de faciliter grandement la navigation dans les cartes à l'aide du clavier.
35 | Voici pour exemple les raccourcis que j'utilise :
36 | Commandes principales
37 |
38 | - Placer / Supprimer un marque-page : Ctrl-Maj-B ( B comme Bookmark )
39 | - Basculer un marque-page : Ctrl-Maj-T ( T comme Toggle )
40 | - Atteindre un marque-page : Ctrl-Maj-J ( J comme Jump )
41 |
42 | Je me suis basé sur les mots anglais pour mes raccourcis, mais j'aurais aussi bien pu utiliser Ctrl-Maj-M,Ctrl-Maj-B et Ctrl-Maj-A pour utiliser les initiales des mots français correspondants.
43 | Autres commandes
44 |
45 | - Atteindre le marque-page précédent : Ctrl-Maj-Haut
46 | - Atteindre le marque-page suivant : Ctrl-Maj-Bas
47 | - Liens > Créer un lien dans un marque-page : Ctrl-Maj-I ( "In" - dans le nœud sélectionné )
48 | - Liens > Créer un lien vers un marque-page : Ctrl-Maj-O ( "Out" - hors du nœud sélectionné )
49 |
50 | Pour définir un raccourci clavier dans Freeplane, cliquer sur une entrée de menu en maintenant la touche Ctrl enfoncée, puis choisir la combinaison de touches à y associer.
51 |
52 |
53 | Deux types de marque-pages
54 | Le module permet d'utiliser deux sortes de marque-page:
55 |
56 |
Le marque-page standard. Un nœud avec un tel marque-page contient l'icône de marque-page violette. Il n'est pas différent d'un autre nœud de Freeplane qui contient une icône, si ce n'est qu'il est reconnu par le module comme nœud marqué.
57 |
Le marque-page nommé. Un nœud avec un tel marque-page contient l'icône de marque-page verte et a un "nom". Ce nom est une unique lettre, chiffre, ou autre touche du clavier. Il permet un accès rapide à ce nœud. On peut utiliser ce marque-page pour des nœud particulièrement important ou visités de la carte.
58 |
59 | 
60 |
61 |
62 | Créer un marque-page
63 | Pour créer un marque-page, utiliser la commande Placer / Supprimer un marque-page
64 | Ceci ouvre une boîte de dialogue qui montre les marque-pages existants, et qui explique les actions possibles :
65 | 
66 |
67 | - Enfoncer la touche espace pour créer un marque-page standard
68 | - Ou toute autre touche du clavier pour créer un marque-page nommé
69 |
70 | 
71 | Si vous choisissez un nom qui est déjà utilisé par un autre marque-page nommé, ce marque-page sera effacé.
Voici ce que cela donne pour un marque-page nommé A :
72 | 
73 | Une autre façon de définir rapidement un marque-page standard est d'utiliser la commande Basculer un marque-page :
74 | 
75 |
76 |
77 | Atteindre un marque-page
78 | Pour aller à un nœud contenant un marque-page, utiliser la commande Atteindre un marque-page.
79 | Ceci ouvre boîte de dialogue qui permet de choisir un marque-page. Vous pouvez choisir le marque-page avec le clavier ou la souris.
80 | 
81 | Utiliser la touche Tab pour basculer l'affichage entre les marque-pages standards et les marque-pages nommés.
82 | 
83 | Vous pouvez aussi sauter au marque-page précédent ou suivant avec les commandes Atteindre le marque-page précédent et Atteindre le marque-page suivant :
84 | 
85 |
86 |
87 | Effacer un marque-page
88 | Pour supprimer un marque-page, utiliser la commande Placer / Supprimer un marque-page et appuyer sur la touche Effacement arrière :
89 | 
90 | vous pouvez aussi utiliser la commande Basculer un marque-page :
91 | 
92 |
93 |
94 | Créer des liens
95 | Vous pouvez créer facilement un lien vers un nœud contenant un marque-page dans le nœud actuellement sélectionné.
96 | Sélectionnez le nœud où créer le lien, puis utiliser la commande Liens > Créer un lien vers un marque-page. Choisissez alors le nœud marqué qui sera la cible du lien.
97 | Par exemple, pour créer dans un nœud un lien vers le nœud "Chapitre 2" :
98 | 
99 | Astuce: vous pouvez également utiliser cette commande pour créer un lien vers le nœud mémorisé par la commande Édition > Lien > Mémoriser le nœud de Freeplane (Ctrl-M pour moi). Pour ceci, presser la touche espace plutôt que choisir un marque-page.
100 | Par exemple, pour créer un lien vers le nœud "Conclusion" :
101 | 
102 | À l'inverse, vous pouvez créer un lien vers le nœud actuellement sélectionné dans un nœud marqué.
103 | Pour cela, utiliser la commande Liens > Créer un lien dans un marque-page, puis choisir le marque-page du nœud où créer le lien.
104 | Par exemple, pour créer un lien vers le nœud sélectionné dans le nœud "Chapitre 2" :
105 | 
106 | Astuce: vous pouvez également utiliser cette commande pour créer un lien dans le nœud mémorisé par la commande Édition > Lien > Mémoriser le nœud de Freeplane. Pour ceci, presser la touche espace plutôt que choisir un marque-page.
107 |
108 |
109 | Outils divers
110 |
111 | Convertir les marque-pages natifs de Freeplane en marque-pages du module, et vice-versa
112 |
Les utilisateurs de Freeplane qui n'utilisent pas ce module peuvent utiliser l'icône en forme d'étoile pour marquer des nœuds particuliers. Ce module n'utilise pas ces icônes comme marqueurs de marque-page. Par contre, il est possible de transformer ces icônes en marque-pages utilisables par ce module avec la commande Outils > Convertir toutes les icônes de marque-page de FreePlane (étoile) en marque-pages pour ce module :
113 | 
114 | L'opération inverse est également possible avec la commande Outils > Convertir tous les marque-pages en icônes de marque-page de FreePlane (étoile). Ceci peut être utile si vous souhaitez ne plus utiliser ce module mais voulez conserver les marque-pages que vous avez définis. Une fois que vous avez ainsi converti les marque-pages de vos cartes, vous pouvez désinstaller le module car vos nœud sont maintenant marqués avec les icônes en forme d'étoile de Freeplane. Attention, cette opération efface les noms des marque-pages nommés, et n'est pas réversible.
115 |
116 |
117 | Mettre à jour les marque-pages d'une version précédente du module
118 | Si après une mise-à-jour du module vous avez des comportements inattendus avec vos marque-pages, vous pouvez utiliser la commande Outils > Récupérer les marque-pages nommés d'une version antérieure du module. Ceci devrait résoudre le problème. Mais ne vous alarmez pas trop, cette commande sera utile seulement au petit nombre de personnes qui ont utilisé la version 0.5.0-beta.
119 |
120 |
121 |
122 | Obtenir plus d'aide
123 | N'hésitez pas à poser des questions sur le forum de Freeplane. Il y existe déjà une discussion sur ce module, ajoutez-y votre question.
124 | Vous pouvez également faire part de vos problèmes en ouvrant une issue sur le dépot github du module.
125 |
126 |
127 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/src/main/groovy/Bookmarks.groovy:
--------------------------------------------------------------------------------
1 | package lilive.bookmarks
2 |
3 | import groovy.json.JsonBuilder
4 | import groovy.json.JsonSlurper
5 | import java.awt.Graphics2D
6 | import java.awt.Image
7 | import java.awt.image.BufferedImage
8 | import java.util.Map as JMap
9 | import javax.swing.Icon
10 | import javax.swing.ImageIcon
11 | import javax.swing.UIManager
12 | import org.freeplane.api.MindMap as MindMap
13 | import org.freeplane.api.Node
14 | import org.freeplane.api.Properties
15 | import org.freeplane.core.util.TextUtils
16 | import org.freeplane.plugin.script.proxy.Convertible
17 | import org.freeplane.plugin.script.proxy.ScriptUtils
18 |
19 | class Bookmarks
20 | {
21 |
22 | final static String storageKey = "BookmarksKeys"
23 | final static String anonymousIcon = "bookmarks/Bookmark 1"
24 | final static String namedIcon = "bookmarks/Bookmark 2"
25 |
26 | // gtt = Get Translated Text
27 | static String gtt( String key )
28 | {
29 | return TextUtils.getText( 'addons.bookmarks.' + key )
30 | }
31 |
32 | // Create a java.util.Map where :
33 | // - the keys are the keyboard keys assigned to a bookmarked node;
34 | // - the values are the id of the corresponding bookmarked node.
35 | // This java.util.Map is read from the freeplane map storage area.
36 | static JMap loadNamedBookmarks( MindMap map )
37 | {
38 | // Read the datas from the map storage
39 | Convertible stored = map.storage.getAt( storageKey )
40 |
41 | // Convert these datas to an java.util.Map
42 | if( stored ) return new JsonSlurper().parseText( stored.getText() ) as JMap
43 | else return [:]
44 | }
45 |
46 | // Store the java.util.Map namedBookmarks in the freeplane map storage area.
47 | static void saveNamedBookmarks( JMap namedBookmarks, MindMap map )
48 | {
49 | JsonBuilder builder = new JsonBuilder()
50 | builder( namedBookmarks )
51 | map.storage.putAt( storageKey, builder.toString() )
52 | }
53 |
54 | // Erase the stored named bookmarks.
55 | // Return true is something change.
56 | static Boolean eraseNamedBookmarksStorage( MindMap map )
57 | {
58 | Convertible storage = map.storage.getAt( storageKey )
59 | if( storage != null )
60 | {
61 | map.storage.putAt( storageKey, null )
62 | return true
63 | }
64 | else
65 | {
66 | return false
67 | }
68 | }
69 |
70 | // Remove in namedBookmarks all the node that don't exist,
71 | // and add the named bookmark icon to each referenced node that miss it.
72 | // Return the currated bookmarks map.
73 | static JMap fixNamedBookmarksInconsistency( JMap namedBookmarks, MindMap map )
74 | {
75 | Boolean changed = namedBookmarks.removeAll
76 | {
77 | key, id ->
78 | return ( map.node( id ) == null )
79 | }
80 | if( changed ) saveNamedBookmarks( namedBookmarks, map )
81 |
82 | namedBookmarks.each
83 | {
84 | key, id ->
85 | Node n = map.node( id )
86 | if( ! Bookmarks.hasNamedBookmarkIcon( n ) ) n.icons.add( Bookmarks.namedIcon )
87 | }
88 |
89 | return namedBookmarks
90 | }
91 |
92 | // Return true if the node has the anonymous bookmark icon
93 | static Boolean hasAnonymousBookmarkIcon( Node node )
94 | {
95 | return node.icons.contains( anonymousIcon )
96 | }
97 |
98 | // Return true if the node is bookmarked with an anonymous bookmark icon
99 | // (actually it's the same than hasAnonymousBookmarkIcon()
100 | static Boolean isAnonymousBookmarked( Node node )
101 | {
102 | return node.icons.contains( anonymousIcon )
103 | }
104 |
105 | // Return true if the node has the named bookmark icon
106 | static Boolean hasNamedBookmarkIcon( Node node )
107 | {
108 | return node.icons.contains( namedIcon )
109 | }
110 |
111 | // Return true if the node appear in the namedBookmarks map
112 | static Boolean hasBookmarkName( Node node, JMap namedBookmarks )
113 | {
114 | return namedBookmarks.containsValue( node.id )
115 | }
116 |
117 | // Return true if the node is bookmarked with a named bookmark
118 | static Boolean isNamedBookmarked( Node node, JMap namedBookmarks )
119 | {
120 | return hasNamedBookmarkIcon( node ) && hasBookmarkName( node, namedBookmarks )
121 | }
122 |
123 | // Return true if the node is bookmarked (anonymous or named bookmark)
124 | static Boolean isBookmarked( Node node, JMap namedBookmarks )
125 | {
126 | return isAnonymousBookmarked( node ) || isNamedBookmarked( node, namedBookmarks )
127 | }
128 |
129 | static String getNodeShortPlainText( Node node )
130 | {
131 | String text = node.plainText
132 | if( text.length() > 30 ) text = text[0..27] + " ..."
133 | return text
134 | }
135 |
136 | // Create an anonymous bookmark for this node.
137 | static void createAnonymousBookmark( Node node )
138 | {
139 | if( ! node.icons.contains( anonymousIcon ) )
140 | {
141 | node.icons.add( anonymousIcon )
142 | }
143 | }
144 |
145 | // Remove an anonymous bookmark for this node.
146 | static void deleteAnonymousBookmark( Node node )
147 | {
148 | while( node.icons.remove( anonymousIcon ) ){}
149 | }
150 |
151 | // Create a named bookmark for this node.
152 | // The name of the bookmark is a single keyboard key.
153 | static JMap createNamedBookmark( Node node, keyCharCode, JMap namedBookmarks )
154 | {
155 | String s = String.valueOf( keyCharCode )
156 |
157 | // If another node has this named bookmark, remove it
158 | if( namedBookmarks.containsKey( s ) )
159 | {
160 | Node n = node.map.node( namedBookmarks[ s ] )
161 | if( n && n != node ) deleteNamedBookmark( n, namedBookmarks )
162 | }
163 |
164 | // Delete the existing named bookmarks assigned to the current node
165 | namedBookmarks.removeAll{ k, v -> v == node.id }
166 |
167 | // Assign the key pressed to the current node
168 | namedBookmarks[ s ] = node.id
169 | namedBookmarks = namedBookmarks.sort()
170 |
171 | // Save the new namedBookmarks map
172 | saveNamedBookmarks( namedBookmarks, node.map )
173 |
174 | // Add the icon
175 | node.icons.add( namedIcon )
176 |
177 | return namedBookmarks
178 | }
179 |
180 | // Delete an existing named bookmark
181 | static JMap deleteNamedBookmark( Node node, JMap namedBookmarks )
182 | {
183 | if( namedBookmarks.containsValue( node.id ) )
184 | {
185 | // Clear the map
186 | namedBookmarks.removeAll{ key, value -> value == node.id }
187 |
188 | // Save the new namedBookmarks map
189 | saveNamedBookmarks( namedBookmarks, node.map )
190 | }
191 |
192 | // Remove the icon
193 | while( node.icons.remove( namedIcon ) ){}
194 |
195 | return namedBookmarks
196 | }
197 |
198 | // Delete any bookmark in this node
199 | static JMap deleteBookmark( Node node, JMap namedBookmarks )
200 | {
201 | if( isAnonymousBookmarked( node ) ) deleteAnonymousBookmark( node )
202 | if( isNamedBookmarked( node, namedBookmarks ) ) namedBookmarks = deleteNamedBookmark( node, namedBookmarks )
203 | return namedBookmarks
204 | }
205 |
206 | /**
207 | * Delete all bookmarks in a node and its descendants
208 | *
209 | * @param node The root of the target subtree
210 | * @param anonymous Delete anonymous bookmarks
211 | * @param named Delete named bookmarks
212 | */
213 | static void deleteSubTreeBookmarks( Node node, boolean anonymous = true, boolean named = true )
214 | {
215 | if( ! anonymous && ! named ) return
216 | JMap namedBookmarks = loadNamedBookmarks( node.map )
217 | namedBookmarks = fixNamedBookmarksInconsistency( namedBookmarks, node.map )
218 | int size = namedBookmarks.size()
219 | namedBookmarks = deleteBookmarks( [node], namedBookmarks, true, anonymous, named )
220 | }
221 |
222 | /**
223 | * Delete any bookmarks in this list of nodes.
224 | * Can delete all bookmarks in descendants nodes in recursive mode.
225 | *
226 | * @param nodes The nodes where to delete the bookmarks
227 | * @param namedBookmarks
228 | * @param recursive Also delete the bookmarks in the nodes children
229 | * @param anonymous Delete anonymous bookmarks
230 | * @param named Delete named bookmarks
231 | */
232 | private static JMap deleteBookmarks(
233 | ArrayList< Node > nodes,
234 | JMap namedBookmarks,
235 | Boolean recursive = false,
236 | boolean anonymous = true, boolean named = true
237 | ){
238 | if( ! nodes ) return namedBookmarks
239 | nodes.each{
240 | node ->
241 | if( anonymous ) deleteAnonymousBookmark( node )
242 | if( named ) deleteNamedBookmark( node, namedBookmarks )
243 | if( recursive ){
244 | namedBookmarks = deleteBookmarks( node.children, namedBookmarks, true, anonymous, named )
245 | }
246 | }
247 | return namedBookmarks
248 | }
249 |
250 | // Create a list of all the nodes with an anonymous bookmarks.
251 | // Each element of this list is a map [ id, text ] where:
252 | // - id is the node id,
253 | // - text is the node text, possibly truncated.
254 | // It is possible to exclude some node from this list.
255 | static List getAllAnonymousBookmarkedNodes( MindMap map, List excludeIds = null )
256 | {
257 | List bookmarks = []
258 | map.root.findAll().each
259 | {
260 | n ->
261 | if( isAnonymousBookmarked( n ) )
262 | {
263 | if( excludeIds && excludeIds.contains( n.id ) ) return
264 | String text = getNodeShortPlainText( n )
265 | bookmarks << [ "id": n.id, "text": text ]
266 | }
267 | }
268 | return bookmarks
269 | }
270 |
271 | // Create a list of all the nodes with a named bookmarks.
272 | // Each element of this list is a map [ id, name, text ] where:
273 | // - id is the node id,
274 | // - name is the bookmark key (string)
275 | // - text is the node text, possibly truncated, without html format.
276 | // It is possible to exclude some node from this list.
277 | static List getAllNameBookmarkedNodes( MindMap map, List excludeIds = null )
278 | {
279 | JMap bmksMap = loadNamedBookmarks( map )
280 | bmksMap = fixNamedBookmarksInconsistency( bmksMap, map )
281 |
282 | if( excludeIds )
283 | {
284 | bmksMap.removeAll{ key, id -> excludeIds.contains( id ) }
285 | }
286 |
287 | List bmksList = bmksMap.collect
288 | {
289 | key, id ->
290 | Node node = map.node( id )
291 | return [
292 | "id": id,
293 | "name": String.valueOf( (char) Integer.parseInt( key ) ),
294 | "text": getNodeShortPlainText( node )
295 | ]
296 | }
297 |
298 | return bmksList;
299 | }
300 |
301 | static ImageIcon getQuestionMarkIcon()
302 | {
303 | // Get a small question mark icon from the theme.
304 | // We can't simply call icon.getImage().getScaledInstance() because some themes (ie Nimbus)
305 | // do not return a suitable icon.getImage(). That's why we paint the icon.
306 | Icon srcIcon = UIManager.getIcon("OptionPane.questionIcon")
307 | int w = srcIcon.getIconWidth()
308 | int h = srcIcon.getIconHeight()
309 | BufferedImage bufferedImage = new BufferedImage( w, h, BufferedImage.TYPE_INT_ARGB )
310 | Graphics2D g = bufferedImage.createGraphics()
311 | srcIcon.paintIcon( null, g, 0, 0 );
312 | g.dispose()
313 | h = h / w * 16
314 | w = 16
315 | ImageIcon icon = new ImageIcon( bufferedImage.getScaledInstance( w, h, Image.SCALE_SMOOTH ) )
316 | return icon
317 | }
318 |
319 | static ImageIcon getWarningIcon()
320 | {
321 | // Get a small warning icon from the theme.
322 | // We can't simply call icon.getImage().getScaledInstance() because some themes (ie Nimbus)
323 | // do not return a suitable icon.getImage(). That's why we paint the icon.
324 | Icon srcIcon = UIManager.getIcon("OptionPane.warningIcon")
325 | int w = srcIcon.getIconWidth()
326 | int h = srcIcon.getIconHeight()
327 | BufferedImage bufferedImage = new BufferedImage( w, h, BufferedImage.TYPE_INT_ARGB )
328 | Graphics2D g = bufferedImage.createGraphics()
329 | srcIcon.paintIcon( null, g, 0, 0 );
330 | g.dispose()
331 | h = h / w * 16
332 | w = 16
333 | ImageIcon icon = new ImageIcon( bufferedImage.getScaledInstance( w, h, Image.SCALE_SMOOTH ) )
334 | return icon
335 | }
336 |
337 | }
338 |
--------------------------------------------------------------------------------
/src/main/groovy/JumpGUI.groovy:
--------------------------------------------------------------------------------
1 | package lilive.bookmarks
2 |
3 | import lilive.bookmarks.Bookmarks as BM
4 | import groovy.swing.SwingBuilder
5 | import java.awt.BorderLayout
6 | import java.awt.Component
7 | import java.awt.GridBagConstraints
8 | import java.awt.event.*
9 | import java.util.Map as JMap
10 | import javax.swing.AbstractAction
11 | import javax.swing.InputMap
12 | import javax.swing.JComponent
13 | import javax.swing.JFrame
14 | import javax.swing.JList as SwingList
15 | import javax.swing.JPanel
16 | import javax.swing.KeyStroke
17 | import org.freeplane.api.MindMap as MindMap
18 | import org.freeplane.api.Node as Node
19 | import org.freeplane.core.ui.components.UITools as ui
20 | import org.freeplane.plugin.script.proxy.Proxy.Controller as ProxyController
21 | import org.freeplane.plugin.script.proxy.Proxy.Node as ProxyNode
22 | import org.freeplane.plugin.script.proxy.ScriptUtils
23 | import org.freeplane.plugin.script.FreeplaneScriptBaseClass
24 |
25 |
26 | /**
27 | * Display a window for jumping to an existing bookmark
28 | */
29 | public class JumpGUI
30 | {
31 | static private Object gui
32 |
33 | // Build and display the window
34 | static public void show( ProxyNode node, FreeplaneScriptBaseClass.ConfigProperties config )
35 | {
36 | MindMap map = node.map
37 | gui = null
38 | SwingBuilder swing = new SwingBuilder()
39 |
40 | // Find all the bookmarks
41 | List namedBookmarks = BM.getAllNameBookmarkedNodes( map )
42 | List anonymousBookmarks = BM.getAllAnonymousBookmarkedNodes( map )
43 |
44 | // Quit the script if there is no bookmarks
45 | if( ! namedBookmarks && ! anonymousBookmarks )
46 | {
47 | ui.informationMessage( ui.currentFrame, BM.gtt( 'T_no_bookmarks' ) + " !", BM.gtt( 'T_BM_win_title' ) )
48 | return
49 | }
50 |
51 | // Create the gui
52 | gui = createWindow(
53 | swing, node, map,
54 | namedBookmarks, anonymousBookmarks,
55 | ! config.getBooleanProperty("addon_bookmarks_hide_clones")
56 | )
57 |
58 | // Center the gui over the freeplane window
59 | gui.pack()
60 | gui.setLocationRelativeTo( ui.currentFrame )
61 | gui.visible = true
62 | }
63 |
64 | // Jump to a node after the gui close
65 | static private void jumpToNodeAfterGuiDispose( ProxyNode target, String message )
66 | {
67 | // If the code to jump to a node is executed before the gui close,
68 | // it leave freeplane in a bad focus state.
69 | // This is solved by putting this code in a listener executed
70 | // after the gui destruction:
71 |
72 | ProxyController c = ScriptUtils.c()
73 |
74 | gui.addWindowListener(
75 | new WindowAdapter()
76 | {
77 | @Override
78 | public void windowClosed( WindowEvent event )
79 | {
80 | c.select( target )
81 | c.centerOnNode( target )
82 | Utils.setStatusInfo( message )
83 | }
84 | }
85 | )
86 | }
87 |
88 | // Build a GUI list component that display the named bookmarks and
89 | // that allow to jump to them.
90 | static private SwingList getNamedBookmarksSwingList(
91 | SwingBuilder swing,
92 | ProxyNode node, MindMap map,
93 | List bookmarks // List of the bookmarks
94 | ){
95 | if( ! bookmarks ) return null
96 |
97 | // Create the component
98 | SwingList component
99 | swing.build{
100 | component = list(
101 | items: bookmarks.collect
102 | {
103 | // Display for each bookmark the name of the bookmark,
104 | // followed by the text of the node
105 | if( it.id != node.id ) "