mirror of
https://gitlab.com/biskuteri-cafe/JKomasto2.git
synced 2024-11-20 05:04:51 +01:00
203 lines
4.8 KiB
Java
203 lines
4.8 KiB
Java
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JComponent;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JMenu;
|
|
import javax.swing.JMenuBar;
|
|
import javax.swing.JSeparator;
|
|
import javax.swing.Box;
|
|
import javax.swing.BorderFactory;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.FlowLayout;
|
|
import java.awt.Font;
|
|
import java.awt.Dimension;
|
|
import java.awt.Insets;
|
|
import java.util.List;
|
|
import java.util.ArrayList;
|
|
|
|
class
|
|
TimelineWindow extends JFrame {
|
|
|
|
private Timeline
|
|
timeline;
|
|
|
|
// - -%- -
|
|
|
|
private TimelineComponent
|
|
display;
|
|
|
|
// ---%-@-%---
|
|
|
|
public void
|
|
setTimeline(Timeline timeline)
|
|
{
|
|
if (timeline == null)
|
|
{
|
|
timeline = new Timeline();
|
|
timeline.type = TimelineType.LOCAL;
|
|
}
|
|
|
|
assert timeline != null;
|
|
this.timeline = timeline;
|
|
|
|
// Here, we should request for posts for the timeline.
|
|
// And pass data to TimelineComponent.
|
|
}
|
|
|
|
// ---%-@-%---
|
|
|
|
TimelineWindow()
|
|
{
|
|
getContentPane().setPreferredSize(new Dimension(300, 400));
|
|
pack();
|
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
|
|
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(new JSeparator());
|
|
programMenu.add("Create a post");
|
|
programMenu.add("Open auto post view");
|
|
programMenu.add(new JSeparator());
|
|
programMenu.add("Quit");
|
|
JMenu timelineMenu = new JMenu("Timeline");
|
|
timelineMenu.add("Flip to newest post");
|
|
JMenuBar menuBar = new JMenuBar();
|
|
menuBar.add(programMenu);
|
|
menuBar.add(timelineMenu);
|
|
setJMenuBar(menuBar);
|
|
|
|
display = new TimelineComponent();
|
|
|
|
setContentPane(display);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class
|
|
TimelineComponent extends JPanel {
|
|
|
|
private JButton
|
|
next, prev;
|
|
|
|
private JLabel
|
|
pageLabel;
|
|
|
|
private final List<PostPreviewComponent>
|
|
postPreviews = new ArrayList<>();
|
|
|
|
// ---%-@-%---
|
|
|
|
public void
|
|
setPosts()
|
|
{
|
|
/*
|
|
* 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.
|
|
*/
|
|
}
|
|
|
|
// ---%-@-%---
|
|
|
|
TimelineComponent()
|
|
{
|
|
prev = new JButton("<");
|
|
next = new JButton(">");
|
|
|
|
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);
|
|
for (int n = 8; n > 0; --n)
|
|
{
|
|
PostPreviewComponent p = new PostPreviewComponent();
|
|
centre.add(p, constraints);
|
|
postPreviews.add(p);
|
|
}
|
|
|
|
setLayout(new BorderLayout());
|
|
add(centre, BorderLayout.CENTER);
|
|
add(bottom, BorderLayout.SOUTH);
|
|
|
|
setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class
|
|
PostPreviewComponent extends JComponent {
|
|
|
|
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); }
|
|
|
|
// ---%-@-%---
|
|
|
|
public
|
|
PostPreviewComponent()
|
|
{
|
|
Font font;
|
|
|
|
topLeft = new JLabel("Top left");
|
|
font = topLeft.getFont();
|
|
topLeft.setFont(font.deriveFont(Font.PLAIN, 12f));
|
|
setOpaque(false);
|
|
|
|
topRight = new JLabel("Top right");
|
|
topRight.setHorizontalAlignment(JLabel.RIGHT);
|
|
font = topRight.getFont();
|
|
topRight.setFont(font.deriveFont(Font.ITALIC, 12f));
|
|
setOpaque(false);
|
|
|
|
bottom = new JLabel("Bottom");
|
|
font = bottom.getFont();
|
|
bottom.setFont(font.deriveFont(Font.PLAIN, 16f));
|
|
bottom.setOpaque(false);
|
|
|
|
Box top = Box.createHorizontalBox();
|
|
top.add(topLeft);
|
|
top.add(Box.createGlue());
|
|
top.add(topRight);
|
|
|
|
setLayout(new BorderLayout());
|
|
add(top, BorderLayout.NORTH);
|
|
add(bottom, BorderLayout.SOUTH);
|
|
}
|
|
|
|
}
|