Skip to content

Commit ea8957c

Browse files
committed
Fix CommentPanel
- Use plain text as default - Add a toggle action for preview (HTML/Plain)
1 parent f4f5a99 commit ea8957c

3 files changed

Lines changed: 59 additions & 6 deletions

File tree

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/ui/CommentPanel.form

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<Component id="contentTextPane" max="32767" attributes="0"/>
2323
<Group type="102" alignment="0" attributes="0">
2424
<Component id="userLinkButton" min="-2" max="-2" attributes="0"/>
25-
<EmptySpace pref="56" max="32767" attributes="0"/>
25+
<EmptySpace pref="66" max="32767" attributes="0"/>
2626
<Component id="createdLabel" min="-2" max="-2" attributes="0"/>
2727
<EmptySpace max="-2" attributes="0"/>
2828
<Component id="createdDateLabel" min="-2" max="-2" attributes="0"/>
@@ -31,6 +31,8 @@
3131
<EmptySpace max="-2" attributes="0"/>
3232
<Component id="updatedDateLabel" min="-2" max="-2" attributes="0"/>
3333
<EmptySpace max="-2" attributes="0"/>
34+
<Component id="previewLinkButton" min="-2" max="-2" attributes="0"/>
35+
<EmptySpace max="-2" attributes="0"/>
3436
<Component id="quoteLinkButton" min="-2" max="-2" attributes="0"/>
3537
<EmptySpace max="-2" attributes="0"/>
3638
<Component id="editLinkButton" min="-2" max="-2" attributes="0"/>
@@ -56,6 +58,7 @@
5658
<Component id="editLinkButton" alignment="3" min="-2" max="-2" attributes="0"/>
5759
<Component id="quoteLinkButton" alignment="3" min="-2" max="-2" attributes="0"/>
5860
<Component id="deleteLinkButton" alignment="3" min="-2" max="-2" attributes="0"/>
61+
<Component id="previewLinkButton" alignment="3" min="-2" max="-2" attributes="0"/>
5962
</Group>
6063
<EmptySpace min="-2" max="-2" attributes="0"/>
6164
<Component id="jSeparator1" min="-2" max="-2" attributes="0"/>
@@ -122,7 +125,6 @@
122125
<EmptyBorder bottom="3" left="5" right="5" top="3"/>
123126
</Border>
124127
</Property>
125-
<Property name="contentType" type="java.lang.String" value="text/html" noResource="true"/>
126128
</Properties>
127129
</Component>
128130
<Component class="org.netbeans.modules.bugtracking.commons.LinkButton" name="quoteLinkButton">
@@ -145,5 +147,15 @@
145147
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="deleteLinkButtonActionPerformed"/>
146148
</Events>
147149
</Component>
150+
<Component class="org.netbeans.modules.bugtracking.commons.LinkButton" name="previewLinkButton">
151+
<Properties>
152+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
153+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="CommentPanel.previewLinkButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
154+
</Property>
155+
</Properties>
156+
<Events>
157+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="previewLinkButtonActionPerformed"/>
158+
</Events>
159+
</Component>
148160
</SubComponents>
149161
</Form>

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/ui/CommentPanel.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
public class CommentPanel extends javax.swing.JPanel {
5555

5656
private static final long serialVersionUID = -1191208334240462498L;
57+
private static final String HTML_MIME_TYPE = "text/html"; // NOI18N
58+
private static final String PLAIN_MIME_TYPE = "text/plain"; // NOI18N
5759

5860
private Comment comment;
5961
private boolean isQuote;
@@ -70,15 +72,20 @@ private CommentPanel() {
7072
public CommentPanel(Comment comment) {
7173
this.comment = comment;
7274
initComponents();
75+
init();
7376
load();
7477
}
7578

79+
private void init() {
80+
previewLinkButton.setText(Bundle.CommentPanel_previewLinkButton_title_html());
81+
}
82+
7683
final void load() {
7784
if (comment != null) {
7885
setUserName(comment.getUser().getLogin());
7986
setCreatedDate(comment.getCreatedAt());
8087
setUpdatedDate(comment.getUpdatedAt());
81-
setContent(comment.getBodyHtml());
88+
setContent(comment.getBody());
8289
}
8390
}
8491

@@ -165,6 +172,7 @@ private void initComponents() {
165172
contentTextPane = new javax.swing.JTextPane();
166173
quoteLinkButton = new org.netbeans.modules.bugtracking.commons.LinkButton();
167174
deleteLinkButton = new org.netbeans.modules.bugtracking.commons.LinkButton();
175+
previewLinkButton = new org.netbeans.modules.bugtracking.commons.LinkButton();
168176

169177
org.openide.awt.Mnemonics.setLocalizedText(createdLabel, org.openide.util.NbBundle.getMessage(CommentPanel.class, "CommentPanel.createdLabel.text")); // NOI18N
170178

@@ -185,7 +193,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
185193

186194
contentTextPane.setEditable(false);
187195
contentTextPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 5, 3, 5));
188-
contentTextPane.setContentType("text/html"); // NOI18N
189196

190197
org.openide.awt.Mnemonics.setLocalizedText(quoteLinkButton, org.openide.util.NbBundle.getMessage(CommentPanel.class, "CommentPanel.quoteLinkButton.text")); // NOI18N
191198
quoteLinkButton.addActionListener(new java.awt.event.ActionListener() {
@@ -201,6 +208,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
201208
}
202209
});
203210

