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;
|
2022-05-22 05:14:21 +02:00
|
|
|
import javax.swing.MenuSelectionManager;
|
|
|
|
import javax.swing.MenuElement;
|
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;
|
2022-06-01 10:42:04 +02:00
|
|
|
import java.awt.MediaTracker;
|
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-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();
|
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-28 03:41:12 +02:00
|
|
|
String ownId = api.getAccountDetails().get("acct").value;
|
2022-05-06 09:05:01 +02:00
|
|
|
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-05-19 09:24:03 +02:00
|
|
|
if (!w.isVisible())
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2022-05-20 15:14:32 +02:00
|
|
|
getContentPane().setPreferredSize(new Dimension(360, 260));
|
2021-07-16 11:46:17 +02:00
|
|
|
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>
|
2022-05-19 09:24:03 +02:00
|
|
|
authorNameOr;
|
2022-04-15 14:54:31 +02:00
|
|
|
|
|
|
|
private RichTextPane
|
2022-05-19 09:24:03 +02:00
|
|
|
authorName;
|
|
|
|
|
|
|
|
private RichTextPane3
|
|
|
|
body;
|
2022-04-15 14:54:31 +02:00
|
|
|
|
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;
|
|
|
|
|
2022-05-20 15:14:32 +02:00
|
|
|
private Image
|
|
|
|
backgroundImage;
|
|
|
|
|
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
|
2022-06-02 02:44:06 +02:00
|
|
|
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
|
2022-05-19 09:24:03 +02:00
|
|
|
setEmojiUrls(String[][] n)
|
|
|
|
{
|
|
|
|
emojiUrls = n;
|
|
|
|
|
|
|
|
Map<String, Image> emojis = new HashMap<>();
|
|
|
|
for (String[] entry: n)
|
|
|
|
{
|
|
|
|
emojis.put(entry[0], ImageApi.remote(entry[1]));
|
|
|
|
}
|
|
|
|
body.setEmojis(emojis);
|
|
|
|
}
|
2022-04-15 14:54:31 +02:00
|
|
|
|
|
|
|
public void
|
|
|
|
setHtml(String n)
|
|
|
|
{
|
2022-05-19 09:24:03 +02:00
|
|
|
body.setText(BasicHTMLParser.parse(n));
|
2022-04-15 14:54:31 +02:00
|
|
|
}
|
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()
|
|
|
|
{
|
|
|
|
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-05-22 05:14:21 +02:00
|
|
|
if (miscMenu.isVisible())
|
|
|
|
{
|
|
|
|
Component sel = getSelected(miscMenu);
|
|
|
|
if (sel == null) return;
|
|
|
|
assert sel instanceof JMenuItem;
|
|
|
|
((JMenuItem)sel).doClick();
|
|
|
|
}
|
|
|
|
else if (command.startsWith("reply"))
|
|
|
|
{
|
2022-04-28 03:56:25 +02:00
|
|
|
primaire.reply();
|
2022-05-22 05:14:21 +02:00
|
|
|
}
|
|
|
|
else if (command.startsWith("misc"))
|
2022-04-28 03:56:25 +02:00
|
|
|
{
|
|
|
|
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-05-22 05:14:21 +02:00
|
|
|
else miscMenu.setVisible(false);
|
2022-04-12 08:37:39 +02:00
|
|
|
|
|
|
|
if (src == nextPrev)
|
2021-07-31 13:36:56 +02:00
|
|
|
{
|
2022-05-20 15:14:32 +02:00
|
|
|
if (command.startsWith("next"))
|
2022-04-12 08:37:39 +02:00
|
|
|
{
|
2022-05-20 15:14:32 +02:00
|
|
|
body.nextPage();
|
2022-04-12 08:37:39 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-20 15:14:32 +02:00
|
|
|
body.previousPage();
|
2022-04-12 08:37:39 +02:00
|
|
|
}
|
2022-05-20 15:14:32 +02:00
|
|
|
// First time an interactive element
|
|
|
|
// doesn't call something in primaire..
|
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();
|
|
|
|
FontMetrics fm1 = getFontMetrics(authorName.getFont());
|
2022-05-19 09:24:03 +02:00
|
|
|
List<RichTextPane.Segment> lay1;
|
2022-05-01 08:46:10 +02:00
|
|
|
lay1 = RichTextPane.layout(authorNameOr, fm1, w1);
|
|
|
|
authorName.setText(lay1);
|
2022-05-06 22:34:22 +02:00
|
|
|
|
2022-05-20 15:14:32 +02:00
|
|
|
if (backgroundImage != null)
|
|
|
|
{
|
|
|
|
int tw = backgroundImage.getWidth(this);
|
|
|
|
int th = backgroundImage.getHeight(this);
|
|
|
|
if (tw != -1)
|
|
|
|
for (int y = 0; y < getHeight(); y += th)
|
|
|
|
for (int x = 0; x < getWidth(); x += tw)
|
|
|
|
{
|
|
|
|
g.drawImage(backgroundImage, x, y, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-22 05:14:21 +02:00
|
|
|
// - -%- -
|
|
|
|
|
|
|
|
private static Component
|
|
|
|
getSelected(JPopupMenu menu)
|
|
|
|
{
|
|
|
|
MenuElement[] sel =
|
|
|
|
MenuSelectionManager.defaultManager()
|
|
|
|
.getSelectedPath();
|
|
|
|
/*
|
|
|
|
* (知) For some reason, the selection model of the
|
|
|
|
* JPopupMenu doesn't do anything. So we have to
|
|
|
|
* consult this apparently global menu manager.
|
|
|
|
*/
|
|
|
|
for (int o = 0; o < sel.length - 1; ++o)
|
|
|
|
{
|
|
|
|
if (sel[o] == menu)
|
|
|
|
return sel[o + 1].getComponent();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
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();
|
2022-05-20 15:14:32 +02:00
|
|
|
top1.setOpaque(false);
|
2022-04-15 14:54:31 +02:00
|
|
|
top1.setLayout(new BorderLayout(8, 0));
|
|
|
|
top1.add(authorId);
|
|
|
|
top1.add(date, BorderLayout.EAST);
|
|
|
|
JPanel top2 = new JPanel();
|
2022-05-20 15:14:32 +02:00
|
|
|
top2.setOpaque(false);
|
2022-04-15 14:54:31 +02:00
|
|
|
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);
|
|
|
|
|
2022-05-19 09:24:03 +02:00
|
|
|
body = new RichTextPane3();
|
2022-04-19 16:08:20 +02:00
|
|
|
body.setFont(f3);
|
|
|
|
|
2022-05-20 15:14:32 +02:00
|
|
|
/*
|
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-05-20 15:14:32 +02:00
|
|
|
*/
|
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-20 15:14:32 +02:00
|
|
|
centre.add(body);
|
2022-04-15 14:54:31 +02:00
|
|
|
|
|
|
|
setLayout(new BorderLayout(8, 0));
|
|
|
|
add(left, BorderLayout.WEST);
|
|
|
|
add(centre);
|
|
|
|
|
|
|
|
setBorder(b);
|
2022-05-20 15:14:32 +02:00
|
|
|
|
|
|
|
backgroundImage = ImageApi.local("postWindow");
|
2021-07-16 01:07:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|