2021-07-16 00:37:03 +02:00
|
|
|
|
2021-07-16 01:07:23 +02:00
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JPanel;
|
2021-07-16 00:37:03 +02:00
|
|
|
import javax.swing.JComponent;
|
2021-07-17 11:06:50 +02:00
|
|
|
import javax.swing.JButton;
|
2021-07-16 00:37:03 +02:00
|
|
|
import javax.swing.JLabel;
|
2021-07-17 12:03:59 +02:00
|
|
|
import javax.swing.JMenu;
|
2021-07-31 06:01:20 +02:00
|
|
|
import javax.swing.JMenuItem;
|
2021-07-17 12:03:59 +02:00
|
|
|
import javax.swing.JMenuBar;
|
|
|
|
import javax.swing.JSeparator;
|
2021-07-16 00:37:03 +02:00
|
|
|
import javax.swing.Box;
|
2021-07-17 11:06:50 +02:00
|
|
|
import javax.swing.BorderFactory;
|
2021-07-16 00:37:03 +02:00
|
|
|
import java.awt.BorderLayout;
|
2021-07-17 11:06:50 +02:00
|
|
|
import java.awt.GridBagLayout;
|
|
|
|
import java.awt.GridBagConstraints;
|
|
|
|
import java.awt.FlowLayout;
|
2021-07-16 00:37:03 +02:00
|
|
|
import java.awt.Font;
|
2021-07-16 11:46:17 +02:00
|
|
|
import java.awt.Dimension;
|
2021-07-17 11:06:50 +02:00
|
|
|
import java.awt.Insets;
|
2022-04-12 08:37:39 +02:00
|
|
|
import java.awt.Cursor;
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Graphics;
|
2021-07-17 11:06:50 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.ArrayList;
|
2021-07-31 06:01:20 +02:00
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
import java.awt.event.ActionEvent;
|
2022-04-12 08:37:39 +02:00
|
|
|
import java.awt.event.MouseListener;
|
|
|
|
import java.awt.event.MouseEvent;
|
|
|
|
|
|
|
|
import cafe.biskuteri.hinoki.Tree;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.time.ZonedDateTime;
|
|
|
|
import java.time.ZoneId;
|
|
|
|
import java.time.Period;
|
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
|
import java.time.format.DateTimeParseException;
|
2021-07-16 00:37:03 +02:00
|
|
|
|
2021-07-16 01:07:23 +02:00
|
|
|
class
|
2021-07-31 06:01:20 +02:00
|
|
|
TimelineWindow extends JFrame
|
|
|
|
implements ActionListener {
|
2021-07-16 01:07:23 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
private JKomasto
|
|
|
|
primaire;
|
|
|
|
|
|
|
|
private MastodonApi
|
|
|
|
api;
|
|
|
|
|
|
|
|
private TimelinePage
|
|
|
|
page;
|
2021-07-16 11:46:17 +02:00
|
|
|
|
|
|
|
// - -%- -
|
|
|
|
|
2021-07-16 01:07:23 +02:00
|
|
|
private TimelineComponent
|
|
|
|
display;
|
|
|
|
|
2021-07-31 06:01:20 +02:00
|
|
|
private JMenuItem
|
|
|
|
openHome,
|
|
|
|
// umm, what about the timeline that's like, notes that your
|
|
|
|
// post was favourited or replied to? those aren't messages..
|
|
|
|
openMessages,
|
|
|
|
openLocal,
|
|
|
|
openFederated,
|
|
|
|
createPost,
|
|
|
|
openAutoPostView,
|
|
|
|
quit;
|
|
|
|
|
|
|
|
private JMenuItem
|
|
|
|
flipToNewestPost;
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
// - -%- -
|
|
|
|
|
|
|
|
private static final int
|
|
|
|
PREVIEW_COUNT = TimelineComponent.PREVIEW_COUNT;
|
2021-08-14 20:56:37 +02:00
|
|
|
|
2021-07-17 11:46:27 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public void
|
2022-04-12 08:37:39 +02:00
|
|
|
setTimelineType(TimelineType type)
|
2021-07-17 11:46:27 +02:00
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
page.type = type;
|
|
|
|
String s = type.toString();
|
|
|
|
s = s.charAt(0) + s.substring(1).toLowerCase();
|
|
|
|
setTitle(s + " - JKomasto");
|
|
|
|
}
|
2021-07-29 11:40:52 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
public void
|
|
|
|
showLatestPage()
|
|
|
|
{
|
|
|
|
display.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
|
|
|
api.getTimelinePage(
|
|
|
|
page.type, PREVIEW_COUNT, null, null,
|
|
|
|
new RequestListener() {
|
|
|
|
|
|
|
|
public void
|
|
|
|
connectionFailed(IOException eIo)
|
|
|
|
{
|
|
|
|
String s = eIo.getClass().getName();
|
|
|
|
setTitle(s + " - JKomasto");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestFailed(int httpCode, Tree<String> json)
|
|
|
|
{
|
|
|
|
setTitle(httpCode + " - JKomasto");
|
|
|
|
// lol...
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestSucceeded(Tree<String> json)
|
|
|
|
{
|
|
|
|
page.posts = toPosts(json);
|
|
|
|
display.setPosts(page.posts);
|
|
|
|
display.setNextPageAvailable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
display.setCursor(null);
|
2021-07-17 11:46:27 +02:00
|
|
|
}
|
|
|
|
|
2021-07-31 13:28:46 +02:00
|
|
|
public void
|
|
|
|
nextPage()
|
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
assert page.posts != null;
|
|
|
|
assert page.posts.size() != 0;
|
|
|
|
Post last = page.posts.get(page.posts.size() - 1);
|
|
|
|
|
|
|
|
display.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
|
|
|
api.getTimelinePage(
|
|
|
|
page.type, PREVIEW_COUNT, last.postId, null,
|
|
|
|
new RequestListener() {
|
|
|
|
|
|
|
|
public void
|
|
|
|
connectionFailed(IOException eIo)
|
|
|
|
{
|
|
|
|
String s = eIo.getClass().getName();
|
|
|
|
setTitle(s + " - JKomasto");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestFailed(int httpCode, Tree<String> json)
|
|
|
|
{
|
|
|
|
setTitle(httpCode + " - JKomasto");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestSucceeded(Tree<String> json)
|
|
|
|
{
|
|
|
|
page.posts = toPosts(json);
|
|
|
|
display.setPosts(page.posts);
|
|
|
|
display.setPreviousPageAvailable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
display.setCursor(null);
|
2021-07-31 13:28:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
previousPage()
|
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
assert page.posts != null;
|
|
|
|
assert page.posts.size() != 0;
|
|
|
|
Post first = page.posts.get(0);
|
|
|
|
|
|
|
|
display.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
|
|
|
api.getTimelinePage(
|
|
|
|
page.type, PREVIEW_COUNT, null, first.postId,
|
|
|
|
new RequestListener() {
|
|
|
|
|
|
|
|
public void
|
|
|
|
connectionFailed(IOException eIo)
|
|
|
|
{
|
|
|
|
String s = eIo.getClass().getName();
|
|
|
|
setTitle(s + " - JKomasto");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestFailed(int httpCode, Tree<String> json)
|
|
|
|
{
|
|
|
|
setTitle(httpCode + " - JKomasto");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
requestSucceeded(Tree<String> json)
|
|
|
|
{
|
|
|
|
page.posts = toPosts(json);
|
|
|
|
display.setPosts(page.posts);
|
|
|
|
display.setNextPageAvailable(true);
|
|
|
|
display.setPreviousPageAvailable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
display.setCursor(null);
|
|
|
|
|
|
|
|
if (page.posts.size() < PREVIEW_COUNT) showLatestPage();
|
2021-07-31 13:28:46 +02:00
|
|
|
}
|
|
|
|
|
2021-07-31 06:01:20 +02:00
|
|
|
// - -%- -
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
public void
|
|
|
|
postSelected(Post post)
|
|
|
|
{
|
|
|
|
primaire.getAutoViewWindow().showPost(post);
|
|
|
|
}
|
|
|
|
|
2021-07-31 06:01:20 +02:00
|
|
|
public void
|
|
|
|
actionPerformed(ActionEvent eA)
|
|
|
|
{
|
|
|
|
Object src = eA.getSource();
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
if (src == openHome)
|
|
|
|
{
|
|
|
|
setTimelineType(TimelineType.HOME);
|
|
|
|
showLatestPage();
|
|
|
|
}
|
|
|
|
if (src == openFederated)
|
|
|
|
{
|
|
|
|
setTimelineType(TimelineType.FEDERATED);
|
|
|
|
showLatestPage();
|
|
|
|
}
|
|
|
|
if (src == openLocal)
|
|
|
|
{
|
|
|
|
setTimelineType(TimelineType.LOCAL);
|
|
|
|
showLatestPage();
|
|
|
|
}
|
|
|
|
if (src == createPost)
|
|
|
|
{
|
|
|
|
primaire.getComposeWindow().setVisible(true);
|
|
|
|
}
|
|
|
|
if (src == openAutoPostView)
|
|
|
|
{
|
|
|
|
PostWindow w = primaire.getAutoViewWindow();
|
|
|
|
w.setLocation(getX() + 10 + getWidth(), getY());
|
|
|
|
w.setVisible(true);
|
|
|
|
}
|
|
|
|
if (src == flipToNewestPost)
|
|
|
|
{
|
|
|
|
showLatestPage();
|
|
|
|
}
|
2021-07-31 06:01:20 +02:00
|
|
|
if (src == quit)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Umm.. should we even have a quit option?
|
|
|
|
* Wouldn't closing every window work? By
|
|
|
|
* disposing of everyone. We won't be having any
|
|
|
|
* background threads IIRC (and they can check
|
|
|
|
* if the Swing thread is alive).
|
|
|
|
*/
|
2022-04-12 08:37:39 +02:00
|
|
|
dispose();
|
2021-07-31 06:01:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
// - -%- -
|
|
|
|
|
|
|
|
private static List<Post>
|
|
|
|
toPosts(Tree<String> json)
|
|
|
|
{
|
|
|
|
List<Post> posts = new ArrayList<>();
|
|
|
|
for (Tree<String> post: json.children)
|
|
|
|
{
|
|
|
|
Tree<String> account = post.get("account");
|
|
|
|
Post addee = new Post();
|
|
|
|
addee.postId = post.get("id").value;
|
|
|
|
try {
|
|
|
|
String s = post.get("created_at").value;
|
|
|
|
addee.date = ZonedDateTime.parse(s);
|
|
|
|
ZoneId z = ZoneId.systemDefault();
|
|
|
|
addee.date = addee.date.withZoneSameInstant(z);
|
|
|
|
}
|
|
|
|
catch (DateTimeParseException eDt) {
|
|
|
|
assert false;
|
|
|
|
addee.date = ZonedDateTime.now();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
StringBuilder b = new StringBuilder();
|
|
|
|
Tree<String> nodes =
|
|
|
|
RudimentaryHTMLParser
|
|
|
|
.depthlessRead(post.get("content").value);
|
|
|
|
for (Tree<String> node: nodes.children)
|
|
|
|
{
|
|
|
|
if (node.key.equals("tag"))
|
|
|
|
{
|
|
|
|
if (node.get(0).key.equals("br")) {
|
|
|
|
b.append(" \n ");
|
|
|
|
}
|
|
|
|
if (node.get(0).key.equals("/p")) {
|
|
|
|
b.append(" \n\n ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (node.key.equals("text")) {
|
|
|
|
b.append(node.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addee.text = b.toString();
|
|
|
|
}
|
|
|
|
catch (IOException eIo) {
|
|
|
|
eIo.printStackTrace();
|
|
|
|
assert false;
|
|
|
|
}
|
|
|
|
String s = post.get("spoiler_text").value;
|
|
|
|
if (!s.isEmpty()) addee.contentWarning = s;
|
|
|
|
else addee.contentWarning = null;
|
|
|
|
addee.authorId = account.get("acct").value;
|
|
|
|
addee.authorName = account.get("username").value;
|
|
|
|
String s2 = account.get("display_name").value;
|
|
|
|
if (!s2.isEmpty()) addee.authorName = s2;
|
|
|
|
String f = post.get("favourited").value;
|
|
|
|
String b = post.get("reblogged").value;
|
|
|
|
addee.favourited = f.equals("true");
|
|
|
|
addee.boosted = b.equals("true");
|
|
|
|
posts.add(addee);
|
|
|
|
}
|
|
|
|
return posts;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String
|
|
|
|
plainify(String html)
|
|
|
|
{
|
|
|
|
// Delete all tags.
|
|
|
|
StringBuilder b = new StringBuilder();
|
|
|
|
boolean in = false;
|
|
|
|
for (char c: html.toCharArray()) switch (c) {
|
|
|
|
case '<': in = true; break;
|
|
|
|
case '>': in = false; break;
|
|
|
|
default: if (!in) b.append(c);
|
|
|
|
}
|
|
|
|
String s = b.toString();
|
|
|
|
s = s.replaceAll("<", "<");
|
|
|
|
s = s.replaceAll(">", ">");
|
|
|
|
s = s.replaceAll(" ", "");
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-07-16 01:07:23 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
TimelineWindow(JKomasto primaire)
|
2021-07-16 01:07:23 +02:00
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
this.primaire = primaire;
|
|
|
|
this.api = primaire.getMastodonApi();
|
|
|
|
|
|
|
|
getContentPane().setPreferredSize(new Dimension(320, 460));
|
2021-07-16 11:46:17 +02:00
|
|
|
pack();
|
|
|
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
|
|
|
2021-07-31 06:01:20 +02:00
|
|
|
openHome = new JMenuItem("Open home timeline");
|
|
|
|
openFederated = new JMenuItem("Open federated timeline");
|
|
|
|
createPost = new JMenuItem("Create a post");
|
|
|
|
openAutoPostView = new JMenuItem("Open auto post view");
|
|
|
|
quit = new JMenuItem("Quit");
|
|
|
|
openHome.addActionListener(this);
|
|
|
|
openFederated.addActionListener(this);
|
|
|
|
createPost.addActionListener(this);
|
|
|
|
openAutoPostView.addActionListener(this);
|
|
|
|
quit.addActionListener(this);
|
|
|
|
|
|
|
|
flipToNewestPost = new JMenuItem("Flip to newest post");
|
|
|
|
flipToNewestPost.addActionListener(this);
|
|
|
|
|
2021-07-17 12:03:59 +02:00
|
|
|
JMenu programMenu = new JMenu("Program");
|
2021-07-31 06:01:20 +02:00
|
|
|
programMenu.add(openHome);
|
|
|
|
programMenu.add(openFederated);
|
2021-07-17 12:03:59 +02:00
|
|
|
programMenu.add(new JSeparator());
|
2021-07-31 06:01:20 +02:00
|
|
|
programMenu.add(createPost);
|
|
|
|
programMenu.add(openAutoPostView);
|
2021-07-17 12:03:59 +02:00
|
|
|
programMenu.add(new JSeparator());
|
2021-07-31 06:01:20 +02:00
|
|
|
programMenu.add(quit);
|
2021-07-17 12:03:59 +02:00
|
|
|
JMenu timelineMenu = new JMenu("Timeline");
|
2021-07-31 06:01:20 +02:00
|
|
|
timelineMenu.add(flipToNewestPost);
|
2021-07-17 12:03:59 +02:00
|
|
|
JMenuBar menuBar = new JMenuBar();
|
|
|
|
menuBar.add(programMenu);
|
|
|
|
menuBar.add(timelineMenu);
|
|
|
|
setJMenuBar(menuBar);
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
page = new TimelinePage();
|
|
|
|
page.posts = new ArrayList<>();
|
|
|
|
setTimelineType(TimelineType.FEDERATED);
|
|
|
|
|
2021-07-31 06:01:20 +02:00
|
|
|
display = new TimelineComponent(this);
|
2022-04-12 08:37:39 +02:00
|
|
|
display.setNextPageAvailable(false);
|
|
|
|
display.setPreviousPageAvailable(false);
|
2021-07-17 12:03:59 +02:00
|
|
|
|
|
|
|
setContentPane(display);
|
2021-07-16 01:07:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class
|
2021-07-31 06:01:20 +02:00
|
|
|
TimelineComponent extends JPanel
|
2022-04-12 08:37:39 +02:00
|
|
|
implements ActionListener, MouseListener {
|
2021-07-31 06:01:20 +02:00
|
|
|
|
|
|
|
private TimelineWindow
|
|
|
|
primaire;
|
|
|
|
|
|
|
|
private final List<Post>
|
|
|
|
posts = new ArrayList<>();
|
|
|
|
|
|
|
|
// - -%- -
|
2021-07-16 01:07:23 +02:00
|
|
|
|
2021-07-17 11:06:50 +02:00
|
|
|
private JButton
|
|
|
|
next, prev;
|
|
|
|
|
|
|
|
private JLabel
|
|
|
|
pageLabel;
|
|
|
|
|
2021-07-17 11:46:27 +02:00
|
|
|
private final List<PostPreviewComponent>
|
2022-04-12 08:37:39 +02:00
|
|
|
postPreviews;
|
|
|
|
|
|
|
|
private boolean
|
|
|
|
hoverSelect;
|
|
|
|
|
|
|
|
// - -%- -
|
|
|
|
|
|
|
|
static final int
|
|
|
|
PREVIEW_COUNT = 10;
|
2021-07-17 11:06:50 +02:00
|
|
|
|
2021-07-29 11:40:52 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public void
|
2021-07-31 06:01:20 +02:00
|
|
|
setPosts(List<Post> posts)
|
|
|
|
{
|
|
|
|
this.posts.clear();
|
|
|
|
this.posts.addAll(posts);
|
2022-04-12 08:37:39 +02:00
|
|
|
|
|
|
|
assert posts.size() <= postPreviews.size();
|
|
|
|
for (int o = 0; o < posts.size(); ++o)
|
|
|
|
{
|
|
|
|
PostPreviewComponent c = postPreviews.get(o);
|
|
|
|
Post p = posts.get(o);
|
|
|
|
c.setTopLeft(p.authorName);
|
|
|
|
{
|
|
|
|
ZonedDateTime now = ZonedDateTime.now();
|
|
|
|
long d = ChronoUnit.SECONDS.between(p.date, now);
|
|
|
|
long s = Math.abs(d);
|
|
|
|
if (s < 30) c.setTopRight("now");
|
|
|
|
else if (s < 60) c.setTopRight(d + "s");
|
|
|
|
else if (s < 3600) c.setTopRight((d / 60) + "m");
|
|
|
|
else if (s < 86400) c.setTopRight((d / 3600) + "h");
|
|
|
|
else c.setTopRight((d / 86400) + "d");
|
|
|
|
}
|
|
|
|
if (p.contentWarning != null)
|
|
|
|
c.setBottom("(" + p.contentWarning + ")");
|
|
|
|
else
|
|
|
|
c.setBottom(p.text + " ");
|
|
|
|
}
|
|
|
|
for (int o = posts.size(); o < postPreviews.size(); ++o)
|
|
|
|
{
|
|
|
|
postPreviews.get(o).reset();
|
|
|
|
}
|
2021-07-31 06:01:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
setPageLabel(String label)
|
|
|
|
{
|
|
|
|
assert label != null;
|
|
|
|
pageLabel.setText("" + label);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
setNextPageAvailable(boolean available)
|
|
|
|
{
|
|
|
|
next.setEnabled(available);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
setPreviousPageAvailable(boolean available)
|
|
|
|
{
|
|
|
|
prev.setEnabled(available);
|
|
|
|
}
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
public void
|
|
|
|
setHoverSelect(boolean a) { this.hoverSelect = a; }
|
|
|
|
|
2021-07-31 06:01:20 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
public void
|
|
|
|
mouseEntered(MouseEvent eM)
|
2021-07-29 11:40:52 +02:00
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
if (!hoverSelect) return;
|
|
|
|
mouseClicked(eM);
|
|
|
|
}
|
|
|
|
|
|
|
|
// (知) First time I'm using one of these..!
|
|
|
|
|
|
|
|
public void
|
|
|
|
mouseClicked(MouseEvent eM)
|
|
|
|
{
|
|
|
|
int offset = postPreviews.indexOf(eM.getSource());
|
|
|
|
assert offset != -1;
|
|
|
|
primaire.postSelected(posts.get(offset));
|
|
|
|
postPreviews.get(offset).setSelected(true);
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
mouseExited(MouseEvent eM)
|
|
|
|
{
|
|
|
|
if (!hoverSelect) return;
|
|
|
|
int offset = postPreviews.indexOf(eM.getSource());
|
|
|
|
assert offset != -1;
|
|
|
|
postPreviews.get(offset).setSelected(false);
|
|
|
|
repaint();
|
2021-07-31 06:01:20 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
public void
|
|
|
|
mousePressed(MouseEvent eM) { }
|
|
|
|
|
|
|
|
public void
|
|
|
|
mouseReleased(MouseEvent eM) { }
|
|
|
|
|
|
|
|
// - -%- -
|
|
|
|
|
2021-07-31 06:01:20 +02:00
|
|
|
public void
|
|
|
|
actionPerformed(ActionEvent eA)
|
|
|
|
{
|
|
|
|
Object src = eA.getSource();
|
|
|
|
|
2021-07-31 13:28:46 +02:00
|
|
|
if (src == next) primaire.nextPage();
|
|
|
|
else if (src == prev) primaire.previousPage();
|
2021-07-29 11:40:52 +02:00
|
|
|
/*
|
2021-07-31 06:01:20 +02:00
|
|
|
* I think the page previews will just forward to us.
|
|
|
|
* But I think they'll have to tell us where they are
|
|
|
|
* in the list somehow, because we need to show only
|
|
|
|
* one post as selected.
|
2021-07-29 11:40:52 +02:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2021-07-17 11:06:50 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
2021-07-31 06:01:20 +02:00
|
|
|
TimelineComponent(TimelineWindow primaire)
|
2021-07-16 01:07:23 +02:00
|
|
|
{
|
2021-07-31 06:01:20 +02:00
|
|
|
this.primaire = primaire;
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
postPreviews = new ArrayList<>(PREVIEW_COUNT);
|
|
|
|
hoverSelect = true;
|
|
|
|
|
2021-07-17 11:06:50 +02:00
|
|
|
prev = new JButton("<");
|
|
|
|
next = new JButton(">");
|
2021-07-31 06:01:20 +02:00
|
|
|
prev.setEnabled(false);
|
|
|
|
next.setEnabled(false);
|
2022-04-12 08:37:39 +02:00
|
|
|
prev.addActionListener(this);
|
|
|
|
next.addActionListener(this);
|
2021-07-31 06:01:20 +02:00
|
|
|
|
|
|
|
pageLabel = new JLabel("0");
|
2021-07-17 11:06:50 +02:00
|
|
|
|
|
|
|
Box bottom = Box.createHorizontalBox();
|
|
|
|
bottom.add(Box.createGlue());
|
|
|
|
bottom.add(prev);
|
|
|
|
bottom.add(Box.createHorizontalStrut(8));
|
|
|
|
bottom.add(next);
|
|
|
|
|
|
|
|
JPanel centre = new JPanel();
|
|
|
|
centre.setOpaque(false);
|
|
|
|
centre.setLayout(new GridBagLayout());
|
|
|
|
GridBagConstraints constraints = new GridBagConstraints();
|
|
|
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
|
|
|
constraints.gridx = 0;
|
|
|
|
constraints.weightx = 1;
|
|
|
|
constraints.insets = new Insets(4, 0, 4, 0);
|
2022-04-12 08:37:39 +02:00
|
|
|
for (int n = PREVIEW_COUNT; n > 0; --n)
|
2021-07-17 11:06:50 +02:00
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
PostPreviewComponent c = new PostPreviewComponent();
|
|
|
|
c.reset();
|
|
|
|
c.addMouseListener(this);
|
|
|
|
centre.add(c, constraints);
|
|
|
|
postPreviews.add(c);
|
2021-07-17 11:06:50 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 01:07:23 +02:00
|
|
|
setLayout(new BorderLayout());
|
2021-07-17 11:06:50 +02:00
|
|
|
add(centre, BorderLayout.CENTER);
|
|
|
|
add(bottom, BorderLayout.SOUTH);
|
|
|
|
|
|
|
|
setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
2021-07-16 01:07:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-16 00:37:03 +02:00
|
|
|
class
|
2021-07-17 11:46:27 +02:00
|
|
|
PostPreviewComponent extends JComponent {
|
2021-07-16 00:37:03 +02:00
|
|
|
|
|
|
|
private JLabel
|
|
|
|
topLeft, topRight, bottom;
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public void
|
|
|
|
setTopLeft(String text) { topLeft.setText(text); }
|
|
|
|
|
|
|
|
public void
|
|
|
|
setTopRight(String text) { topRight.setText(text); }
|
|
|
|
|
|
|
|
public void
|
|
|
|
setBottom(String text) { bottom.setText(text); }
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
public void
|
|
|
|
reset()
|
|
|
|
{
|
|
|
|
setTopLeft(" ");
|
|
|
|
setTopRight(" ");
|
|
|
|
setBottom(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
setSelected(boolean selected)
|
|
|
|
{
|
|
|
|
if (!selected) setBackground(null);
|
|
|
|
else setBackground(new Color(0, 0, 0, 25));
|
|
|
|
}
|
|
|
|
|
|
|
|
// - -%- -
|
|
|
|
|
|
|
|
protected void
|
|
|
|
paintComponent(Graphics g)
|
|
|
|
{
|
|
|
|
g.setColor(getBackground());
|
|
|
|
g.fillRect(0, 0, getWidth(), getHeight());
|
|
|
|
}
|
|
|
|
|
2021-07-16 00:37:03 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public
|
2021-07-17 11:46:27 +02:00
|
|
|
PostPreviewComponent()
|
2021-07-16 00:37:03 +02:00
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
Font f = new JLabel().getFont();
|
|
|
|
Font f1 = f.deriveFont(Font.PLAIN, 12f);
|
|
|
|
Font f2 = f.deriveFont(Font.ITALIC, 12f);
|
|
|
|
Font f3 = f.deriveFont(Font.PLAIN, 14f);
|
2021-07-16 00:37:03 +02:00
|
|
|
|
2021-07-31 06:01:20 +02:00
|
|
|
topLeft = new JLabel();
|
2022-04-12 08:37:39 +02:00
|
|
|
topLeft.setFont(f1);
|
2021-07-16 00:37:03 +02:00
|
|
|
setOpaque(false);
|
|
|
|
|
2021-07-31 06:01:20 +02:00
|
|
|
topRight = new JLabel();
|
2021-07-16 00:37:03 +02:00
|
|
|
topRight.setHorizontalAlignment(JLabel.RIGHT);
|
2022-04-12 08:37:39 +02:00
|
|
|
topRight.setFont(f2);
|
2021-07-16 00:37:03 +02:00
|
|
|
setOpaque(false);
|
|
|
|
|
2021-07-31 06:01:20 +02:00
|
|
|
bottom = new JLabel();
|
2022-04-12 08:37:39 +02:00
|
|
|
bottom.setFont(f3);
|
2021-07-16 00:37:03 +02:00
|
|
|
bottom.setOpaque(false);
|
|
|
|
|
|
|
|
Box top = Box.createHorizontalBox();
|
2022-04-12 08:37:39 +02:00
|
|
|
top.setOpaque(false);
|
2021-07-16 00:37:03 +02:00
|
|
|
top.add(topLeft);
|
|
|
|
top.add(Box.createGlue());
|
|
|
|
top.add(topRight);
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
setOpaque(false);
|
|
|
|
setSelected(false);
|
2021-07-16 00:37:03 +02:00
|
|
|
setLayout(new BorderLayout());
|
|
|
|
add(top, BorderLayout.NORTH);
|
2022-04-12 08:37:39 +02:00
|
|
|
add(bottom);
|
2021-07-16 00:37:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|