Added timeline background functionality.

Bug fix on ImageWindow.
This commit is contained in:
Snowyfox 2022-04-12 08:48:24 -04:00
parent 0a3154bbfb
commit 28c7da2034
4 changed files with 65 additions and 26 deletions

View File

@ -5,6 +5,7 @@ import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
@ -72,12 +73,13 @@ ImageWindow extends JFrame {
toImage(int offset)
{
int last = attachments.length - 1;
assert offset >= 0;
assert offset < attachments.length;
Attachment prev, curr, next;
curr = attachments[offset];
prev = offset < last ? attachments[offset + 1] : null;
next = offset > 0 ? attachments[offset - 1] : null;
next = offset < last ? attachments[offset + 1] : null;
prev = offset > 0 ? attachments[offset - 1] : null;
display.setImage(curr.image);
display.setNext(next != null ? next.image : null);
@ -283,6 +285,8 @@ implements
{
this.primaire = primaire;
Dimension BUTTON_SIZE = new Dimension(80, 60);
setOpaque(false);
scaleImage = true;
zoomLevel = 100;
@ -290,6 +294,8 @@ implements
prev = new JButton("<");
toggle = new JButton("Show unscaled");
next = new JButton(">");
prev.setPreferredSize(BUTTON_SIZE);
next.setPreferredSize(BUTTON_SIZE);
prev.addActionListener(this);
toggle.addActionListener(this);
next.addActionListener(this);

View File

@ -21,6 +21,7 @@ import java.awt.Insets;
import java.awt.Cursor;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.util.List;
import java.util.ArrayList;
import java.net.URL;
@ -81,9 +82,21 @@ implements ActionListener {
setTimelineType(TimelineType type)
{
page.type = type;
String s = type.toString();
s = s.charAt(0) + s.substring(1).toLowerCase();
setTitle(s + " - JKomasto");
String s1 = type.toString();
s1 = s1.charAt(0) + s1.substring(1).toLowerCase();
setTitle(s1 + " - JKomasto");
String s2 = type.toString().toLowerCase();
s2 = "/graphics/" + s2 + ".png";
URL url = getClass().getResource(s2);
if (url != null) {
ImageIcon icon = new ImageIcon(url);
display.setBackgroundImage(icon.getImage());
}
else {
display.setBackgroundImage(null);
}
}
public void
@ -310,6 +323,9 @@ implements ActionListener {
else addee.contentWarning = null;
Tree<String> account = post.get("account");
if (post.get("reblog").size() != 0) {
account = post.get("reblog").get("account");
}
addee.authorId = account.get("acct").value;
addee.authorName = account.get("username").value;
String s2 = account.get("display_name").value;
@ -418,13 +434,13 @@ implements ActionListener {
page = new TimelinePage();
page.posts = new ArrayList<>();
setTimelineType(TimelineType.HOME);
display = new TimelineComponent(this);
display.setNextPageAvailable(false);
display.setPreviousPageAvailable(false);
setContentPane(display);
setTimelineType(TimelineType.HOME);
}
}
@ -455,6 +471,9 @@ implements ActionListener, MouseListener {
private boolean
hoverSelect;
private Image
backgroundImage;
// - -%- -
static final int
@ -503,20 +522,28 @@ implements ActionListener, MouseListener {
}
public void
setNextPageAvailable(boolean available)
{
next.setEnabled(available);
}
setNextPageAvailable(boolean n) { next.setEnabled(n); }
public void
setPreviousPageAvailable(boolean available)
{
prev.setEnabled(available);
}
setPreviousPageAvailable(boolean n) { prev.setEnabled(n); }
public void
setHoverSelect(boolean a) { this.hoverSelect = a; }
setHoverSelect(boolean n) { hoverSelect = n; }
public void
setBackgroundImage(Image n) { backgroundImage = n; }
// - -%- -
protected void
paintComponent(Graphics g)
{
int w = getWidth(), h = getHeight();
g.clearRect(0, 0, w, h);
int h2 = h * 5 / 10, w2 = h2;
int x = w - w2, y = h - h2;
g.drawImage(backgroundImage, x, y, w2, h2, this);
}
public void
mouseEntered(MouseEvent eM)
@ -553,8 +580,6 @@ implements ActionListener, MouseListener {
public void
mouseReleased(MouseEvent eM) { }
// - -%- -
public void
actionPerformed(ActionEvent eA)
{
@ -628,6 +653,9 @@ PostPreviewComponent extends JComponent {
private JLabel
topLeft, topRight, bottom;
private boolean
selected;
// ---%-@-%---
public void
@ -650,6 +678,7 @@ PostPreviewComponent extends JComponent {
public void
setSelected(boolean selected)
{
this.selected = selected;
if (!selected) setBackground(null);
else setBackground(new Color(0, 0, 0, 25));
}
@ -659,15 +688,19 @@ PostPreviewComponent extends JComponent {
protected void
paintComponent(Graphics g)
{
if (selected) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
}
}
// ---%-@-%---
public
PostPreviewComponent()
{
selected = false;
Font f = new JLabel().getFont();
Font f1 = f.deriveFont(Font.PLAIN, 12f);
Font f2 = f.deriveFont(Font.ITALIC, 12f);
@ -675,16 +708,12 @@ PostPreviewComponent extends JComponent {
topLeft = new JLabel();
topLeft.setFont(f1);
setOpaque(false);
topLeft.setOpaque(false);
topRight = new JLabel();
topRight.setHorizontalAlignment(JLabel.RIGHT);
topRight.setFont(f2);
setOpaque(false);
bottom = new JLabel();
bottom.setFont(f3);
bottom.setOpaque(false);
topRight.setOpaque(false);
Box top = Box.createHorizontalBox();
top.setOpaque(false);
@ -692,6 +721,10 @@ PostPreviewComponent extends JComponent {
top.add(Box.createGlue());
top.add(topRight);
bottom = new JLabel();
bottom.setFont(f3);
bottom.setOpaque(false);
setOpaque(false);
setSelected(false);
setLayout(new BorderLayout());

BIN
graphics/Federated.xcf Normal file

Binary file not shown.

BIN
graphics/federated.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB