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

View File

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