mirror of
https://gitlab.com/biskuteri-cafe/JKomasto2.git
synced 2024-11-20 05:04:51 +01:00
Added start of project.
This commit is contained in:
commit
8659d7d291
19
ArchitectureProposals.txt
Normal file
19
ArchitectureProposals.txt
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
(1) The Tab Manager
|
||||
|
||||
The GUI is centralised around an always-present Tab Manager. It keeps track of what timelines, what posts, and what reply sessions, are open.
|
||||
|
||||
There is a singular timeline window, post window, and reply window. They are highly integrated with the tab manager, displaying what it says is selected.
|
||||
|
||||
The windows get their domain object from the tab manager, and handle rendering it into their content pane.
|
||||
|
||||
Everyone has a mix of forwarding actions, and abstract actions.
|
||||
|
||||
|
||||
(2) The Windows
|
||||
|
||||
This classical design is centralised on no one. It has the application close when all windows are closed. Regular windows are spawned by actions, and special windows can be opened by menu.
|
||||
|
||||
The hidden application instance provides window management services and access to the data interchange. But all windows store and manage their domain objects by themselves.
|
||||
|
||||
Windows will probably be local controllers, while their content panes are controlled components.
|
35
JKomasto.java
Normal file
35
JKomasto.java
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
class
|
||||
JKomasto extends JPanel {
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
55
PostComponent.java
Normal file
55
PostComponent.java
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
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..";
|
||||
}
|
||||
|
||||
}
|
40
PostWindow.java
Normal file
40
PostWindow.java
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenu;
|
||||
import java.awt.Dimension;
|
||||
|
||||
class
|
||||
PostWindow extends JFrame {
|
||||
|
||||
private PostComponent
|
||||
posts;
|
||||
|
||||
private RepliesComponent
|
||||
replies;
|
||||
|
||||
// ---%-@-%---
|
||||
|
||||
// ---%-@-%---
|
||||
|
||||
PostWindow()
|
||||
{
|
||||
setLocationByPlatform(true);
|
||||
|
||||
posts = new PostComponent();
|
||||
|
||||
replies = new RepliesComponent();
|
||||
|
||||
JMenu postMenu = new JMenu("Post");
|
||||
postMenu.add("Favourite");
|
||||
postMenu.add("Reply");
|
||||
postMenu.add("Show replies");
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.add(postMenu);
|
||||
setJMenuBar(menuBar);
|
||||
|
||||
setContentPane(posts);
|
||||
setSize(360, 270);
|
||||
}
|
||||
|
||||
}
|
58
PreviewComponent.java
Normal file
58
PreviewComponent.java
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.Box;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Font;
|
||||
|
||||
class
|
||||
PreviewComponent 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
|
||||
PreviewComponent()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
71
RepliesComponent.java
Normal file
71
RepliesComponent.java
Normal file
@ -0,0 +1,71 @@
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user