Skip to content

Commit

Permalink
Merge pull request #141 from sifran-github/main
Browse files Browse the repository at this point in the history
Added multiple examples
  • Loading branch information
sifran-github authored Dec 15, 2023
2 parents dfcf5b1 + da0d813 commit 273c057
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,15 @@
- [Security considerations](scripting/Security_considerations.md)
- [Scripting (Examples By Category)](scripting_examples/_scripting_examples.md)
- [Node Attributes](scripting_examples/_category_node.md)
- [Text, Details (TBD)]()
- [Note (TBD)]()
- [Fonts (TBD)]()
- [Text, Details, Note](scripting_examples/text_details_note.md)
- [Node Style](scripting_examples/style.md)
- [Links](scripting_examples/links.md)
- [Icons](scripting_examples/icons.md)
- [Attributes (TBD)]()
- [Attributes](scripting_examples/attributes.md)
- [Cloud (TBD)]()
- [Shape, Border (TBD)]()
- [Edges (TBD)]()
- [Layout (TBD)]()
- [Style (TBD)]()
- [Mind Map](scripting_examples/_category_map.md)
- [Mindmap Traversal](scripting_examples/traverse.md)
- [Selection](scripting_examples/selection.md)
Expand Down
Binary file added src/docs/images/examples_gui_output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/docs/images/examples_node_style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/docs/scripting_examples/attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Attributes

Set attributes:
```groovy
node["attribute_text"]="hello"
node["attribute_num"]=123
```

Get attributes:
```groovy
c.statusInfo = node["attribute_text"]
```

Get attributes properties:
```groovy
c.statusInfo = node.attributes.size()
```

Clear attributes:
```groovy
node.attributes = [:]
```
46 changes: 45 additions & 1 deletion src/docs/scripting_examples/gui.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,51 @@ c.statusInfo=result

### Simple Msgbox
```groovy
script1 import org.freeplane.core.ui.components.UITools;
import org.freeplane.core.ui.components.UITools;
UITools.informationMessage('Simple Messagebox')
```

### Display output in a window (+ copy button)
Code for displaying some output text in a window. Useful when running some function that returns an output.

```groovy
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
def copy_textarea_to_clipboard(JTextArea textArea) {
textUtils.copyToClipboard(textArea.getText());
textArea.requestFocusInWindow();
textArea.selectAll();
}
def show_output_window(String txt, String title="", int width=600, int height=400) {
JFrame frame = new JFrame(title);
JTextArea textArea = new JTextArea();
textArea.setText(txt);
textArea.setLineWrap(false);
textArea.setWrapStyleWord(false);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setPreferredSize(new Dimension(width, height));
JButton copyButton = new JButton("Copy to Clipboard");
copyButton.addActionListener(e -> copy_textarea_to_clipboard(textArea));
JPanel contentPane = new JPanel(new BorderLayout());
contentPane.add(scrollPane, BorderLayout.CENTER);
contentPane.add(copyButton, BorderLayout.SOUTH);
frame.setContentPane(contentPane);
frame.pack();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
show_output_window("This is an example of an output text that will be displayed in a window.", "Output Window");
```

result:

![output window](../images/examples_gui_output.png "output window")
17 changes: 17 additions & 0 deletions src/docs/scripting_examples/style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Node Style

```groovy
node.style.font.size = 20
node.style.font.name = "Arial"
node.style.setTextColorCode("#ff0000")
node.style.setBackgroundColorCode("#000000")
node.style.edge.setColorCode("#00ff00")
```

Result:

![node style](../images/examples_node_style.png "node style")

## Details & Notes Style
Can't be done with attributes? only html?
[Workaround](https://sourceforge.net/p/freeplane/discussion/758437/thread/08695c2617/)
9 changes: 9 additions & 0 deletions src/docs/scripting_examples/text_details_note.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Text, Details, Notes

How to change text and details:

```groovy
node.text = "node text"
node.details = "node details"
node.note = "node notes"
```

0 comments on commit 273c057

Please sign in to comment.