211+
org.openide.awt.Mnemonics.setLocalizedText(previewLinkButton, org.openide.util.NbBundle.getMessage(CommentPanel.class, "CommentPanel.previewLinkButton.text")); // NOI18N
212+
previewLinkButton.addActionListener(new java.awt.event.ActionListener() {
213+
public void actionPerformed(java.awt.event.ActionEvent evt) {
214+
previewLinkButtonActionPerformed(evt);
215+
}
216+
});
217+
204218
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
205219
this.setLayout(layout);
206220
layout.setHorizontalGroup(
@@ -211,7 +225,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
211225
.addComponent(contentTextPane)
212226
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
213227
.addComponent(userLinkButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
214-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)
228+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
215229
.addComponent(createdLabel)
216230
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
217231
.addComponent(createdDateLabel)
@@ -220,6 +234,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
220234
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
221235
.addComponent(updatedDateLabel)
222236
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
237+
.addComponent(previewLinkButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
238+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
223239
.addComponent(quoteLinkButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
224240
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
225241
.addComponent(editLinkButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
@@ -240,7 +256,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
240256
.addComponent(userLinkButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
241257
.addComponent(editLinkButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
242258
.addComponent(quoteLinkButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
243-
.addComponent(deleteLinkButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
259+
.addComponent(deleteLinkButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
260+
.addComponent(previewLinkButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
244261
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
245262
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
246263
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
@@ -270,13 +287,36 @@ private void editLinkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GE
270287
firePropertyChange(CommentsPanel.PROP_COMMENT_EDITED, null, null);
271288
}//GEN-LAST:event_editLinkButtonActionPerformed
272289

290+
@NbBundle.Messages({
291+
"CommentPanel.previewLinkButton.title.html=HTML",
292+
"CommentPanel.previewLinkButton.title.plain=Plain"
293+
})
294+
private void previewLinkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_previewLinkButtonActionPerformed
295+
String text = previewLinkButton.getText();
296+
if (text.equals(Bundle.CommentPanel_previewLinkButton_title_html())) {
297+
previewLinkButton.setText(Bundle.CommentPanel_previewLinkButton_title_plain());
298+
} else {
299+
previewLinkButton.setText(Bundle.CommentPanel_previewLinkButton_title_html());
300+
}
301+
302+
String contentType = contentTextPane.getContentType();
303+
if (contentType.equals(HTML_MIME_TYPE)) {
304+
contentTextPane.setContentType(PLAIN_MIME_TYPE);
305+
contentTextPane.setText(comment.getBody());
306+
return;
307+
}
308+
contentTextPane.setContentType(HTML_MIME_TYPE);
309+
contentTextPane.setText(comment.getBodyHtml());
310+
}//GEN-LAST:event_previewLinkButtonActionPerformed
311+
273312
// Variables declaration - do not modify//GEN-BEGIN:variables
274313
private javax.swing.JTextPane contentTextPane;
275314
private javax.swing.JLabel createdDateLabel;
276315
private javax.swing.JLabel createdLabel;
277316
private org.netbeans.modules.bugtracking.commons.LinkButton deleteLinkButton;
278317
private org.netbeans.modules.bugtracking.commons.LinkButton editLinkButton;
279318
private javax.swing.JSeparator jSeparator1;
319+
private org.netbeans.modules.bugtracking.commons.LinkButton previewLinkButton;
280320
private org.netbeans.modules.bugtracking.commons.LinkButton quoteLinkButton;
281321
private javax.swing.JLabel updatedDateLabel;
282322
private javax.swing.JLabel updatedLabel;

src/main/resources/com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ MilestonePanel.dueDateLabel.text=Due Date
4848
GitHubIssuePanel.newMilestoneButton.text=New Milestone
4949
MilestonePanel.errorLabel.text=ERROR
5050
GitHubIssuePanel.newLabelButton.text=New Label
51+
CommentPanel.previewLinkButton.text=HTML

0 commit comments

Comments
 (0)