mirror of
https://gitlab.com/biskuteri-cafe/JKomasto2.git
synced 2024-11-20 06:24:50 +01:00
Added basically correct description editing for attachments.
Added desktop file.
This commit is contained in:
parent
39cb81d758
commit
0fad4bfacd
@ -14,13 +14,16 @@ import javax.swing.JScrollPane;
|
|||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.JToggleButton;
|
import javax.swing.JToggleButton;
|
||||||
import javax.swing.ButtonGroup;
|
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.text.JTextComponent;
|
import javax.swing.text.JTextComponent;
|
||||||
|
import javax.swing.undo.UndoableEdit;
|
||||||
|
import javax.swing.undo.UndoManager;
|
||||||
|
import javax.swing.event.UndoableEditListener;
|
||||||
|
import javax.swing.event.UndoableEditEvent;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
@ -31,6 +34,8 @@ import java.awt.event.KeyListener;
|
|||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.ComponentListener;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
@ -550,7 +555,7 @@ implements ActionListener, CaretListener, KeyListener {
|
|||||||
|
|
||||||
class
|
class
|
||||||
AttachmentsComponent extends JPanel
|
AttachmentsComponent extends JPanel
|
||||||
implements ActionListener {
|
implements ComponentListener, ActionListener {
|
||||||
|
|
||||||
private ComposeWindow
|
private ComposeWindow
|
||||||
primaire;
|
primaire;
|
||||||
@ -567,7 +572,8 @@ implements ActionListener {
|
|||||||
attachment1,
|
attachment1,
|
||||||
attachment2,
|
attachment2,
|
||||||
attachment3,
|
attachment3,
|
||||||
attachment4;
|
attachment4,
|
||||||
|
selected;
|
||||||
|
|
||||||
private JButton
|
private JButton
|
||||||
add;
|
add;
|
||||||
@ -585,6 +591,9 @@ implements ActionListener {
|
|||||||
private JFileChooser
|
private JFileChooser
|
||||||
chooser;
|
chooser;
|
||||||
|
|
||||||
|
private UndoManager
|
||||||
|
descriptionUndos;
|
||||||
|
|
||||||
// ---%-@-%---
|
// ---%-@-%---
|
||||||
|
|
||||||
public void
|
public void
|
||||||
@ -612,37 +621,37 @@ implements ActionListener {
|
|||||||
Dimension sz = add.getPreferredSize();
|
Dimension sz = add.getPreferredSize();
|
||||||
|
|
||||||
selections.removeAll();
|
selections.removeAll();
|
||||||
if (working.size() > 0) selections.add(attachment1);
|
selected = null;
|
||||||
if (working.size() > 1) selections.add(attachment2);
|
if (working.size() > 0)
|
||||||
if (working.size() > 2) selections.add(attachment3);
|
|
||||||
if (working.size() > 3) selections.add(attachment4);
|
|
||||||
if (working.size() < 4) selections.add(add);
|
|
||||||
|
|
||||||
if (working.size() > 3)
|
|
||||||
{
|
|
||||||
Image i = working.get(3).image;
|
|
||||||
attachment4.setIcon(new ImageIcon(i));
|
|
||||||
}
|
|
||||||
else if (working.size() > 2)
|
|
||||||
{
|
|
||||||
Image i = working.get(2).image;
|
|
||||||
attachment3.setIcon(new ImageIcon(i));
|
|
||||||
}
|
|
||||||
else if (working.size() > 1)
|
|
||||||
{
|
|
||||||
Image i = working.get(1).image;
|
|
||||||
attachment2.setIcon(new ImageIcon(i));
|
|
||||||
}
|
|
||||||
else if (working.size() > 0)
|
|
||||||
{
|
{
|
||||||
|
selections.add(attachment1);
|
||||||
Image i = working.get(0).image;
|
Image i = working.get(0).image;
|
||||||
attachment1.setIcon(new ImageIcon(i));
|
attachment1.setIcon(new ImageIcon(i));
|
||||||
}
|
}
|
||||||
|
if (working.size() > 1)
|
||||||
|
{
|
||||||
|
selections.add(attachment2);
|
||||||
|
Image i = working.get(1).image;
|
||||||
|
attachment2.setIcon(new ImageIcon(i));
|
||||||
|
}
|
||||||
|
if (working.size() > 2)
|
||||||
|
{
|
||||||
|
selections.add(attachment3);
|
||||||
|
Image i = working.get(2).image;
|
||||||
|
attachment3.setIcon(new ImageIcon(i));
|
||||||
|
}
|
||||||
|
if (working.size() > 3)
|
||||||
|
{
|
||||||
|
selections.add(attachment4);
|
||||||
|
Image i = working.get(3).image;
|
||||||
|
attachment4.setIcon(new ImageIcon(i));
|
||||||
|
}
|
||||||
|
if (working.size() < 4) selections.add(add);
|
||||||
|
|
||||||
attachment4.setSelected(working.size() > 3);
|
if (working.size() > 3) open(attachment4);
|
||||||
attachment3.setSelected(working.size() > 2);
|
else if (working.size() > 2) open(attachment3);
|
||||||
attachment2.setSelected(working.size() > 1);
|
else if (working.size() > 1) open(attachment2);
|
||||||
attachment1.setSelected(working.size() > 0);
|
else if (working.size() > 0) open(attachment1);
|
||||||
|
|
||||||
int bw = sz.width;
|
int bw = sz.width;
|
||||||
int hgap = 4;
|
int hgap = 4;
|
||||||
@ -651,8 +660,11 @@ implements ActionListener {
|
|||||||
int h = bw;
|
int h = bw;
|
||||||
selections.setPreferredSize(new Dimension(w, h));
|
selections.setPreferredSize(new Dimension(w, h));
|
||||||
selections.setMaximumSize(new Dimension(w, h));
|
selections.setMaximumSize(new Dimension(w, h));
|
||||||
|
|
||||||
selections.revalidate();
|
selections.revalidate();
|
||||||
|
|
||||||
|
delete.setEnabled(selected != null);
|
||||||
|
revert.setEnabled(selected != null);
|
||||||
|
description.setEnabled(selected != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void
|
public void
|
||||||
@ -669,6 +681,8 @@ implements ActionListener {
|
|||||||
|
|
||||||
Attachment a = new Attachment();
|
Attachment a = new Attachment();
|
||||||
a.uploadee = f;
|
a.uploadee = f;
|
||||||
|
a.description = "";
|
||||||
|
a.type = "unknown";
|
||||||
|
|
||||||
String mime = "", primary = "";
|
String mime = "", primary = "";
|
||||||
try
|
try
|
||||||
@ -683,101 +697,100 @@ implements ActionListener {
|
|||||||
{
|
{
|
||||||
String urlr = f.toURI().toString();
|
String urlr = f.toURI().toString();
|
||||||
a.image = ImageApi.remote(urlr);
|
a.image = ImageApi.remote(urlr);
|
||||||
|
a.type = "image";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selected != null) open(selected);
|
||||||
|
// Save first before resetting
|
||||||
|
|
||||||
working.add(a);
|
working.add(a);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src == delete)
|
if (src == delete)
|
||||||
{
|
{
|
||||||
if (attachment1.isSelected())
|
assert selected != null;
|
||||||
{
|
working.remove(getAttachmentFor(selected));
|
||||||
assert working.size() > 0;
|
|
||||||
working.remove(0);
|
|
||||||
}
|
|
||||||
if (attachment2.isSelected())
|
|
||||||
{
|
|
||||||
assert working.size() > 1;
|
|
||||||
working.remove(1);
|
|
||||||
}
|
|
||||||
if (attachment3.isSelected())
|
|
||||||
{
|
|
||||||
assert working.size() > 2;
|
|
||||||
working.remove(2);
|
|
||||||
}
|
|
||||||
if (attachment4.isSelected())
|
|
||||||
{
|
|
||||||
assert working.size() > 3;
|
|
||||||
working.remove(3);
|
|
||||||
}
|
|
||||||
updateButtons();
|
updateButtons();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src != add && selections.isAncestorOf((Component)src))
|
if (src != add && selections.isAncestorOf((Component)src))
|
||||||
{
|
{
|
||||||
int iCurr = getSelectedIndex();
|
assert src instanceof JToggleButton;
|
||||||
int iNext = getIndex(src);
|
if (src == selected) preview(getAttachmentFor(src));
|
||||||
System.err.println(iCurr + ":" + iNext);
|
else open((JToggleButton)src);
|
||||||
assert iNext != 0;
|
|
||||||
if (iCurr == iNext) {
|
|
||||||
save();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (iCurr != 0) save();
|
|
||||||
load(iNext);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src == revert)
|
if (src == revert)
|
||||||
{
|
{
|
||||||
assert getSelectedIndex() != 0;
|
while (descriptionUndos.canUndo())
|
||||||
// Should the controls be disabled until
|
descriptionUndos.undo();
|
||||||
// there is an attachment?
|
return;
|
||||||
load(getSelectedIndex());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int
|
private Attachment
|
||||||
getIndex(Object src)
|
getAttachmentFor(Object button)
|
||||||
{
|
{
|
||||||
if (src == attachment4) return 4;
|
if (button == null) return null;
|
||||||
if (src == attachment3) return 3;
|
assert button instanceof JToggleButton;
|
||||||
if (src == attachment2) return 2;
|
assert selections.isAncestorOf((Component)button);
|
||||||
if (src == attachment1) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int
|
int index = 0;
|
||||||
getSelectedIndex()
|
if (button == attachment4) index = 4;
|
||||||
{
|
if (button == attachment3) index = 3;
|
||||||
if (attachment4.isSelected()) return 4;
|
if (button == attachment2) index = 2;
|
||||||
if (attachment3.isSelected()) return 3;
|
if (button == attachment1) index = 1;
|
||||||
if (attachment2.isSelected()) return 2;
|
|
||||||
if (attachment1.isSelected()) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void
|
|
||||||
save()
|
|
||||||
{
|
|
||||||
int index = getSelectedIndex();
|
|
||||||
assert index != 0;
|
assert index != 0;
|
||||||
|
assert index <= working.size();
|
||||||
Attachment a = working.get(index - 1);
|
return working.get(index - 1);
|
||||||
a.description = this.description.getText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void
|
private void
|
||||||
load(int index)
|
open(JToggleButton button)
|
||||||
{
|
{
|
||||||
assert index > 0;
|
assert selections.isAncestorOf(button);
|
||||||
assert working.size() >= index;
|
|
||||||
|
|
||||||
Attachment a = working.get(index - 1);
|
if (selected != null)
|
||||||
this.description.setText(a.description);
|
{
|
||||||
|
Attachment a = getAttachmentFor(selected);
|
||||||
|
a.description = description.getText();
|
||||||
|
selected.setSelected(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Attachment a = getAttachmentFor(button);
|
||||||
|
description.setText(a.description);
|
||||||
|
descriptionUndos.discardAllEdits();
|
||||||
|
(selected = button).setSelected(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void
|
||||||
|
componentHidden(ComponentEvent eC)
|
||||||
|
{
|
||||||
|
if (selected != null) open(selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void
|
||||||
|
preview(Attachment a)
|
||||||
|
{
|
||||||
|
ImageWindow w = new ImageWindow();
|
||||||
|
w.showAttachments(new Attachment[] { a } );
|
||||||
|
w.setTitle("Attachment preview");
|
||||||
|
w.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void
|
||||||
|
componentShown(ComponentEvent eC) { }
|
||||||
|
|
||||||
|
public void
|
||||||
|
componentMoved(ComponentEvent eC) { }
|
||||||
|
|
||||||
|
public void
|
||||||
|
componentResized(ComponentEvent eC) { }
|
||||||
|
|
||||||
// ---%-@-%---
|
// ---%-@-%---
|
||||||
|
|
||||||
AttachmentsComponent(ComposeWindow primaire)
|
AttachmentsComponent(ComposeWindow primaire)
|
||||||
@ -818,41 +831,18 @@ implements ActionListener {
|
|||||||
selections.setOpaque(false);
|
selections.setOpaque(false);
|
||||||
selections.setLayout(new GridLayout(1, 0, 4, 0));
|
selections.setLayout(new GridLayout(1, 0, 4, 0));
|
||||||
working = new ArrayList<Attachment>();
|
working = new ArrayList<Attachment>();
|
||||||
ButtonGroup selectionsGroup = new ButtonGroup();
|
|
||||||
selectionsGroup.add(attachment1);
|
|
||||||
selectionsGroup.add(attachment2);
|
|
||||||
selectionsGroup.add(attachment3);
|
|
||||||
selectionsGroup.add(attachment4);
|
|
||||||
updateButtons();
|
|
||||||
|
|
||||||
JButton del = new JButton("D");
|
|
||||||
JButton rev = new JButton("R");
|
|
||||||
JButton ml = new JButton("←");
|
|
||||||
JButton mr = new JButton("→");
|
|
||||||
del.setMargin(new Insets(0, 0, 0, 0));
|
|
||||||
//ml.setMargin(new Insets(0, 0, 0, 0));
|
|
||||||
//mr.setMargin(new Insets(0, 0, 0, 0));
|
|
||||||
rev.setMargin(new Insets(0, 0, 0, 0));
|
|
||||||
|
|
||||||
JPanel actions = new JPanel();
|
|
||||||
actions.setOpaque(false);
|
|
||||||
actions.setLayout(new GridLayout(1, 4, 4, 4));
|
|
||||||
actions.add(del);
|
|
||||||
actions.add(rev);
|
|
||||||
actions.add(ml);
|
|
||||||
actions.add(mr);
|
|
||||||
actions.setPreferredSize(new Dimension(108, 24));
|
|
||||||
actions.setMaximumSize(new Dimension(108, 24));
|
|
||||||
|
|
||||||
delete = new JButton("Delete");
|
|
||||||
revert = new JButton("Revert");
|
|
||||||
delete.addActionListener(this);
|
|
||||||
revert.addActionListener(this);
|
|
||||||
|
|
||||||
Box top = Box.createHorizontalBox();
|
Box top = Box.createHorizontalBox();
|
||||||
top.add(selections);
|
top.add(selections);
|
||||||
top.add(Box.createGlue());
|
top.add(Box.createGlue());
|
||||||
|
|
||||||
|
delete = new JButton("Delete");
|
||||||
|
revert = new JButton("Revert");
|
||||||
|
JButton ml = new JButton("←");
|
||||||
|
JButton mr = new JButton("→");
|
||||||
|
delete.addActionListener(this);
|
||||||
|
revert.addActionListener(this);
|
||||||
|
|
||||||
Box bottom = Box.createHorizontalBox();
|
Box bottom = Box.createHorizontalBox();
|
||||||
bottom.add(ml);
|
bottom.add(ml);
|
||||||
bottom.add(mr);
|
bottom.add(mr);
|
||||||
@ -870,6 +860,11 @@ implements ActionListener {
|
|||||||
description.addMouseListener(textActionPopup);
|
description.addMouseListener(textActionPopup);
|
||||||
descriptionLabel = new JLabel("Description");
|
descriptionLabel = new JLabel("Description");
|
||||||
descriptionLabel.setLabelFor(description);
|
descriptionLabel.setLabelFor(description);
|
||||||
|
descriptionUndos = new UndoManager();
|
||||||
|
description.getDocument().
|
||||||
|
addUndoableEditListener(descriptionUndos);
|
||||||
|
|
||||||
|
updateButtons();
|
||||||
|
|
||||||
JPanel row1 = new JPanel();
|
JPanel row1 = new JPanel();
|
||||||
row1.setOpaque(false);
|
row1.setOpaque(false);
|
||||||
@ -877,14 +872,6 @@ implements ActionListener {
|
|||||||
row1.add(descriptionLabel, BorderLayout.NORTH);
|
row1.add(descriptionLabel, BorderLayout.NORTH);
|
||||||
row1.add(description, BorderLayout.CENTER);
|
row1.add(description, BorderLayout.CENTER);
|
||||||
|
|
||||||
/*
|
|
||||||
Box row2 = Box.createHorizontalBox();
|
|
||||||
row2.add(Box.createGlue());
|
|
||||||
row2.add(delete);
|
|
||||||
row2.add(Box.createHorizontalStrut(8));
|
|
||||||
row2.add(revert);
|
|
||||||
*/
|
|
||||||
|
|
||||||
Box centre = Box.createVerticalBox();
|
Box centre = Box.createVerticalBox();
|
||||||
centre.setBorder(b4);
|
centre.setBorder(b4);
|
||||||
centre.add(row1);
|
centre.add(row1);
|
||||||
@ -895,6 +882,7 @@ implements ActionListener {
|
|||||||
add(bottom, BorderLayout.SOUTH);
|
add(bottom, BorderLayout.SOUTH);
|
||||||
|
|
||||||
setBorder(b1);
|
setBorder(b1);
|
||||||
|
this.addComponentListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
13
JKomasto.desktop
Normal file
13
JKomasto.desktop
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Version=1.5
|
||||||
|
|
||||||
|
Type=Application
|
||||||
|
Name=JKomasto
|
||||||
|
GenericName=Mastodon client
|
||||||
|
GenericName[ja]=Mastodon クライアント
|
||||||
|
Categories=Network
|
||||||
|
|
||||||
|
Path=/home/snowyfox/Documents/Programming/JKomasto2/
|
||||||
|
Icon=/home/snowyfox/Documents/Programming/JKomasto2/graphics/kettle.png
|
||||||
|
Exec=java -cp ".:../Hinoki:/usr/share/java/javax.json.jar" -ea JKomasto
|
||||||
|
Terminal=false
|
Loading…
Reference in New Issue
Block a user