Refactored to follow windows architecture.

This commit is contained in:
Snowyfox 2021-07-15 19:07:23 -04:00
parent 8659d7d291
commit 5defb14735
6 changed files with 227 additions and 140 deletions

28
ComposeWindow.java Normal file
View File

@ -0,0 +1,28 @@
import javax.swing.JFrame;
import javax.swing.JPanel;
class
ComposeWindow extends JFrame {
private ComposeComponent
display;
// ---%-@-%---
// ---%-@-%---
ComposeWindow()
{
display = new ComposeComponent();
setContentPane(display);
}
}
class
ComposeComponent extends JPanel {
}

View File

@ -1,35 +1,59 @@
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComponent;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.BorderLayout;
class
JKomasto extends JPanel {
JKomasto {
public void
openTimelineWindow() {
}
public void
openPostWindow() {
}
public void
openComposeWindow() {
}
// ---%-@-%---
public static void
main(String... args)
{
JFrame mainframe = new JFrame("JKomasto");
mainframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
mainframe.setLocationByPlatform(true);
JKomasto instance = new JKomasto();
mainframe.add(instance);
mainframe.pack();
mainframe.setVisible(true);
new PostWindow().setVisible(true);
}
// ---%-@-%---
JKomasto()
{
setPreferredSize(new Dimension(360, 270));
setLayout(new GridLayout());
add(new PreviewComponent());
}
// - -%- -
private static void
test(JComponent component, int width, int height)
{
JFrame frame = new JFrame();
frame.setTitle(component.getClass().getName());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationByPlatform(true);
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(width, height));
panel.add(component);
frame.setContentPane(panel);
frame.setVisible(true);
}
}

View File

@ -1,55 +0,0 @@
import javax.swing.JPanel;
import java.awt.Graphics;
class
PostComponent extends JPanel {
private String
author, time, text;
// ---%-@-%---
public void
setAuthor(String author)
{
assert author != null;
this.author = author;
}
public void
setTime(String time)
{
assert time != null;
this.time = time;
}
public void
setText(String text)
{
assert text != null;
this.text = text;
}
// - -%- -
protected void
paintComponent(Graphics g)
{
int lineHeight = 24;
g.drawString(author, 0, lineHeight);
g.drawString(text, 0, 2 * lineHeight);
}
// ---%-@-%---
PostComponent()
{
author = "Author";
time = "Time";
text = "This is a soft post..";
}
}

View File

@ -1,8 +1,18 @@
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.Box;
import javax.swing.BorderFactory;
import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.util.List;
import java.util.ArrayList;
class
PostWindow extends JFrame {
@ -38,3 +48,120 @@ PostWindow extends JFrame {
}
}
class
PostComponent extends JPanel {
private String
author, time, text;
// ---%-@-%---
public void
setAuthor(String author)
{
assert author != null;
this.author = author;
}
public void
setTime(String time)
{
assert time != null;
this.time = time;
}
public void
setText(String text)
{
assert text != null;
this.text = text;
}
// - -%- -
protected void
paintComponent(Graphics g)
{
int lineHeight = 24;
g.drawString(author, 0, lineHeight);
g.drawString(text, 0, 2 * lineHeight);
}
// ---%-@-%---
PostComponent()
{
author = "Author";
time = "Time";
text = "This is a soft post..";
}
}
class
RepliesComponent extends JPanel {
private List<String>
authors, texts;
private JButton
prevPage, nextPage;
private JLabel
pageLabel;
// ---%-@-%---
public void
setReplies(List<String> authors, List<String> texts)
{
this.authors.clear();
this.authors.addAll(authors);
this.texts.clear();
this.texts.addAll(texts);
}
// ---%-@-%---
RepliesComponent()
{
authors = new ArrayList<>();
texts = new ArrayList<>();
prevPage = new JButton("<");
nextPage = new JButton(">");
prevPage.setEnabled(false);
nextPage.setEnabled(false);
pageLabel = new JLabel("0 / 0");
Box bottom = Box.createHorizontalBox();
bottom.add(Box.createGlue());
bottom.add(prevPage);
bottom.add(pageLabel);
bottom.add(nextPage);
JPanel centre = new JPanel();
centre.setLayout(new GridLayout(0, 1, 0, 2));
for (int n = 8; n > 0; --n) {
String label = "Eggplant -%- A short reply..";
JButton reply = new JButton(label);
// We likely need a custom class..
centre.add(reply);
}
setLayout(new BorderLayout(4, 4));
add(centre, BorderLayout.CENTER);
add(bottom, BorderLayout.SOUTH);
setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
}
}

View File

@ -1,71 +0,0 @@
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.Box;
import javax.swing.BorderFactory;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.util.List;
import java.util.ArrayList;
class
RepliesComponent extends JPanel {
private List<String>
authors, texts;
private JButton
prevPage, nextPage;
private JLabel
pageLabel;
// ---%-@-%---
public void
setReplies(List<String> authors, List<String> texts)
{
this.authors.clear();
this.authors.addAll(authors);
this.texts.clear();
this.texts.addAll(texts);
}
// ---%-@-%---
RepliesComponent()
{
authors = new ArrayList<>();
texts = new ArrayList<>();
prevPage = new JButton("<");
nextPage = new JButton(">");
prevPage.setEnabled(false);
nextPage.setEnabled(false);
pageLabel = new JLabel("0 / 0");
Box bottom = Box.createHorizontalBox();
bottom.add(Box.createGlue());
bottom.add(prevPage);
bottom.add(pageLabel);
bottom.add(nextPage);
JPanel centre = new JPanel();
centre.setLayout(new GridLayout(0, 1, 0, 2));
for (int n = 8; n > 0; --n) {
String label = "Eggplant -%- A short reply..";
JButton reply = new JButton(label);
// We likely need a custom class..
centre.add(reply);
}
setLayout(new BorderLayout(4, 4));
add(centre, BorderLayout.CENTER);
add(bottom, BorderLayout.SOUTH);
setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
}
}

View File

@ -1,10 +1,44 @@
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.Box;
import java.awt.BorderLayout;
import java.awt.Font;
class
TimelineWindow extends JFrame {
private TimelineComponent
display;
// ---%-@-%---
// ---%-@-%---
TimelineWindow()
{
setContentPane(display);
}
}
class
TimelineComponent extends JPanel {
TimelineComponent()
{
setLayout(new BorderLayout());
add(new PreviewComponent());
}
}
class
PreviewComponent extends JComponent {