2021-07-16 00:37:03 +02:00
|
|
|
|
|
|
|
import javax.swing.JFrame;
|
2021-07-16 01:07:23 +02:00
|
|
|
import javax.swing.JPanel;
|
2021-07-16 00:37:03 +02:00
|
|
|
import javax.swing.JMenuBar;
|
2022-04-28 03:56:25 +02:00
|
|
|
import javax.swing.JPopupMenu;
|
2021-07-29 10:03:32 +02:00
|
|
|
import javax.swing.JMenuItem;
|
2021-07-16 01:07:23 +02:00
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.JLabel;
|
2022-04-19 16:08:20 +02:00
|
|
|
import javax.swing.JScrollPane;
|
|
|
|
import javax.swing.JScrollBar;
|
2021-07-16 01:07:23 +02:00
|
|
|
import javax.swing.Box;
|
2022-04-12 08:37:39 +02:00
|
|
|
import javax.swing.BoxLayout;
|
2021-07-16 01:07:23 +02:00
|
|
|
import javax.swing.BorderFactory;
|
2022-04-12 08:37:39 +02:00
|
|
|
import javax.swing.border.Border;
|
|
|
|
import javax.swing.JOptionPane;
|
2022-04-12 13:52:07 +02:00
|
|
|
import javax.swing.ImageIcon;
|
2021-07-16 01:07:23 +02:00
|
|
|
import java.awt.Graphics;
|
2022-04-12 08:37:39 +02:00
|
|
|
import java.awt.Font;
|
2021-07-29 10:03:32 +02:00
|
|
|
import java.awt.FontMetrics;
|
2022-04-12 08:37:39 +02:00
|
|
|
import java.awt.Shape;
|
2021-07-16 00:37:03 +02:00
|
|
|
import java.awt.Dimension;
|
2021-07-16 01:07:23 +02:00
|
|
|
import java.awt.BorderLayout;
|
|
|
|
import java.awt.GridLayout;
|
2022-04-12 08:37:39 +02:00
|
|
|
import java.awt.Cursor;
|
2022-04-12 13:52:07 +02:00
|
|
|
import java.awt.Image;
|
2022-04-14 06:38:49 +02:00
|
|
|
import java.awt.Component;
|
2021-07-29 10:03:32 +02:00
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
import java.awt.event.ActionEvent;
|
2021-07-16 01:07:23 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.ArrayList;
|
2022-04-15 14:54:31 +02:00
|
|
|
import java.net.URL;
|
|
|
|
import java.net.MalformedURLException;
|
2022-04-12 08:37:39 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import cafe.biskuteri.hinoki.Tree;
|
2022-04-15 19:07:22 +02:00
|
|
|
import java.text.BreakIterator;
|
|
|
|
import java.util.Locale;
|
2022-04-23 16:19:43 +02:00
|
|
|
import java.time.ZonedDateTime;
|
|
|
|
import java.time.ZoneId;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
|
2021-07-16 00:37:03 +02:00
|
|
|
|
|
|
|
class
|
2021-07-29 10:03:32 +02:00
|
|
|
PostWindow extends JFrame
|
|
|
|
implements ActionListener {
|
2021-07-16 00:37:03 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
private JKomasto
|
|
|
|
primaire;
|
|
|
|
|
|
|
|
private MastodonApi
|
|
|
|
api;
|
|
|
|
|
2022-04-23 16:19:43 +02:00
|
|
|
private Tree<String>
|
|
|
|
post;
|
2021-07-16 11:46:17 +02:00
|
|
|
|
|
|
|
// - -%- -
|
|
|
|
|
2021-07-16 00:37:03 +02:00
|
|
|
private PostComponent
|
2021-07-16 11:46:17 +02:00
|
|
|
postDisplay;
|
2021-07-16 00:37:03 +02:00
|
|
|
|
|
|
|
private RepliesComponent
|
2021-07-16 11:46:17 +02:00
|
|
|
repliesDisplay;
|
2021-07-16 00:37:03 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
// - -%- -
|
|
|
|
|
|
|
|
private static final DateTimeFormatter
|
|
|
|
DATE_FORMAT = DateTimeFormatter.ofPattern("d LLLL ''uu"),
|
|
|
|
TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm");
|
|
|
|
|
2021-07-29 10:03:32 +02:00
|
|
|
// ---%-@-%---
|
2021-07-17 13:17:14 +02:00
|
|
|
|
2022-04-23 16:19:43 +02:00
|
|
|
public void
|
|
|
|
displayEntity(Tree<String> post)
|
|
|
|
{
|
2021-07-29 10:03:32 +02:00
|
|
|
this.post = post;
|
|
|
|
|
2022-04-23 16:19:43 +02:00
|
|
|
Tree<String> boosted = post.get("reblog");
|
|
|
|
if (boosted.size() > 0) post = boosted;
|
|
|
|
|
|
|
|
Tree<String> author = post.get("account");
|
|
|
|
Tree<String> emojis = post.get("emojis");
|
|
|
|
Tree<String> media = post.get("media_attachments");
|
|
|
|
|
|
|
|
String an = author.get("display_name").value;
|
|
|
|
if (an.isEmpty()) an = author.get("username").value;
|
|
|
|
postDisplay.setAuthorName(an);
|
|
|
|
postDisplay.setAuthorId(author.get("acct").value);
|
|
|
|
|
2022-04-28 03:56:25 +02:00
|
|
|
String aid = author.get("id").value;
|
|
|
|
String oid = api.getAccountDetails().get("id").value;
|
|
|
|
postDisplay.setDeleteEnabled(aid.equals(oid));
|
|
|
|
|
2022-04-23 16:19:43 +02:00
|
|
|
String avurl = author.get("avatar").value;
|
|
|
|
postDisplay.setAuthorAvatar(ImageApi.remote(avurl));
|
|
|
|
|
|
|
|
String sdate = post.get("created_at").value;
|
|
|
|
ZonedDateTime date = ZonedDateTime.parse(sdate);
|
|
|
|
date = date.withZoneSameInstant(ZoneId.systemDefault());
|
|
|
|
postDisplay.setDate(DATE_FORMAT.format(date));
|
|
|
|
postDisplay.setTime(TIME_FORMAT.format(date));
|
|
|
|
|
|
|
|
String[][] emojiUrls = new String[emojis.size()][];
|
|
|
|
for (int o = 0; o < emojiUrls.length; ++o) {
|
|
|
|
Tree<String> emoji = emojis.get(o);
|
|
|
|
emojiUrls[o] = new String[2];
|
|
|
|
emojiUrls[o][0] = emoji.get("shortcode").value;
|
|
|
|
emojiUrls[o][1] = emoji.get("url").value;
|
|
|
|
}
|
|
|
|
postDisplay.setEmojiUrls(emojiUrls);
|
|
|
|
|
|
|
|
postDisplay.setHtml(post.get("content").value);
|
|
|
|
boolean f = post.get("favourited").value.equals("true");
|
|
|
|
boolean b = post.get("reblogged").value.equals("true");
|
|
|
|
postDisplay.setFavourited(f);
|
|
|
|
postDisplay.setBoosted(b);
|
|
|
|
|
2022-04-27 10:17:02 +02:00
|
|
|
if (media.size() > 0)
|
2022-04-23 16:19:43 +02:00
|
|
|
{
|
|
|
|
Tree<String> first = media.get(0);
|
|
|
|
String u1 = first.get("remote_url").value;
|
|
|
|
String u2 = first.get("text_url").value;
|
|
|
|
String u3 = first.get("url").value;
|
|
|
|
String purl = u1 != null ? u1 : u2 != null ? u2 : u3;
|
|
|
|
postDisplay.setMediaPreview(ImageApi.remote(purl));
|
|
|
|
}
|
|
|
|
else postDisplay.setMediaPreview(null);
|
2021-07-29 11:26:16 +02:00
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
postDisplay.resetFocus();
|
2022-04-12 08:37:39 +02:00
|
|
|
repaint();
|
2021-07-17 13:17:14 +02:00
|
|
|
}
|
|
|
|
|
2021-07-31 13:36:56 +02:00
|
|
|
public void
|
|
|
|
openAuthorProfile()
|
|
|
|
{
|
2022-04-23 16:19:43 +02:00
|
|
|
Tree<String> post = this.post;
|
|
|
|
Tree<String> boosted = post.get("reblog");
|
|
|
|
if (boosted.size() > 0) post = boosted;
|
|
|
|
|
|
|
|
TimelineWindow w = new TimelineWindow(primaire);
|
|
|
|
w.showAuthorPosts(post.get("account").get("id").value);
|
2022-04-14 06:38:49 +02:00
|
|
|
w.showLatestPage();
|
|
|
|
w.setLocationRelativeTo(this);
|
|
|
|
w.setVisible(true);
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
2022-04-12 08:37:39 +02:00
|
|
|
favourite(boolean favourited)
|
2021-07-31 13:36:56 +02:00
|
|
|
{
|
2022-04-23 16:19:43 +02:00
|
|
|
Tree<String> post = this.post;
|
|
|
|
Tree<String> boosted = post.get("reblog");
|
|
|
|
if (boosted.size() > 0) post = boosted;
|
2022-04-27 10:17:02 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
postDisplay.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
|
|
|
postDisplay.setFavouriteBoostEnabled(false);
|
|
|
|
postDisplay.paintImmediately(postDisplay.getBounds());
|
|
|
|
RequestListener handler = new RequestListener() {
|
|
|
|
|
|
|
|
public void
|
|
|
|
connectionFailed(IOException eIo)
|
|
|
|
{
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
PostWindow.this,
|
|
|
|
"Tried to favourite post, failed.."
|
|
|
|
+ "\n" + eIo.getClass() + ": " + eIo.getMessage()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestFailed(int httpCode, Tree<String> json)
|
|
|
|
{
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
PostWindow.this,
|
|
|
|
"Tried to favourite post, failed.."
|
|
|
|
+ "\n" + json.get("error").value
|
|
|
|
+ "\n(HTTP error code: " + httpCode + ")"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestSucceeded(Tree<String> json)
|
|
|
|
{
|
2022-04-23 16:19:43 +02:00
|
|
|
String n = Boolean.toString(favourited);
|
|
|
|
PostWindow.this.post.get("favourited").value = n;
|
2022-04-12 08:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2022-04-23 16:19:43 +02:00
|
|
|
String postId = post.get("id").value;
|
|
|
|
api.setPostFavourited(postId, favourited, handler);
|
2022-04-12 08:37:39 +02:00
|
|
|
postDisplay.setCursor(null);
|
2022-04-14 06:38:49 +02:00
|
|
|
postDisplay.setFavouriteBoostEnabled(true);
|
|
|
|
postDisplay.repaint();
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
2022-04-12 08:37:39 +02:00
|
|
|
boost(boolean boosted)
|
2021-07-31 13:36:56 +02:00
|
|
|
{
|
2022-04-23 16:19:43 +02:00
|
|
|
Tree<String> post = this.post;
|
|
|
|
Tree<String> boosted2 = post.get("reblog");
|
|
|
|
if (boosted2.size() > 0) post = boosted2;
|
2022-04-27 10:17:02 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
postDisplay.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
|
|
|
postDisplay.setFavouriteBoostEnabled(false);
|
|
|
|
postDisplay.paintImmediately(postDisplay.getBounds());
|
|
|
|
RequestListener handler = new RequestListener() {
|
|
|
|
|
|
|
|
public void
|
|
|
|
connectionFailed(IOException eIo)
|
|
|
|
{
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
PostWindow.this,
|
|
|
|
"Tried to boost post, failed.."
|
|
|
|
+ "\n" + eIo.getClass() + ": " + eIo.getMessage()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestFailed(int httpCode, Tree<String> json)
|
|
|
|
{
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
PostWindow.this,
|
|
|
|
"Tried to boost post, failed.."
|
|
|
|
+ "\n" + json.get("error").value
|
|
|
|
+ "\n(HTTP error code: " + httpCode + ")"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestSucceeded(Tree<String> json)
|
|
|
|
{
|
2022-04-23 16:19:43 +02:00
|
|
|
String n = Boolean.toString(boosted);
|
|
|
|
PostWindow.this.post.get("reblogged").value = n;
|
2022-04-12 08:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2022-04-23 16:19:43 +02:00
|
|
|
String postId = post.get("id").value;
|
|
|
|
api.setPostBoosted(postId, boosted, handler);
|
2022-04-12 08:37:39 +02:00
|
|
|
postDisplay.setCursor(null);
|
2022-04-14 06:38:49 +02:00
|
|
|
postDisplay.setFavouriteBoostEnabled(true);
|
|
|
|
postDisplay.repaint();
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
reply()
|
|
|
|
{
|
2022-04-23 16:19:43 +02:00
|
|
|
Tree<String> post = this.post;
|
|
|
|
Tree<String> boosted = post.get("reblog");
|
|
|
|
if (boosted.size() > 0) post = boosted;
|
|
|
|
|
|
|
|
String authorId = post.get("account").get("acct").value;
|
|
|
|
String postId = post.get("id").value;
|
|
|
|
String cw = post.get("spoiler_text").value;
|
|
|
|
|
2022-04-23 16:28:29 +02:00
|
|
|
String id1 = post.get("account").get("id").value;
|
|
|
|
String id2 = api.getAccountDetails().get("id").value;
|
2022-04-27 10:17:02 +02:00
|
|
|
|
2022-04-23 16:19:43 +02:00
|
|
|
String vs = post.get("visibility").value;
|
|
|
|
PostVisibility v = null;
|
|
|
|
if (vs.equals("public")) v = PostVisibility.PUBLIC;
|
|
|
|
if (vs.equals("unlisted")) v = PostVisibility.UNLISTED;
|
|
|
|
if (vs.equals("private")) v = PostVisibility.FOLLOWERS;
|
|
|
|
if (vs.equals("direct")) v = PostVisibility.MENTIONED;
|
2022-04-28 03:56:25 +02:00
|
|
|
|
2022-04-23 16:19:43 +02:00
|
|
|
Composition c = new Composition();
|
|
|
|
c.contentWarning = cw;
|
2022-04-23 16:28:29 +02:00
|
|
|
c.text = id1.equals(id2) ? "" : "@" + authorId + " ";
|
2022-04-23 16:19:43 +02:00
|
|
|
c.visibility = v;
|
|
|
|
c.replyToPostId = postId;
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
ComposeWindow w = primaire.getComposeWindow();
|
|
|
|
w.setLocation(getX(), getY() + 100);
|
|
|
|
w.setVisible(true);
|
2022-04-23 16:19:43 +02:00
|
|
|
w.setComposition(c);
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
openMedia()
|
|
|
|
{
|
2022-04-27 10:17:02 +02:00
|
|
|
Tree<String> post = this.post;
|
|
|
|
Tree<String> boosted = post.get("reblog");
|
|
|
|
if (boosted.size() > 0) post = boosted;
|
2022-04-23 16:19:43 +02:00
|
|
|
Tree<String> media = post.get("media_attachments");
|
2022-04-27 10:17:02 +02:00
|
|
|
|
2022-04-23 16:19:43 +02:00
|
|
|
Attachment[] as = new Attachment[media.size()];
|
|
|
|
for (int o = 0; o < as.length; ++o)
|
|
|
|
{
|
|
|
|
Tree<String> medium = media.get(o);
|
|
|
|
String u1 = medium.get("remote_url").value;
|
|
|
|
String u2 = medium.get("text_url").value;
|
|
|
|
String u3 = medium.get("url").value;
|
2022-04-27 10:17:02 +02:00
|
|
|
|
2022-04-23 16:19:43 +02:00
|
|
|
Attachment a = as[o] = new Attachment();
|
|
|
|
a.url = u1 != null ? u1 : u2 != null ? u2 : u3;
|
|
|
|
a.type = medium.get("type").value;
|
|
|
|
a.description = medium.get("description").value;
|
|
|
|
a.image = ImageApi.remote(a.url);
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
ImageWindow w = primaire.getMediaWindow();
|
2022-04-23 16:19:43 +02:00
|
|
|
w.setTitle(post.get("id").value);
|
|
|
|
w.showAttachments(as);
|
2022-04-12 13:52:07 +02:00
|
|
|
if (!w.isVisible()) {
|
2022-04-14 06:38:49 +02:00
|
|
|
w.setLocationRelativeTo(null);
|
2022-04-12 13:52:07 +02:00
|
|
|
w.setVisible(true);
|
|
|
|
}
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
2022-04-28 03:56:25 +02:00
|
|
|
public void
|
|
|
|
deletePost(boolean redraft)
|
|
|
|
{
|
|
|
|
postDisplay.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
|
|
|
postDisplay.setDeleteEnabled(false);
|
|
|
|
postDisplay.paintImmediately(postDisplay.getBounds());
|
|
|
|
|
|
|
|
if (redraft)
|
|
|
|
{
|
|
|
|
String html = post.get("content").value;
|
|
|
|
StringBuilder b = new StringBuilder();
|
|
|
|
Tree<String> nodes;
|
|
|
|
nodes = RudimentaryHTMLParser.depthlessRead(html);
|
|
|
|
// We have to salvage whatever we can from the HTML.
|
|
|
|
for (Tree<String> node: nodes)
|
|
|
|
{
|
|
|
|
if (node.key.equals("text"))
|
|
|
|
{
|
|
|
|
b.append(node.value);
|
|
|
|
}
|
|
|
|
if (node.key.equals("emoji"))
|
|
|
|
{
|
|
|
|
b.append(":" + node.value + ":");
|
|
|
|
}
|
|
|
|
if (node.key.equals("tag"))
|
|
|
|
{
|
|
|
|
if (node.get(0).key.equals("/p"))
|
|
|
|
b.append("\n\n");
|
|
|
|
if (node.get(0).key.equals("br"))
|
|
|
|
b.append("\n");
|
|
|
|
if (node.get(0).key.equals("a")) {
|
|
|
|
b.append(node.get("href").value);
|
|
|
|
b.append(" ");
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* We don't omit the contents of the <a>
|
|
|
|
* which is an automatic label, but we'll
|
|
|
|
* need a non-depthless parser to omit that.
|
|
|
|
* For now prioritise not losing anything
|
|
|
|
* from our composition.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
// I think that's all. I hope.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String cw = post.get("spoiler_text").value;
|
|
|
|
|
|
|
|
String vs = post.get("visibility").value;
|
|
|
|
PostVisibility v = null;
|
|
|
|
if (vs.equals("public")) v = PostVisibility.PUBLIC;
|
|
|
|
if (vs.equals("unlisted")) v = PostVisibility.UNLISTED;
|
|
|
|
if (vs.equals("private")) v = PostVisibility.FOLLOWERS;
|
|
|
|
if (vs.equals("direct")) v = PostVisibility.MENTIONED;
|
|
|
|
|
|
|
|
String replyTo = post.get("in_reply_to_id").value;
|
|
|
|
|
|
|
|
Composition c = new Composition();
|
|
|
|
c.contentWarning = cw;
|
|
|
|
c.text = b.toString();
|
|
|
|
c.visibility = v;
|
|
|
|
c.replyToPostId = replyTo;
|
|
|
|
|
|
|
|
ComposeWindow w = primaire.getComposeWindow();
|
|
|
|
w.setLocation(getX(), getY() + 100);
|
|
|
|
w.setVisible(true);
|
|
|
|
w.setComposition(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.deletePost(post.get("id").value, new RequestListener() {
|
|
|
|
|
|
|
|
public void
|
|
|
|
connectionFailed(IOException eIo)
|
|
|
|
{
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
PostWindow.this,
|
|
|
|
"Failed to delete post.."
|
|
|
|
+ "\n" + eIo.getMessage()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestFailed(int httpCode, Tree<String> json)
|
|
|
|
{
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
PostWindow.this,
|
|
|
|
"Failed to delete post.."
|
|
|
|
+ "\n" + json.get("error").value
|
|
|
|
+ "\n(HTTP code: " + httpCode + ")"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestSucceeded(Tree<String> json)
|
|
|
|
{
|
|
|
|
setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
postDisplay.setCursor(null);
|
|
|
|
postDisplay.setDeleteEnabled(true);
|
|
|
|
postDisplay.paintImmediately(postDisplay.getBounds());
|
|
|
|
if (!isVisible()) dispose();
|
|
|
|
}
|
|
|
|
|
2021-07-29 10:03:32 +02:00
|
|
|
// - -%- -
|
2021-07-17 11:46:27 +02:00
|
|
|
|
|
|
|
public void
|
2021-07-29 10:03:32 +02:00
|
|
|
actionPerformed(ActionEvent eA)
|
2021-07-17 11:46:27 +02:00
|
|
|
{
|
2022-04-14 06:38:49 +02:00
|
|
|
Component src = (Component)eA.getSource();
|
2021-07-29 10:03:32 +02:00
|
|
|
if (!(src instanceof JMenuItem)) return;
|
|
|
|
String text = ((JMenuItem)src).getText();
|
|
|
|
|
|
|
|
if (text.equals("Post"))
|
|
|
|
{
|
|
|
|
setContentPane(postDisplay);
|
|
|
|
revalidate();
|
|
|
|
/*
|
|
|
|
* (知) Setting a content pane in itself doesn't
|
|
|
|
* do anything to the content pane. Validation
|
|
|
|
* of the validate root does. Which happens on
|
|
|
|
* window realisation, or by manual call.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else if (text.equals("Replies"))
|
|
|
|
{
|
|
|
|
setContentPane(repliesDisplay);
|
|
|
|
revalidate();
|
|
|
|
}
|
2021-07-17 11:46:27 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 00:37:03 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
PostWindow(JKomasto primaire)
|
2021-07-16 00:37:03 +02:00
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
this.primaire = primaire;
|
|
|
|
this.api = primaire.getMastodonApi();
|
|
|
|
|
2021-07-16 11:46:17 +02:00
|
|
|
getContentPane().setPreferredSize(new Dimension(360, 270));
|
|
|
|
pack();
|
|
|
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
2021-07-16 00:37:03 +02:00
|
|
|
setLocationByPlatform(true);
|
|
|
|
|
2021-07-31 13:36:56 +02:00
|
|
|
postDisplay = new PostComponent(this);
|
2021-07-16 11:46:17 +02:00
|
|
|
repliesDisplay = new RepliesComponent();
|
2021-07-29 10:03:32 +02:00
|
|
|
|
2021-07-17 11:46:27 +02:00
|
|
|
setContentPane(postDisplay);
|
2021-07-29 10:03:32 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 00:37:03 +02:00
|
|
|
}
|
2021-07-16 01:07:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class
|
2021-07-31 13:36:56 +02:00
|
|
|
PostComponent extends JPanel
|
|
|
|
implements ActionListener {
|
|
|
|
|
|
|
|
private PostWindow
|
|
|
|
primaire;
|
2021-07-16 01:07:23 +02:00
|
|
|
|
2021-07-31 13:28:46 +02:00
|
|
|
// - -%- -
|
|
|
|
|
2022-04-15 14:54:31 +02:00
|
|
|
private List<RichTextPane.Segment>
|
|
|
|
authorNameOr, bodyOr;
|
|
|
|
|
|
|
|
private RichTextPane
|
|
|
|
authorName, body;
|
|
|
|
|
|
|
|
private JLabel
|
|
|
|
authorId, time, date;
|
|
|
|
|
|
|
|
private String[][]
|
|
|
|
emojiUrls;
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
private TwoToggleButton
|
2021-07-31 13:28:46 +02:00
|
|
|
favouriteBoost,
|
|
|
|
replyMisc,
|
2022-04-12 08:37:39 +02:00
|
|
|
nextPrev;
|
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
private RoundButton
|
2022-04-12 08:37:39 +02:00
|
|
|
profile,
|
2021-07-31 13:28:46 +02:00
|
|
|
media;
|
|
|
|
|
2022-04-28 03:56:25 +02:00
|
|
|
private JPopupMenu
|
|
|
|
miscMenu;
|
|
|
|
|
|
|
|
private JMenuItem
|
|
|
|
deletePost,
|
|
|
|
redraftPost;
|
|
|
|
|
2021-07-16 01:07:23 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public void
|
2022-04-15 14:54:31 +02:00
|
|
|
setAuthorName(String n)
|
|
|
|
{
|
|
|
|
authorNameOr = new RichTextPane.Builder().text(n).finish();
|
|
|
|
}
|
2022-04-12 08:37:39 +02:00
|
|
|
|
|
|
|
public void
|
2022-04-15 14:54:31 +02:00
|
|
|
setAuthorId(String n) { authorId.setText(n); }
|
2022-04-12 13:52:07 +02:00
|
|
|
|
|
|
|
public void
|
|
|
|
setAuthorAvatar(Image n) { profile.setImage(n); }
|
2022-04-12 08:37:39 +02:00
|
|
|
|
|
|
|
public void
|
2022-04-15 14:54:31 +02:00
|
|
|
setDate(String n) { date.setText(n); }
|
2021-07-16 01:07:23 +02:00
|
|
|
|
|
|
|
public void
|
2022-04-15 14:54:31 +02:00
|
|
|
setTime(String n) { time.setText(n); }
|
2021-07-16 01:07:23 +02:00
|
|
|
|
2022-04-15 14:54:31 +02:00
|
|
|
public void
|
|
|
|
setEmojiUrls(String[][] n) { emojiUrls = n; }
|
|
|
|
|
|
|
|
public void
|
|
|
|
setHtml(String n)
|
|
|
|
{
|
|
|
|
RichTextPane.Builder b = new RichTextPane.Builder();
|
|
|
|
Tree<String> nodes = RudimentaryHTMLParser.depthlessRead(n);
|
|
|
|
for (Tree<String> node: nodes)
|
|
|
|
{
|
|
|
|
if (node.key.equals("tag"))
|
|
|
|
{
|
|
|
|
String tagName = node.get(0).key;
|
|
|
|
if (tagName.equals("br"))
|
|
|
|
b = b.spacer("\n");
|
|
|
|
if (tagName.equals("/p"))
|
|
|
|
b = b.spacer("\n").spacer("\n");
|
|
|
|
if (tagName.equals("a"))
|
|
|
|
b = b.link(node.get("href").value, null).spacer(" ");
|
|
|
|
}
|
|
|
|
if (node.key.equals("text"))
|
|
|
|
{
|
2022-04-15 19:07:22 +02:00
|
|
|
BreakIterator it = BreakIterator.getWordInstance(Locale.ROOT);
|
|
|
|
String text = node.value;
|
|
|
|
it.setText(text);
|
|
|
|
int start = it.first(), end = it.next();
|
|
|
|
while (end != BreakIterator.DONE)
|
|
|
|
{
|
|
|
|
String word = text.substring(start, end);
|
|
|
|
char c = word.isEmpty() ? ' ' : word.charAt(0);
|
|
|
|
boolean w = Character.isWhitespace(c);
|
|
|
|
b = w ? b.spacer(word) : b.text(word);
|
|
|
|
start = end;
|
|
|
|
end = it.next();
|
|
|
|
}
|
2022-04-15 14:54:31 +02:00
|
|
|
}
|
|
|
|
if (node.key.equals("emoji"))
|
|
|
|
{
|
|
|
|
String shortcode = node.value;
|
|
|
|
String url = null;
|
|
|
|
for (String[] entry: emojiUrls)
|
|
|
|
if (entry[0].equals(shortcode)) url = entry[1];
|
|
|
|
try {
|
|
|
|
ImageIcon image = new ImageIcon(new URL(url));
|
|
|
|
b = b.image(image, node.value);
|
|
|
|
}
|
|
|
|
catch (MalformedURLException eMu) {
|
2022-04-19 16:08:20 +02:00
|
|
|
b = b.text(":" + shortcode + ":");
|
2022-04-15 14:54:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bodyOr = b.finish();
|
|
|
|
}
|
2021-07-16 01:07:23 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
public void
|
|
|
|
setFavourited(boolean a)
|
|
|
|
{
|
|
|
|
favouriteBoost.removeActionListener(this);
|
|
|
|
favouriteBoost.setPrimaryToggled(a);
|
|
|
|
favouriteBoost.addActionListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
setBoosted(boolean a)
|
|
|
|
{
|
|
|
|
favouriteBoost.removeActionListener(this);
|
|
|
|
favouriteBoost.setSecondaryToggled(a);
|
|
|
|
favouriteBoost.addActionListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
setFavouriteBoostEnabled(boolean a)
|
|
|
|
{
|
|
|
|
favouriteBoost.setEnabled(a);
|
|
|
|
}
|
|
|
|
|
2022-04-28 03:56:25 +02:00
|
|
|
public void
|
|
|
|
setDeleteEnabled(boolean a)
|
|
|
|
{
|
|
|
|
deletePost.setEnabled(a);
|
|
|
|
redraftPost.setEnabled(a);
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
public void
|
|
|
|
setMediaPreview(Image n) { media.setImage(n); }
|
|
|
|
|
|
|
|
public void
|
|
|
|
resetFocus() { media.requestFocusInWindow(); }
|
|
|
|
|
2021-07-16 01:07:23 +02:00
|
|
|
// - -%- -
|
|
|
|
|
2021-07-31 13:36:56 +02:00
|
|
|
public void
|
|
|
|
actionPerformed(ActionEvent eA)
|
|
|
|
{
|
2022-04-14 06:38:49 +02:00
|
|
|
Component src = (Component)eA.getSource();
|
2022-04-12 08:37:39 +02:00
|
|
|
String command = eA.getActionCommand();
|
2021-07-31 13:36:56 +02:00
|
|
|
|
|
|
|
if (src == profile)
|
|
|
|
{
|
|
|
|
primaire.openAuthorProfile();
|
2022-04-12 08:37:39 +02:00
|
|
|
return;
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
2022-04-12 08:37:39 +02:00
|
|
|
|
|
|
|
if (src == favouriteBoost)
|
2021-07-31 13:36:56 +02:00
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
if (command.equals("favouriteOn"))
|
|
|
|
primaire.favourite(true);
|
|
|
|
if (command.equals("favouriteOff"))
|
|
|
|
primaire.favourite(false);
|
|
|
|
if (command.equals("boostOn"))
|
|
|
|
primaire.boost(true);
|
|
|
|
if (command.equals("boostOff"))
|
|
|
|
primaire.boost(false);
|
|
|
|
return;
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
if (src == replyMisc)
|
|
|
|
{
|
2022-04-28 03:56:25 +02:00
|
|
|
if (command.startsWith("reply"))
|
|
|
|
primaire.reply();
|
|
|
|
if (command.startsWith("misc"))
|
|
|
|
{
|
|
|
|
int rx = replyMisc.getWidth() / 2;
|
|
|
|
int ry = replyMisc.getHeight() - miscMenu.getHeight();
|
|
|
|
miscMenu.show(replyMisc, rx, ry);
|
|
|
|
}
|
2022-04-12 08:37:39 +02:00
|
|
|
return;
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
2022-04-12 08:37:39 +02:00
|
|
|
|
|
|
|
if (src == nextPrev)
|
2021-07-31 13:36:56 +02:00
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
if (command.equals("next"))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-31 13:36:56 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
}
|
|
|
|
return;
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
2022-04-12 08:37:39 +02:00
|
|
|
|
|
|
|
if (src == media)
|
2021-07-31 13:36:56 +02:00
|
|
|
{
|
|
|
|
primaire.openMedia();
|
2022-04-12 08:37:39 +02:00
|
|
|
return;
|
2022-04-28 03:56:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (src == deletePost)
|
|
|
|
{
|
|
|
|
primaire.deletePost(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src == redraftPost)
|
|
|
|
{
|
|
|
|
primaire.deletePost(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 01:07:23 +02:00
|
|
|
protected void
|
|
|
|
paintComponent(Graphics g)
|
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
g.clearRect(0, 0, getWidth(), getHeight());
|
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
((java.awt.Graphics2D)g).setRenderingHint(
|
2022-04-14 06:38:49 +02:00
|
|
|
java.awt.RenderingHints.KEY_ANTIALIASING,
|
|
|
|
java.awt.RenderingHints.VALUE_ANTIALIAS_ON
|
2022-04-12 13:52:07 +02:00
|
|
|
);
|
|
|
|
|
2022-04-15 14:54:31 +02:00
|
|
|
int w1 = authorName.getWidth();
|
|
|
|
int w2 = body.getWidth();
|
|
|
|
FontMetrics fm1 = getFontMetrics(authorName.getFont());
|
|
|
|
FontMetrics fm2 = getFontMetrics(body.getFont());
|
|
|
|
authorName.setText(RichTextPane.layout(authorNameOr, fm1, w1));
|
|
|
|
body.setText(RichTextPane.layout(bodyOr, fm2, w2));
|
2022-04-19 16:08:20 +02:00
|
|
|
|
|
|
|
List<RichTextPane.Segment> lay;
|
|
|
|
lay = RichTextPane.layout(bodyOr, fm2, w2);
|
|
|
|
int height = 0; for (RichTextPane.Segment s: lay)
|
|
|
|
{
|
|
|
|
if ((s.y + 10) > height) height = s.y + 10;
|
|
|
|
}
|
|
|
|
body.setPreferredSize(new Dimension(1, height));
|
2022-04-12 08:37:39 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 01:07:23 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
2021-07-31 13:36:56 +02:00
|
|
|
PostComponent(PostWindow primaire)
|
2021-07-16 01:07:23 +02:00
|
|
|
{
|
2021-07-31 13:36:56 +02:00
|
|
|
this.primaire = primaire;
|
|
|
|
|
2022-04-15 14:54:31 +02:00
|
|
|
emojiUrls = new String[0][];
|
2022-04-12 08:37:39 +02:00
|
|
|
|
2022-04-14 06:38:49 +02:00
|
|
|
Border b = BorderFactory.createEmptyBorder(10, 10, 10, 10);
|
2022-04-15 14:54:31 +02:00
|
|
|
Font f1 = new Font("IPAGothic", Font.PLAIN, 16);
|
|
|
|
Font f2 = new Font("IPAGothic", Font.PLAIN, 13);
|
2022-04-19 16:08:20 +02:00
|
|
|
Font f3 = getFont().deriveFont(14f);
|
2021-07-16 11:46:17 +02:00
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
profile = new RoundButton();
|
2022-04-15 14:54:31 +02:00
|
|
|
favouriteBoost = new TwoToggleButton("favourite", "boost");
|
|
|
|
replyMisc = new TwoToggleButton("reply", "misc");
|
|
|
|
nextPrev = new TwoToggleButton("next", "prev");
|
|
|
|
media = new RoundButton();
|
2021-07-31 13:36:56 +02:00
|
|
|
profile.addActionListener(this);
|
|
|
|
favouriteBoost.addActionListener(this);
|
|
|
|
replyMisc.addActionListener(this);
|
|
|
|
nextPrev.addActionListener(this);
|
|
|
|
media.addActionListener(this);
|
2021-07-31 13:28:46 +02:00
|
|
|
|
2022-04-28 03:56:25 +02:00
|
|
|
deletePost = new JMenuItem("Delete post");
|
|
|
|
redraftPost = new JMenuItem("Delete and redraft post");
|
|
|
|
deletePost.addActionListener(this);
|
|
|
|
redraftPost.addActionListener(this);
|
|
|
|
miscMenu = new JPopupMenu();
|
|
|
|
miscMenu.add(deletePost);
|
|
|
|
miscMenu.add(redraftPost);
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
Box buttons = Box.createVerticalBox();
|
|
|
|
buttons.setOpaque(false);
|
2022-04-15 14:54:31 +02:00
|
|
|
buttons.add(profile);
|
|
|
|
buttons.add(Box.createVerticalStrut(8));
|
|
|
|
buttons.add(favouriteBoost);
|
|
|
|
buttons.add(Box.createVerticalStrut(8));
|
|
|
|
buttons.add(replyMisc);
|
|
|
|
buttons.add(Box.createVerticalStrut(8));
|
|
|
|
buttons.add(nextPrev);
|
|
|
|
buttons.add(Box.createVerticalStrut(8));
|
|
|
|
buttons.add(media);
|
|
|
|
buttons.setMaximumSize(buttons.getPreferredSize());
|
|
|
|
Box left = Box.createVerticalBox();
|
|
|
|
left.setOpaque(false);
|
|
|
|
left.add(buttons);
|
|
|
|
|
|
|
|
authorId = new JLabel();
|
|
|
|
authorName = new RichTextPane();
|
|
|
|
time = new JLabel();
|
|
|
|
date = new JLabel();
|
|
|
|
authorId.setFont(f2);
|
|
|
|
date.setFont(f2);
|
|
|
|
authorName.setFont(f1);
|
|
|
|
time.setFont(f1);
|
|
|
|
|
|
|
|
JPanel top1 = new JPanel();
|
|
|
|
top1.setLayout(new BorderLayout(8, 0));
|
|
|
|
top1.add(authorId);
|
|
|
|
top1.add(date, BorderLayout.EAST);
|
|
|
|
JPanel top2 = new JPanel();
|
|
|
|
top2.setLayout(new BorderLayout(8, 0));
|
|
|
|
top2.add(authorName);
|
|
|
|
top2.add(time, BorderLayout.EAST);
|
|
|
|
Box top = Box.createVerticalBox();
|
|
|
|
top.add(top1);
|
|
|
|
top.add(Box.createVerticalStrut(2));
|
|
|
|
top.add(top2);
|
|
|
|
|
|
|
|
body = new RichTextPane();
|
2022-04-19 16:08:20 +02:00
|
|
|
body.setFont(f3);
|
|
|
|
|
|
|
|
JScrollPane scroll = new JScrollPane(
|
|
|
|
body,
|
|
|
|
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
|
|
|
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER
|
|
|
|
);
|
|
|
|
JScrollBar vsb = scroll.getVerticalScrollBar();
|
|
|
|
vsb.setPreferredSize(new Dimension(0, 0));
|
|
|
|
vsb.setUnitIncrement(16);
|
|
|
|
scroll.setBorder(null);
|
|
|
|
scroll.setFocusable(true);
|
2022-04-15 14:54:31 +02:00
|
|
|
|
|
|
|
JPanel centre = new JPanel();
|
|
|
|
centre.setOpaque(false);
|
|
|
|
centre.setLayout(new BorderLayout(0, 8));
|
|
|
|
centre.add(top, BorderLayout.NORTH);
|
2022-04-19 16:08:20 +02:00
|
|
|
centre.add(scroll);
|
2022-04-15 14:54:31 +02:00
|
|
|
|
|
|
|
setLayout(new BorderLayout(8, 0));
|
|
|
|
add(left, BorderLayout.WEST);
|
|
|
|
add(centre);
|
|
|
|
|
|
|
|
setBorder(b);
|
2021-07-16 01:07:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class
|
|
|
|
RepliesComponent extends JPanel {
|
|
|
|
|
2021-07-29 11:26:16 +02:00
|
|
|
private List<RepliesComponent.Reply>
|
|
|
|
replies;
|
|
|
|
|
|
|
|
// - -%- -
|
2021-07-16 01:07:23 +02:00
|
|
|
|
|
|
|
private JButton
|
|
|
|
prevPage, nextPage;
|
|
|
|
|
|
|
|
private JLabel
|
|
|
|
pageLabel;
|
|
|
|
|
2021-07-29 10:03:32 +02:00
|
|
|
private ReplyPreviewComponent[]
|
|
|
|
previews;
|
|
|
|
|
2021-07-16 01:07:23 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public void
|
2021-07-29 11:26:16 +02:00
|
|
|
setReplies(List<RepliesComponent.Reply> replies)
|
2021-07-16 01:07:23 +02:00
|
|
|
{
|
2021-07-29 11:26:16 +02:00
|
|
|
assert replies != null;
|
|
|
|
this.replies = replies;
|
2021-07-29 10:03:32 +02:00
|
|
|
displayPage(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// - -%- -
|
|
|
|
|
|
|
|
private void
|
|
|
|
displayPage(int pageNumber)
|
|
|
|
{
|
2021-07-29 11:26:16 +02:00
|
|
|
assert pageNumber > 0;
|
|
|
|
assert this.replies != null;
|
|
|
|
|
|
|
|
List<RepliesComponent.Reply> page;
|
2021-07-29 10:03:32 +02:00
|
|
|
{
|
2021-07-29 11:26:16 +02:00
|
|
|
int oS = (pageNumber - 1) * 8;
|
|
|
|
int oE = Math.min(oS + 8, replies.size());
|
|
|
|
if (oS > oE) page = new ArrayList<>();
|
|
|
|
else page = this.replies.subList(oS, oE);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int o = 0; o < page.size(); ++o)
|
|
|
|
{
|
|
|
|
assert o < previews.length;
|
|
|
|
|
2021-07-29 10:03:32 +02:00
|
|
|
ReplyPreviewComponent preview = previews[o];
|
2021-07-29 11:26:16 +02:00
|
|
|
Reply reply = replies.get(o);
|
2022-04-12 08:37:39 +02:00
|
|
|
preview.setAuthorName(reply.author);
|
2021-07-29 11:26:16 +02:00
|
|
|
preview.setText(reply.text);
|
|
|
|
preview.setVisible(true);
|
|
|
|
}
|
2021-07-29 10:03:32 +02:00
|
|
|
|
2021-07-29 11:26:16 +02:00
|
|
|
for (int o = page.size(); o < previews.length; ++o)
|
|
|
|
{
|
|
|
|
ReplyPreviewComponent preview = previews[o];
|
|
|
|
preview.setVisible(false);
|
2021-07-29 10:03:32 +02:00
|
|
|
}
|
2021-07-29 11:26:16 +02:00
|
|
|
|
|
|
|
int pages = 1 + ((replies.size() - 1) / 8);
|
|
|
|
pageLabel.setText(pageNumber + "/" + pages);
|
2021-07-29 11:40:52 +02:00
|
|
|
prevPage.setEnabled(pageNumber > 1);
|
|
|
|
nextPage.setEnabled(pageNumber < pages);
|
2021-07-29 11:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public static class
|
|
|
|
Reply {
|
|
|
|
|
|
|
|
public String
|
|
|
|
author;
|
|
|
|
|
|
|
|
public String
|
|
|
|
text;
|
|
|
|
|
2021-07-16 01:07:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
RepliesComponent()
|
|
|
|
{
|
|
|
|
prevPage = new JButton("<");
|
|
|
|
nextPage = new JButton(">");
|
|
|
|
prevPage.setEnabled(false);
|
|
|
|
nextPage.setEnabled(false);
|
|
|
|
|
2021-07-29 11:26:16 +02:00
|
|
|
pageLabel = new JLabel();
|
2021-07-16 01:07:23 +02:00
|
|
|
|
|
|
|
Box bottom = Box.createHorizontalBox();
|
|
|
|
bottom.add(Box.createGlue());
|
|
|
|
bottom.add(prevPage);
|
2021-07-17 11:37:00 +02:00
|
|
|
bottom.add(Box.createHorizontalStrut(8));
|
2021-07-16 01:07:23 +02:00
|
|
|
bottom.add(pageLabel);
|
2021-07-17 11:37:00 +02:00
|
|
|
bottom.add(Box.createHorizontalStrut(8));
|
2021-07-16 01:07:23 +02:00
|
|
|
bottom.add(nextPage);
|
|
|
|
|
|
|
|
JPanel centre = new JPanel();
|
2021-07-17 11:37:00 +02:00
|
|
|
centre.setOpaque(false);
|
2021-07-16 01:07:23 +02:00
|
|
|
centre.setLayout(new GridLayout(0, 1, 0, 2));
|
2021-07-29 10:03:32 +02:00
|
|
|
|
|
|
|
previews = new ReplyPreviewComponent[8];
|
|
|
|
for (int o = 0; o < previews.length; ++o)
|
|
|
|
{
|
|
|
|
previews[o] = new ReplyPreviewComponent();
|
|
|
|
previews[o].setVisible(false);
|
|
|
|
centre.add(previews[o]);
|
2021-07-16 01:07:23 +02:00
|
|
|
}
|
|
|
|
|
2021-07-17 11:37:00 +02:00
|
|
|
setLayout(new BorderLayout(0, 8));
|
2021-07-16 01:07:23 +02:00
|
|
|
add(centre, BorderLayout.CENTER);
|
|
|
|
add(bottom, BorderLayout.SOUTH);
|
|
|
|
|
2021-07-17 11:37:00 +02:00
|
|
|
setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
2021-07-29 11:26:16 +02:00
|
|
|
|
|
|
|
setReplies(new ArrayList<>());
|
2021-07-16 01:07:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-07-17 11:37:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
class
|
|
|
|
ReplyPreviewComponent extends JButton {
|
|
|
|
|
|
|
|
private String
|
|
|
|
author;
|
|
|
|
|
|
|
|
private String
|
|
|
|
text;
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void
|
|
|
|
setText(String text)
|
|
|
|
{
|
|
|
|
assert text != null;
|
|
|
|
this.text = text;
|
|
|
|
setText();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
2022-04-12 08:37:39 +02:00
|
|
|
setAuthorName(String author)
|
2021-07-17 11:37:00 +02:00
|
|
|
{
|
|
|
|
assert author != null;
|
|
|
|
this.author = author;
|
|
|
|
setText();
|
|
|
|
}
|
|
|
|
|
|
|
|
// - -%- -
|
|
|
|
|
|
|
|
private void
|
|
|
|
setText()
|
|
|
|
{
|
|
|
|
StringBuilder text = new StringBuilder();
|
|
|
|
text.append(this.author);
|
|
|
|
text.append(" @ ");
|
|
|
|
text.append(this.text);
|
|
|
|
super.setText(text.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void
|
|
|
|
paintComponent(Graphics g)
|
|
|
|
{
|
|
|
|
g.drawString(getText(), 8, 2 * getHeight() / 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|