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;
|
2022-04-28 13:36:45 +02:00
|
|
|
import javax.swing.JSeparator;
|
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-05-16 18:52:00 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
|
2021-07-16 00:37:03 +02:00
|
|
|
class
|
2022-04-29 19:44:38 +02:00
|
|
|
PostWindow extends JFrame {
|
2021-07-16 00:37:03 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
private JKomasto
|
|
|
|
primaire;
|
|
|
|
|
|
|
|
private MastodonApi
|
|
|
|
api;
|
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
private Post
|
|
|
|
post,
|
|
|
|
wrapperPost;
|
2021-07-16 11:46:17 +02:00
|
|
|
|
|
|
|
// - -%- -
|
|
|
|
|
2021-07-16 00:37:03 +02:00
|
|
|
private PostComponent
|
2022-04-29 19:44:38 +02:00
|
|
|
display;
|
2021-07-16 00:37:03 +02:00
|
|
|
|
2022-05-15 00:04:46 +02:00
|
|
|
private static JFrame
|
2022-05-16 18:52:00 +02:00
|
|
|
test;
|
|
|
|
|
|
|
|
private static RichTextPane3
|
|
|
|
test2;
|
2022-05-15 00:04:46 +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-05-06 22:34:22 +02:00
|
|
|
public synchronized void
|
2022-05-06 09:05:01 +02:00
|
|
|
use(Post post)
|
|
|
|
{
|
|
|
|
assert post != null;
|
|
|
|
|
|
|
|
if (post.boostedPost != null)
|
|
|
|
{
|
|
|
|
wrapperPost = post;
|
|
|
|
this.post = post.boostedPost;
|
|
|
|
post = post.boostedPost;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wrapperPost = null;
|
|
|
|
this.post = post;
|
|
|
|
}
|
|
|
|
|
|
|
|
display.setAuthorName(post.author.name);
|
|
|
|
display.setAuthorId(post.author.id);
|
2021-07-29 10:03:32 +02:00
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
String oid = api.getAccountDetails().get("id").value;
|
|
|
|
String aid = post.author.numId;
|
|
|
|
display.setDeleteEnabled(aid.equals(oid));
|
2022-04-23 16:19:43 +02:00
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
post.author.resolveAvatar();
|
|
|
|
display.setAuthorAvatar(post.author.avatar);
|
2022-04-23 16:19:43 +02:00
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
display.setDate(post.date);
|
|
|
|
display.setTime(post.time);
|
2022-04-23 16:19:43 +02:00
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
display.setEmojiUrls(post.emojiUrls);
|
|
|
|
|
|
|
|
display.setHtml(post.text);
|
|
|
|
display.setFavourited(post.favourited);
|
|
|
|
display.setBoosted(post.boosted);
|
|
|
|
|
|
|
|
if (post.attachments.length > 0)
|
|
|
|
{
|
|
|
|
post.attachments[0].resolveImage();
|
|
|
|
display.setMediaPreview(post.attachments[0].image);
|
|
|
|
}
|
|
|
|
else display.setMediaPreview(null);
|
2022-04-28 03:56:25 +02:00
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
post.resolveApproximateText();
|
|
|
|
this.setTitle(post.approximateText);
|
2022-04-28 13:36:45 +02:00
|
|
|
|
2022-04-29 19:44:38 +02:00
|
|
|
display.resetFocus();
|
2022-04-12 08:37:39 +02:00
|
|
|
repaint();
|
2022-05-16 18:52:00 +02:00
|
|
|
|
|
|
|
if (test == null)
|
|
|
|
{
|
|
|
|
test = new JFrame();
|
|
|
|
test.setSize(340, 256);
|
|
|
|
test2 = new RichTextPane3();
|
|
|
|
test2.setFont(new Font("Dialog", Font.PLAIN, 18));
|
|
|
|
test.setContentPane(test2);
|
|
|
|
test.setVisible(true);
|
|
|
|
}
|
|
|
|
test2.setText(BasicHTMLParser.parse(post.text));
|
|
|
|
Map<String, Image> emojis = new HashMap<>();
|
|
|
|
for (String[] entry: post.emojiUrls)
|
|
|
|
{
|
|
|
|
emojis.put(entry[0], ImageApi.remote(entry[1]));
|
|
|
|
}
|
|
|
|
test2.setEmojis(emojis);
|
2022-05-17 09:14:16 +02:00
|
|
|
test2.requestFocusInWindow();
|
2021-07-17 13:17:14 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
public void
|
|
|
|
readEntity(Tree<String> post)
|
|
|
|
{
|
|
|
|
use(new Post(post));
|
|
|
|
}
|
|
|
|
|
2022-05-06 22:34:22 +02:00
|
|
|
public synchronized void
|
2021-07-31 13:36:56 +02:00
|
|
|
openAuthorProfile()
|
|
|
|
{
|
2022-05-13 16:32:11 +02:00
|
|
|
ProfileWindow w = new ProfileWindow(primaire);
|
|
|
|
w.use(post.author);
|
|
|
|
w.setLocationRelativeTo(this);
|
|
|
|
w.setVisible(true);
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 22:34:22 +02:00
|
|
|
public synchronized void
|
2022-04-12 08:37:39 +02:00
|
|
|
favourite(boolean favourited)
|
2021-07-31 13:36:56 +02:00
|
|
|
{
|
2022-05-06 09:05:01 +02:00
|
|
|
display.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
2022-04-29 19:44:38 +02:00
|
|
|
display.setFavouriteBoostEnabled(false);
|
|
|
|
display.paintImmediately(display.getBounds());
|
2022-04-12 08:37:39 +02:00
|
|
|
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-05-06 09:05:01 +02:00
|
|
|
PostWindow.this.post.favourited = favourited;
|
2022-04-12 08:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2022-05-06 09:05:01 +02:00
|
|
|
api.setPostFavourited(post.id, favourited, handler);
|
2022-04-29 19:44:38 +02:00
|
|
|
display.setCursor(null);
|
|
|
|
display.setFavouriteBoostEnabled(true);
|
|
|
|
display.repaint();
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 22:34:22 +02:00
|
|
|
public synchronized void
|
2022-04-12 08:37:39 +02:00
|
|
|
boost(boolean boosted)
|
2021-07-31 13:36:56 +02:00
|
|
|
{
|
2022-04-29 19:44:38 +02:00
|
|
|
display.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
|
|
|
display.setFavouriteBoostEnabled(false);
|
|
|
|
display.paintImmediately(display.getBounds());
|
2022-04-12 08:37:39 +02:00
|
|
|
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-05-06 09:05:01 +02:00
|
|
|
PostWindow.this.post.boosted = boosted;
|
2022-04-12 08:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2022-05-06 09:05:01 +02:00
|
|
|
api.setPostBoosted(post.id, boosted, handler);
|
2022-04-29 19:44:38 +02:00
|
|
|
display.setCursor(null);
|
|
|
|
display.setFavouriteBoostEnabled(true);
|
|
|
|
display.repaint();
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 22:34:22 +02:00
|
|
|
public synchronized void
|
2021-07-31 13:36:56 +02:00
|
|
|
reply()
|
|
|
|
{
|
2022-05-06 09:05:01 +02:00
|
|
|
String ownId = api.getAccountDetails().get("id").value;
|
|
|
|
Composition c = Composition.reply(this.post, ownId);
|
2022-04-12 08:37:39 +02:00
|
|
|
ComposeWindow w = primaire.getComposeWindow();
|
2022-05-06 09:05:01 +02:00
|
|
|
w.setComposition(c);
|
2022-04-12 08:37:39 +02:00
|
|
|
w.setLocation(getX(), getY() + 100);
|
|
|
|
w.setVisible(true);
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 22:34:22 +02:00
|
|
|
public synchronized void
|
2021-07-31 13:36:56 +02:00
|
|
|
openMedia()
|
|
|
|
{
|
2022-05-06 09:05:01 +02:00
|
|
|
display.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
|
|
|
|
|
|
|
for (Attachment a: post.attachments) a.resolveImage();
|
|
|
|
|
|
|
|
ImageWindow w = new ImageWindow();
|
|
|
|
w.setTitle("Media - " + this.getTitle());
|
2022-05-06 22:34:22 +02:00
|
|
|
w.setIconImage(this.getIconImage());
|
2022-05-06 09:05:01 +02:00
|
|
|
w.showAttachments(post.attachments);
|
|
|
|
w.setLocationRelativeTo(null);
|
|
|
|
w.setVisible(true);
|
|
|
|
|
|
|
|
display.setCursor(null);
|
2021-07-31 13:36:56 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 22:34:22 +02:00
|
|
|
public synchronized void
|
2022-04-28 03:56:25 +02:00
|
|
|
deletePost(boolean redraft)
|
|
|
|
{
|
2022-04-29 19:44:38 +02:00
|
|
|
display.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
|
|
|
display.setDeleteEnabled(false);
|
|
|
|
display.paintImmediately(display.getBounds());
|
2022-04-28 03:56:25 +02:00
|
|
|
|
2022-05-13 16:32:11 +02:00
|
|
|
final String S1 =
|
|
|
|
"Are you sure you'd like to delete this post?\n";
|
|
|
|
final String S2 =
|
|
|
|
"Are you sure you'd like to delete this post?\n"
|
|
|
|
+ "You are redrafting, so a composition window\n"
|
|
|
|
+ "should open with its contents filled.";
|
|
|
|
JOptionPane dialog = new JOptionPane();
|
|
|
|
dialog.setMessageType(JOptionPane.QUESTION_MESSAGE);
|
|
|
|
dialog.setMessage(redraft ? S2 : S1);
|
|
|
|
dialog.setOptions(new String[] { "No", "Yes" });
|
|
|
|
String title = "Confirm delete";
|
|
|
|
dialog.createDialog(this, title).setVisible(true);
|
|
|
|
if (!dialog.getValue().equals("Yes"))
|
|
|
|
{
|
|
|
|
display.setCursor(null);
|
|
|
|
display.setDeleteEnabled(true);
|
|
|
|
display.paintImmediately(display.getBounds());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
api.deletePost(post.id, new RequestListener() {
|
2022-04-28 03:56:25 +02:00
|
|
|
|
|
|
|
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);
|
2022-05-06 09:05:01 +02:00
|
|
|
|
|
|
|
if (redraft)
|
|
|
|
{
|
|
|
|
Composition c = Composition.recover(json);
|
|
|
|
ComposeWindow w = new ComposeWindow(primaire);
|
|
|
|
w.setComposition(c);
|
|
|
|
w.setLocation(getX(), getY() + 100);
|
|
|
|
w.setVisible(true);
|
|
|
|
}
|
2022-04-28 03:56:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2022-04-29 19:44:38 +02:00
|
|
|
display.setCursor(null);
|
|
|
|
display.setDeleteEnabled(true);
|
|
|
|
display.paintImmediately(display.getBounds());
|
2022-04-28 03:56:25 +02:00
|
|
|
if (!isVisible()) dispose();
|
|
|
|
}
|
|
|
|
|
2022-05-06 22:34:22 +02:00
|
|
|
public synchronized void
|
2022-04-29 19:44:38 +02:00
|
|
|
copyPostId()
|
|
|
|
{
|
2022-05-06 09:05:01 +02:00
|
|
|
ClipboardApi.serve(post.id);
|
2022-04-29 19:44:38 +02:00
|
|
|
}
|
2021-07-29 10:03:32 +02:00
|
|
|
|
2022-05-06 22:34:22 +02:00
|
|
|
public synchronized void
|
2022-04-29 19:44:38 +02:00
|
|
|
copyPostLink()
|
|
|
|
{
|
2022-05-06 09:05:01 +02:00
|
|
|
ClipboardApi.serve(post.uri);
|
2022-04-29 19:44:38 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 22:34:22 +02:00
|
|
|
public synchronized void
|
2022-04-29 19:44:38 +02:00
|
|
|
openReplies()
|
|
|
|
{
|
|
|
|
RepliesWindow w = new RepliesWindow(primaire, this);
|
2022-05-06 09:05:01 +02:00
|
|
|
w.showFor(post.id);
|
2022-04-29 19:44:38 +02:00
|
|
|
w.setLocation(getX(), getY() + 100);
|
|
|
|
w.setVisible(true);
|
|
|
|
}
|
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);
|
|
|
|
|
2022-04-29 19:44:38 +02:00
|
|
|
display = new PostComponent(this);
|
2021-07-29 10:03:32 +02:00
|
|
|
|
2022-04-29 19:44:38 +02:00
|
|
|
setContentPane(display);
|
2022-05-06 15:57:17 +02:00
|
|
|
setIconImage(primaire.getProgramIcon());
|
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;
|
|
|
|
|
2022-05-06 22:34:22 +02:00
|
|
|
private JScrollPane
|
|
|
|
bodyScrollPane;
|
|
|
|
|
2022-04-15 14:54:31 +02:00
|
|
|
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
|
2022-04-29 19:44:38 +02:00
|
|
|
openReplies,
|
|
|
|
copyPostId,
|
|
|
|
copyPostLink,
|
2022-04-28 03:56:25 +02:00
|
|
|
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
|
2022-05-06 22:34:22 +02:00
|
|
|
resetFocus()
|
|
|
|
{
|
|
|
|
bodyScrollPane.getVerticalScrollBar().setValue(0);
|
|
|
|
media.requestFocusInWindow();
|
|
|
|
}
|
2022-04-12 13:52:07 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-29 19:44:38 +02:00
|
|
|
if (src == openReplies) primaire.openReplies();
|
|
|
|
if (src == copyPostId) primaire.copyPostId();
|
|
|
|
if (src == copyPostLink) primaire.copyPostLink();
|
|
|
|
if (src == deletePost) primaire.deletePost(false);
|
|
|
|
if (src == redraftPost) primaire.deletePost(true);
|
2022-04-28 03:56:25 +02:00
|
|
|
|
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-15 14:54:31 +02:00
|
|
|
int w1 = authorName.getWidth();
|
|
|
|
int w2 = body.getWidth();
|
|
|
|
FontMetrics fm1 = getFontMetrics(authorName.getFont());
|
|
|
|
FontMetrics fm2 = getFontMetrics(body.getFont());
|
2022-05-01 08:46:10 +02:00
|
|
|
List<RichTextPane.Segment> lay1, lay2;
|
|
|
|
lay1 = RichTextPane.layout(authorNameOr, fm1, w1);
|
|
|
|
lay2 = RichTextPane.layout(bodyOr, fm2, w2);
|
|
|
|
|
|
|
|
authorName.setText(lay1);
|
|
|
|
body.setText(lay2);
|
2022-04-19 16:08:20 +02:00
|
|
|
|
2022-05-01 08:46:10 +02:00
|
|
|
int maxY = 0; for (RichTextPane.Segment s: lay2)
|
2022-04-19 16:08:20 +02:00
|
|
|
{
|
2022-05-01 08:46:10 +02:00
|
|
|
if (s.y > maxY) maxY = s.y;
|
2022-04-19 16:08:20 +02:00
|
|
|
}
|
2022-05-01 08:46:10 +02:00
|
|
|
body.setPreferredSize(new Dimension(1, maxY + 10));
|
2022-05-06 22:34:22 +02:00
|
|
|
|
|
|
|
((java.awt.Graphics2D)g).setRenderingHint(
|
|
|
|
java.awt.RenderingHints.KEY_ANTIALIASING,
|
|
|
|
java.awt.RenderingHints.VALUE_ANTIALIAS_ON
|
|
|
|
);
|
2022-04-12 08:37:39 +02:00
|
|
|
}
|
|
|
|
|
2022-05-01 08:46:10 +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-05-01 14:33:17 +02:00
|
|
|
Font f1 = new Font("MotoyaLMaru", Font.PLAIN, 18);
|
|
|
|
Font f2 = new Font("MotoyaLMaru", Font.PLAIN, 14);
|
|
|
|
Font f3 = new Font("MotoyaLMaru", Font.PLAIN, 18);
|
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-29 19:44:38 +02:00
|
|
|
openReplies = new JMenuItem("Browse thread");
|
|
|
|
copyPostId = new JMenuItem("Copy post ID");
|
|
|
|
copyPostLink = new JMenuItem("Copy post link");
|
2022-04-28 03:56:25 +02:00
|
|
|
deletePost = new JMenuItem("Delete post");
|
|
|
|
redraftPost = new JMenuItem("Delete and redraft post");
|
2022-04-29 19:44:38 +02:00
|
|
|
openReplies.addActionListener(this);
|
|
|
|
copyPostId.addActionListener(this);
|
|
|
|
copyPostLink.addActionListener(this);
|
2022-04-28 03:56:25 +02:00
|
|
|
deletePost.addActionListener(this);
|
|
|
|
redraftPost.addActionListener(this);
|
|
|
|
miscMenu = new JPopupMenu();
|
2022-04-29 19:44:38 +02:00
|
|
|
miscMenu.add(openReplies);
|
|
|
|
miscMenu.add(new JSeparator());
|
|
|
|
miscMenu.add(copyPostId);
|
|
|
|
miscMenu.add(copyPostLink);
|
|
|
|
miscMenu.add(new JSeparator());
|
2022-04-28 03:56:25 +02:00
|
|
|
miscMenu.add(deletePost);
|
2022-04-29 19:44:38 +02:00
|
|
|
miscMenu.add(new JSeparator());
|
2022-04-28 03:56:25 +02:00
|
|
|
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);
|
|
|
|
|
2022-05-06 22:34:22 +02:00
|
|
|
bodyScrollPane = new JScrollPane(
|
2022-04-19 16:08:20 +02:00
|
|
|
body,
|
|
|
|
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
|
|
|
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER
|
|
|
|
);
|
2022-05-06 22:34:22 +02:00
|
|
|
JScrollBar vsb = bodyScrollPane.getVerticalScrollBar();
|
2022-04-19 16:08:20 +02:00
|
|
|
vsb.setPreferredSize(new Dimension(0, 0));
|
|
|
|
vsb.setUnitIncrement(16);
|
2022-05-06 22:34:22 +02:00
|
|
|
bodyScrollPane.setBorder(null);
|
|
|
|
bodyScrollPane.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-05-06 22:34:22 +02:00
|
|
|
centre.add(bodyScrollPane);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|