Added UI prototype for attachments uploading.

Fixed text selection bug.
This commit is contained in:
Snowyfox 2022-05-21 21:41:46 -04:00
parent fc2880325e
commit 174df078a5
23 changed files with 201 additions and 23 deletions

0
BasicHTMLParser.java Executable file → Normal file
View File

0
ClipboardApi.java Executable file → Normal file
View File

213
ComposeWindow.java Executable file → Normal file
View File

@ -19,6 +19,8 @@ import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.Cursor;
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.event.CaretListener;
import javax.swing.event.CaretEvent;
@ -40,7 +42,10 @@ ComposeWindow extends JFrame {
composition;
private ComposeComponent
display;
contentsDisplay;
private AttachmentsComponent
attachmentsDisplay;
// ---%-@-%---
@ -73,7 +78,7 @@ ComposeWindow extends JFrame {
if (composition.contentWarning != null)
assert !composition.contentWarning.trim().isEmpty();
display.setSubmitting(true);
contentsDisplay.setSubmitting(true);
api.submit(
composition.text, composition.visibility,
composition.replyToPostId, composition.contentWarning,
@ -108,7 +113,21 @@ ComposeWindow extends JFrame {
}
);
display.setSubmitting(false);
contentsDisplay.setSubmitting(false);
}
public void
showContentsPage()
{
setContentPane(contentsDisplay);
revalidate();
}
public void
showAttachmentsPage()
{
setContentPane(attachmentsDisplay);
revalidate();
}
// - -%- -
@ -116,22 +135,22 @@ ComposeWindow extends JFrame {
private synchronized void
syncDisplayToComposition()
{
display.setText(composition.text);
display.setReplyToPostId(composition.replyToPostId);
display.setVisibility(stringFor(composition.visibility));
display.setContentWarning(composition.contentWarning);
ComposeComponent d = contentsDisplay;
d.setText(composition.text);
d.setReplyToPostId(composition.replyToPostId);
d.setVisibility(stringFor(composition.visibility));
d.setContentWarning(composition.contentWarning);
}
private synchronized void
syncCompositionToDisplay()
{
composition.text = display.getText();
composition.visibility =
visibilityFrom(display.getVisibility());
composition.replyToPostId =
nonEmpty(display.getReplyToPostId());
composition.contentWarning =
nonEmpty(display.getContentWarning());
ComposeComponent d = contentsDisplay;
Composition c = composition;
c.text = d.getText();
c.visibility = visibilityFrom(d.getVisibility());
c.replyToPostId = nonEmpty(d.getReplyToPostId());
c.contentWarning = nonEmpty(d.getContentWarning());
}
// - -%- -
@ -151,14 +170,17 @@ ComposeWindow extends JFrame {
this.primaire = primaire;
this.api = primaire.getMastodonApi();
getContentPane().setPreferredSize(new Dimension(360, 270));
final Dimension SZ = new Dimension(360, 270);
getContentPane().setPreferredSize(SZ);
pack();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
display = new ComposeComponent(this);
contentsDisplay = new ComposeComponent(this);
attachmentsDisplay = new AttachmentsComponent(this);
newComposition();
setContentPane(display);
showContentsPage();
setIconImage(primaire.getProgramIcon());
}
@ -221,6 +243,9 @@ implements ActionListener, CaretListener, KeyListener {
private JButton
submit;
private JButton
showAttachmentsPage;
// ---%-@-%---
public void
@ -300,7 +325,14 @@ implements ActionListener, CaretListener, KeyListener {
// - -%- -
public void
actionPerformed(ActionEvent eA) { primaire.submit(); }
actionPerformed(ActionEvent eA)
{
if (eA.getSource() == showAttachmentsPage)
primaire.showAttachmentsPage();
if (eA.getSource() == submit)
primaire.submit();
}
public void
caretUpdate(CaretEvent eCa) { updateTextLength(); }
@ -375,12 +407,16 @@ implements ActionListener, CaretListener, KeyListener {
"Mentioned"
// Where should we be saving strings..
});
visibility.setPreferredSize(new Dimension(64, 24));
visibility.setPreferredSize(new Dimension(48, 24));
submit = new JButton("Submit");
submit.addActionListener(this);
showAttachmentsPage = new JButton("Media");
showAttachmentsPage.addActionListener(this);
Box bottom = Box.createHorizontalBox();
bottom.add(showAttachmentsPage);
bottom.add(Box.createGlue());
bottom.add(textLength);
bottom.add(Box.createHorizontalStrut(12));
@ -405,3 +441,142 @@ implements ActionListener, CaretListener, KeyListener {
}
}
class
AttachmentsComponent extends JPanel
implements ActionListener {
private ComposeWindow
primaire;
// - -%- -
private Attachment[]
working;
private JButton
attachment1,
attachment2,
attachment3,
attachment4;
private JButton
delete,
revert;
private JButton
close;
private JLabel
descriptionLabel;
private JTextArea
description;
// ---%-@-%---
public void
actionPerformed(ActionEvent eA)
{
Object src = eA.getSource();
if (src == close)
{
primaire.showContentsPage();
return;
}
if (src == revert)
{
return;
}
if (src == delete)
{
return;
}
}
// ---%-@-%---
AttachmentsComponent(ComposeWindow primaire)
{
this.primaire = primaire;
Border b1 = BorderFactory.createEmptyBorder(8, 8, 8, 8);
Border b2 = BorderFactory.createEmptyBorder(4, 4, 4, 4);
Border b3 = BorderFactory.createLineBorder(Color.GRAY);
Border bc = BorderFactory.createCompoundBorder(b3, b2);
attachment1 = new JButton("+");
attachment2 = new JButton("+");
attachment3 = new JButton("+");
attachment4 = new JButton("+");
attachment1.setMargin(new Insets(0, 0, 0, 0));
attachment2.setMargin(new Insets(0, 0, 0, 0));
attachment3.setMargin(new Insets(0, 0, 0, 0));
attachment4.setMargin(new Insets(0, 0, 0, 0));
attachment1.addActionListener(this);
attachment2.addActionListener(this);
attachment3.addActionListener(this);
attachment4.addActionListener(this);
JPanel left = new JPanel();
left.setOpaque(false);
left.setLayout(null);
// BoxLayout wasn't listening to my
// preferred nor minimum sizes.
attachment1.setSize(40, 40);
attachment2.setSize(40, 40);
attachment3.setSize(40, 40);
attachment4.setSize(40, 40);
attachment1.setLocation(0, 0);
attachment2.setLocation(0, 44);
attachment3.setLocation(0, 88);
attachment4.setLocation(0, 132);
left.add(attachment1);
left.add(attachment2);
left.add(attachment3);
left.add(attachment4);
left.setPreferredSize(new Dimension(40, 172));
delete = new JButton("Delete");
revert = new JButton("Revert");
close = new JButton("Save & close");
delete.addActionListener(this);
revert.addActionListener(this);
close.addActionListener(this);
Box bottom = Box.createHorizontalBox();
bottom.add(delete);
bottom.add(Box.createHorizontalStrut(16));
bottom.add(revert);
bottom.add(Box.createGlue());
bottom.add(close);
description = new JTextArea();
description.setLineWrap(true);
description.setWrapStyleWord(true);
java.awt.Font f = description.getFont();
description.setFont(f.deriveFont(16f));
description.setBorder(bc);
descriptionLabel = new JLabel("Description");
descriptionLabel.setLabelFor(description);
JPanel row1 = new JPanel();
row1.setOpaque(false);
row1.setLayout(new BorderLayout());
row1.add(descriptionLabel, BorderLayout.NORTH);
row1.add(description, BorderLayout.CENTER);
Box right = Box.createVerticalBox();
right.add(row1);
setLayout(new BorderLayout(12, 10));
add(right, BorderLayout.CENTER);
add(left, BorderLayout.WEST);
add(bottom, BorderLayout.SOUTH);
setBorder(b1);
}
}

0
ImageApi.java Executable file → Normal file
View File

0
ImageWindow.java Executable file → Normal file
View File

3
JKomasto.java Executable file → Normal file
View File

@ -614,6 +614,9 @@ Composition {
public String
replyToPostId;
public Attachment[]
attachments;
// ---%-@-%---
public

0
KDE_Dialog_Appear.wav Executable file → Normal file
View File

0
LoginWindow.java Executable file → Normal file
View File

0
MastodonApi.java Executable file → Normal file
View File

0
NotificationsWindow.java Executable file → Normal file
View File

0
PostWindow.java Executable file → Normal file
View File

0
ProfileWindow.java Executable file → Normal file
View File

0
RepliesWindow.java Executable file → Normal file
View File

0
RequestListener.java Executable file → Normal file
View File

0
RichTextPane.java Executable file → Normal file
View File

0
RichTextPane2.java Executable file → Normal file
View File

8
RichTextPane3.java Executable file → Normal file
View File

@ -182,7 +182,7 @@ implements
layout.put(temp, cursor.clone());
rem.delete(0, l);
boolean more = rem.length() != 0;
boolean more = rem.length() != 0;
if (more) ++cursor.line;
cursor.x = more ? 0 : w;
aw = mw;
@ -247,7 +247,7 @@ implements
aug.value = child.value;
for (Tree<String> gc: child) aug.add(gc);
// Append all of our attributes. We'd like
// Append all of our attributes. We'd like
// those like href to end up at the text
// nodes. This might collide with our
// child node's attributes, for now I'll
@ -471,7 +471,7 @@ implements
Position ssp = layout.get(selStart);
Position sep = layout.get(selEnd);
assert ssp != null && sep != null;
if (ssp.compareTo(sep) > 1)
if (ssp.compareTo(sep) > 0)
{
Position temp = ssp;
ssp = sep;
@ -613,7 +613,7 @@ implements
compareTo(Position other)
{
if (line < other.line) return -1;
if (line > other.line) return -1;
if (line > other.line) return 1;
if (x < other.x) return -1;
if (x > other.x) return 1;
return 0;

0
RudimentaryHTMLParser.java Executable file → Normal file
View File

0
TimelineWindow.java Executable file → Normal file
View File

0
TwoToggleButton.java Executable file → Normal file
View File

0
WindowUpdater.java Executable file → Normal file
View File

0
notifOptions.txt Executable file → Normal file
View File

0
notifOptions.txt~ Executable file → Normal file
View File