Mostly finished button selection code, in ComposeWindow.

This commit is contained in:
Snowyfox 2022-05-27 21:41:12 -04:00
parent 2d4747d892
commit 45a41af12c
32 changed files with 191 additions and 201 deletions

View File

@ -477,6 +477,12 @@ implements ActionListener {
private ButtonGroup
selectionsGroup;
private JToggleButton
attachment1,
attachment2,
attachment3,
attachment4;
private JButton
add;
@ -495,28 +501,30 @@ implements ActionListener {
private void
updateButtons()
{
selections.removeAll();
Dimension sz = add.getPreferredSize();
int i = 1;
for (Attachment attachment: working)
{
JToggleButton button = new JToggleButton();
button.setPreferredSize(sz);
button.setMargin(add.getMargin());
button.setText(Integer.toString(i++));
selections.add(button);
}
selections.removeAll();
if (working.size() > 0) selections.add(attachment1);
if (working.size() > 1) selections.add(attachment2);
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) attachment4.doClick();
else if (working.size() > 2) attachment3.doClick();
else if (working.size() > 1) attachment2.doClick();
else if (working.size() > 0) attachment1.doClick();
else selectionsGroup.clearSelection();
int bw = sz.width;
int hgap = 4;
int count = Math.min(1 + working.size(), 4);
int count = selections.getComponents().length;
int w = count * bw + (count - 1) * hgap;
int h = bw;
selections.setPreferredSize(new Dimension(w, h));
selections.setMaximumSize(new Dimension(w, h));
selections.revalidate();
}
public void
@ -540,6 +548,31 @@ implements ActionListener {
if (src == delete)
{
Object sm = selectionsGroup.getSelection();
if (sm == attachment1.getModel())
{
assert working.size() > 0;
working.remove(0);
updateButtons();
}
if (sm == attachment2.getModel())
{
assert working.size() > 1;
working.remove(1);
updateButtons();
}
if (sm == attachment3.getModel())
{
assert working.size() > 2;
working.remove(2);
updateButtons();
}
if (sm == attachment4.getModel())
{
assert working.size() > 3;
working.remove(3);
updateButtons();
}
return;
}
@ -567,12 +600,25 @@ implements ActionListener {
add.setPreferredSize(new Dimension(32, 32));
add.setMargin(new Insets(0, 0, 0, 0));
add.addActionListener(this);
attachment1 = new JToggleButton("1");
attachment2 = new JToggleButton("2");
attachment3 = new JToggleButton("3");
attachment4 = new JToggleButton("4");
attachment1.setMargin(add.getMargin());
attachment2.setMargin(add.getMargin());
attachment3.setMargin(add.getMargin());
attachment4.setMargin(add.getMargin());
selections = new JPanel();
selections.setOpaque(false);
selections.setLayout(new GridLayout(1, 0, 4, 0));
working = new ArrayList<Attachment>();
selectionsGroup = new ButtonGroup();
selectionsGroup.add(attachment1);
selectionsGroup.add(attachment2);
selectionsGroup.add(attachment3);
selectionsGroup.add(attachment4);
// Have to add selection listener to button group
updateButtons();
JButton del = new JButton("D");

View File

@ -289,10 +289,6 @@ Post {
text,
approximateText;
public List<RichTextPane.Segment>
formattedText,
laidoutText;
public String
contentWarning;
@ -315,6 +311,9 @@ Post {
public String[][]
emojiUrls;
public String[]
mentions;
// - -%- -
private static final DateTimeFormatter
@ -360,80 +359,6 @@ Post {
approximateText = b.toString();
}
public void
resolveFormattedText()
{
assert text != null;
assert emojiUrls != null;
if (formattedText != null) return;
RichTextPane.Builder b = new RichTextPane.Builder();
Tree<String> nodes;
nodes = RudimentaryHTMLParser.depthlessRead(text);
for (Tree<String> node: nodes)
{
if (node.key.equals("tag"))
{
String tagName = node.get(0).key;
Tree<String> href = node.get("href");
if (tagName.equals("br"))
b = b.spacer("\n");
if (tagName.equals("/p"))
b = b.spacer("\n").spacer("\n");
if (tagName.equals("a"))
b = b.link(href.value, null).spacer(" ");
}
if (node.key.equals("text"))
{
BreakIterator it;
it = BreakIterator.getWordInstance(Locale.ROOT);
it.setText(node.value);
int start = it.first(), end = it.next();
while (end != BreakIterator.DONE)
{
String word = text.substring(start, end);
char c = word.isEmpty() ? ' ' : word.charAt(0);
boolean w = Character.isWhitespace(c);
b = w ? b.spacer(word) : b.text(word);
start = end;
end = it.next();
}
}
if (node.key.equals("emoji"))
{
String shortcode = node.value;
String url = null;
for (String[] mapping: emojiUrls)
{
String ms = mapping[0];
String mu = mapping[1];
if (ms.equals(shortcode)) url = mu;
}
ImageIcon icon = ImageApi.iconRemote(url);
if (icon != null) b = b.image(icon, node.value);
else b = b.text(":" + node.value + ":");
}
}
formattedText = b.finish();
}
public int
resolveLaidoutText(int width, FontMetrics fm)
{
assert formattedText != null;
laidoutText = RichTextPane.layout(formattedText, fm, width);
int maxY = 0;
for (RichTextPane.Segment segment: laidoutText)
if (segment.y > maxY) maxY = segment.y;
return maxY;
}
public void
resolveRelativeTime()
{
@ -509,6 +434,14 @@ Post {
Tree<String> boostedPost = entity.get("reblog");
if (boostedPost.size() > 0)
this.boostedPost = new Post(boostedPost);
Tree<String> mentions = entity.get("mentions");
this.mentions = new String[mentions.size()];
for (int o = 0; o < mentions.size(); ++o)
{
String acct = mentions.get(o).get("acct").value;
this.mentions[o] = acct;
}
}
}
@ -748,7 +681,7 @@ Composition {
}
public static Composition
reply(Post post, String ownNumId)
reply(Post post, String ownId)
{
if (post.boostedPost != null) post = post.boostedPost;
@ -756,9 +689,20 @@ Composition {
c.replyToPostId = post.id;
c.visibility = post.visibility;
c.contentWarning = post.contentWarning;
c.text = "";
if (!post.author.numId.equals(ownNumId))
c.text = "@" + post.author.id + " ";
StringBuilder text = new StringBuilder();
for (String id: post.mentions)
{
if (id.equals(ownId)) continue;
text.append("@" + id);
}
if (!post.author.id.equals(ownId))
{
text.append("@" + post.author.id);
}
c.text = text.toString();
return c;
}

View File

@ -223,7 +223,7 @@ PostWindow extends JFrame {
public synchronized void
reply()
{
String ownId = api.getAccountDetails().get("id").value;
String ownId = api.getAccountDetails().get("acct").value;
Composition c = Composition.reply(this.post, ownId);
ComposeWindow w = primaire.getComposeWindow();
w.setComposition(c);

0
graphics/Federated.xcf Executable file → Normal file
View File

0
graphics/Flags.xcf Executable file → Normal file
View File

0
graphics/Home.xcf Executable file → Normal file
View File

0
graphics/Hourglass.xcf Executable file → Normal file
View File

0
graphics/Kettle.xcf Executable file → Normal file
View File

0
graphics/boostToggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

0
graphics/boostUntoggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

0
graphics/button.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

0
graphics/disabledOverlay.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

0
graphics/favouriteToggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 353 B

After

Width:  |  Height:  |  Size: 353 B

0
graphics/favouriteUntoggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

0
graphics/federated.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

0
graphics/home.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

0
graphics/kettle.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

0
graphics/miscToggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

0
graphics/miscUntoggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

0
graphics/nextToggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

0
graphics/nextUntoggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

0
graphics/postWindow.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 978 B

After

Width:  |  Height:  |  Size: 978 B

0
graphics/prevToggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

0
graphics/prevUntoggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

0
graphics/ref1.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

0
graphics/replyToggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

0
graphics/replyUntoggled.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

0
graphics/selectedOverlay.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 313 B

After

Width:  |  Height:  |  Size: 313 B

0
graphics/test1.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

0
graphics/test2.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

0
graphics/test3.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

0
graphics/test4.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB