summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Yanis482020-05-25 16:48:12 +0200
committerGravatar GitHub2020-05-25 10:48:12 -0400
commitd82f83e6a698f29ee14897ce7666d6f095349dc4 (patch)
tree4f6057ba42f44d5c6861d7712b117e2bb4d28fff
parentAsync search (#245) (diff)
downloadenigma-d82f83e6a698f29ee14897ce7666d6f095349dc4.tar.gz
enigma-d82f83e6a698f29ee14897ce7666d6f095349dc4.tar.xz
enigma-d82f83e6a698f29ee14897ce7666d6f095349dc4.zip
Add tags to javadoc dialog (#248)
* Add tags to javadoc dialog * improvements when you have a text selected
-rw-r--r--build.gradle2
-rw-r--r--src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java69
2 files changed, 70 insertions, 1 deletions
diff --git a/build.gradle b/build.gradle
index 0d744a36..ba2d86c4 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ plugins {
5} 5}
6 6
7group = 'cuchaz' 7group = 'cuchaz'
8version = '0.16.0' 8version = '0.16.1'
9 9
10def generatedSourcesDir = "$buildDir/generated-src" 10def generatedSourcesDir = "$buildDir/generated-src"
11 11
diff --git a/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java b/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java
index b2c159d7..7e414419 100644
--- a/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java
+++ b/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java
@@ -16,6 +16,8 @@ import cuchaz.enigma.gui.util.ScaleUtil;
16import cuchaz.enigma.utils.Utils; 16import cuchaz.enigma.utils.Utils;
17 17
18import javax.swing.*; 18import javax.swing.*;
19import javax.swing.text.html.HTML;
20
19import java.awt.*; 21import java.awt.*;
20import java.awt.event.KeyAdapter; 22import java.awt.event.KeyAdapter;
21import java.awt.event.KeyEvent; 23import java.awt.event.KeyEvent;
@@ -72,6 +74,50 @@ public class JavadocDialog {
72 buttonsPanel.add(saveButton); 74 buttonsPanel.add(saveButton);
73 pane.add(buttonsPanel, BorderLayout.SOUTH); 75 pane.add(buttonsPanel, BorderLayout.SOUTH);
74 76
77 // tags panel
78 JMenuBar tagsMenu = new JMenuBar();
79
80 // add javadoc tags
81 for (JavadocTag tag : JavadocTag.values()) {
82 JButton tagButton = new JButton(tag.getText());
83 tagButton.addActionListener(action -> {
84 boolean textSelected = text.getSelectedText() != null;
85 String tagText = tag.isInline() ? "{" + tag.getText() + " }" : tag.getText() + " ";
86
87 if (textSelected) {
88 if (tag.isInline()) {
89 tagText = "{" + tag.getText() + " " + text.getSelectedText() + "}";
90 } else {
91 tagText = tag.getText() + " " + text.getSelectedText();
92 }
93 text.replaceSelection(tagText);
94 } else {
95 text.insert(tagText, text.getCaretPosition());
96 }
97
98 if (tag.isInline()) {
99 text.setCaretPosition(text.getCaretPosition() - 1);
100 }
101 text.grabFocus();
102 });
103 tagsMenu.add(tagButton);
104 }
105
106 // add html tags
107 JComboBox<String> htmlList = new JComboBox<String>();
108 htmlList.setPreferredSize(new Dimension());
109 for (HTML.Tag htmlTag : HTML.getAllTags()) {
110 htmlList.addItem(htmlTag.toString());
111 }
112 htmlList.addActionListener(action -> {
113 String tagText = "<" + htmlList.getSelectedItem().toString() + ">";
114 text.insert(tagText, text.getCaretPosition());
115 text.grabFocus();
116 });
117 tagsMenu.add(htmlList);
118
119 pane.add(tagsMenu, BorderLayout.NORTH);
120
75 // show the frame 121 // show the frame
76 frame.setSize(ScaleUtil.getDimension(600, 400)); 122 frame.setSize(ScaleUtil.getDimension(600, 400));
77 frame.setLocationRelativeTo(parent); 123 frame.setLocationRelativeTo(parent);
@@ -87,4 +133,27 @@ public class JavadocDialog {
87 public interface Callback { 133 public interface Callback {
88 void closeUi(JFrame frame, boolean save); 134 void closeUi(JFrame frame, boolean save);
89 } 135 }
136
137 private enum JavadocTag {
138 CODE(true),
139 LINK(true),
140 LINKPLAIN(true),
141 RETURN(false),
142 SEE(false),
143 THROWS(false);
144
145 private boolean inline;
146
147 private JavadocTag(boolean inline) {
148 this.inline = inline;
149 }
150
151 public String getText() {
152 return "@" + this.name().toLowerCase();
153 }
154
155 public boolean isInline() {
156 return this.inline;
157 }
158 }
90} 159}