Added roles for timeline components

This commit is contained in:
Snowyfox 2021-07-31 00:01:20 -04:00
parent ce22349538
commit dd42213858

View File

@ -5,6 +5,7 @@ import javax.swing.JComponent;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JSeparator;
import javax.swing.Box;
@ -18,9 +19,12 @@ import java.awt.Dimension;
import java.awt.Insets;
import java.util.List;
import java.util.ArrayList;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class
TimelineWindow extends JFrame {
TimelineWindow extends JFrame
implements ActionListener {
private Timeline
timeline;
@ -30,6 +34,20 @@ TimelineWindow extends JFrame {
private TimelineComponent
display;
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;
// ---%-@-%---
public void
@ -48,6 +66,25 @@ TimelineWindow extends JFrame {
// And pass data to TimelineComponent.
}
// - -%- -
public void
actionPerformed(ActionEvent eA)
{
Object src = eA.getSource();
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).
*/
}
}
// ---%-@-%---
TimelineWindow()
@ -56,24 +93,36 @@ TimelineWindow extends JFrame {
pack();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
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);
JMenu programMenu = new JMenu("Program");
programMenu.add("Open home timeline");
programMenu.add("Open messages timeline");
programMenu.add("Open local timeline");
programMenu.add("Open federated timeline");
programMenu.add(openHome);
programMenu.add(openFederated);
programMenu.add(new JSeparator());
programMenu.add("Create a post");
programMenu.add("Open auto post view");
programMenu.add(createPost);
programMenu.add(openAutoPostView);
programMenu.add(new JSeparator());
programMenu.add("Quit");
programMenu.add(quit);
JMenu timelineMenu = new JMenu("Timeline");
timelineMenu.add("Flip to newest post");
timelineMenu.add(flipToNewestPost);
JMenuBar menuBar = new JMenuBar();
menuBar.add(programMenu);
menuBar.add(timelineMenu);
setJMenuBar(menuBar);
display = new TimelineComponent();
display = new TimelineComponent(this);
setContentPane(display);
}
@ -83,7 +132,16 @@ TimelineWindow extends JFrame {
class
TimelineComponent extends JPanel {
TimelineComponent extends JPanel
implements ActionListener {
private TimelineWindow
primaire;
private final List<Post>
posts = new ArrayList<>();
// - -%- -
private JButton
next, prev;
@ -97,25 +155,88 @@ TimelineComponent extends JPanel {
// ---%-@-%---
public void
setPosts()
setPosts(List<Post> posts)
{
if (posts == null)
{
posts = new ArrayList<>();
// Insert sample timeline posts here
}
this.posts.clear();
this.posts.addAll(posts);
syncPreviewsToPosts();
// We don't store pagination information. We need the
// model manager to inform us about page availability.
}
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);
}
// - -%- -
private void
syncPreviewsToPosts()
{
for (PostPreviewComponent p: postPreviews)
{
p.setTopLeft("Top left");
p.setTopRight("Top right");
p.setBottom("Bottom");
// (In reality we are supposed to map with posts)
}
}
public void
actionPerformed(ActionEvent eA)
{
Object src = eA.getSource();
if (src == next)
{
}
else if (src == prev)
{
}
/*
* Okay, so timelines are infinite, unlike replies.
* We can ask for a finite list of post preview data,
* but we're the ones holding the pagination information?
*
* Or rather, we don't currently.. we should think out
* timeline pagination, then have TimelineWindow hold
* the data.
* 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.
*/
}
// ---%-@-%---
TimelineComponent()
TimelineComponent(TimelineWindow primaire)
{
this.primaire = primaire;
prev = new JButton("<");
next = new JButton(">");
prev.setEnabled(false);
next.setEnabled(false);
pageLabel = new JLabel("0");
Box bottom = Box.createHorizontalBox();
bottom.add(Box.createGlue());
@ -143,6 +264,8 @@ TimelineComponent extends JPanel {
add(bottom, BorderLayout.SOUTH);
setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
setPosts(null);
}
}
@ -173,18 +296,18 @@ PostPreviewComponent extends JComponent {
{
Font font;
topLeft = new JLabel("Top left");
topLeft = new JLabel();
font = topLeft.getFont();
topLeft.setFont(font.deriveFont(Font.PLAIN, 12f));
setOpaque(false);
topRight = new JLabel("Top right");
topRight = new JLabel();
topRight.setHorizontalAlignment(JLabel.RIGHT);
font = topRight.getFont();
topRight.setFont(font.deriveFont(Font.ITALIC, 12f));
setOpaque(false);
bottom = new JLabel("Bottom");
bottom = new JLabel();
font = bottom.getFont();
bottom.setFont(font.deriveFont(Font.PLAIN, 16f));
bottom.setOpaque(false);