mirror of
https://gitlab.com/biskuteri-cafe/JKomasto2.git
synced 2024-11-20 04:54:50 +01:00
Fixed ComposeWindow connections a bit..!
This commit is contained in:
parent
97f4463b43
commit
a93dc7b488
@ -21,18 +21,6 @@ ComposeWindow extends JFrame {
|
||||
private ComposeComponent
|
||||
display;
|
||||
|
||||
// - -%- -
|
||||
|
||||
private static final Composition
|
||||
NULL_COMPOSITION = new Composition();
|
||||
|
||||
{
|
||||
NULL_COMPOSITION.text = "This is a sample composition..!";
|
||||
NULL_COMPOSITION.visibility = PostVisibility.PUBLIC;
|
||||
NULL_COMPOSITION.replyToPostId = null;
|
||||
// Static final does not like structs very much..
|
||||
}
|
||||
|
||||
// ---%-@-%---
|
||||
|
||||
public void
|
||||
@ -42,6 +30,7 @@ ComposeWindow extends JFrame {
|
||||
composition.text = "";
|
||||
composition.visibility = PostVisibility.PUBLIC;
|
||||
composition.replyToPostId = null;
|
||||
syncDisplayToComposition();
|
||||
}
|
||||
|
||||
public void
|
||||
@ -51,52 +40,101 @@ ComposeWindow extends JFrame {
|
||||
composition.text = "";
|
||||
composition.visibility = PostVisibility.PUBLIC;
|
||||
composition.replyToPostId = postId;
|
||||
syncDisplayToComposition();
|
||||
}
|
||||
|
||||
/*
|
||||
* Are we supposed to be reusable? Or should we be more like
|
||||
* a dialog box, constructed as a new post or reply, and
|
||||
* locked once submitted.
|
||||
*
|
||||
* We seem to accept new compositions after we're constructed,
|
||||
* but does this make sense for our usage scenarios..?
|
||||
*
|
||||
* For example, if not, then we don't need to sync the
|
||||
* display to a composition first, or even maintain a
|
||||
* composition, instead setting anew in #submit.
|
||||
*/
|
||||
|
||||
public void
|
||||
submit()
|
||||
{
|
||||
assert composition != null;
|
||||
syncCompositionToDisplay();
|
||||
|
||||
display.setSubmitting(true);
|
||||
|
||||
// Perform fancy submission here..
|
||||
|
||||
display.setSubmitting(false);
|
||||
// (悪) Are we going to block the EDT..?
|
||||
|
||||
startNewPost();
|
||||
}
|
||||
|
||||
// - -%- -
|
||||
|
||||
private void
|
||||
syncDisplayToComposition()
|
||||
{
|
||||
display.setText(composition.text);
|
||||
display.setVisibility(stringFor(composition.visibility));
|
||||
}
|
||||
|
||||
private void
|
||||
syncCompositionToDisplay()
|
||||
{
|
||||
composition.text = display.getText();
|
||||
|
||||
String visibility = display.getSelectedVisibility();
|
||||
if (visibility.equals("Public"))
|
||||
composition.visibility = PostVisibility.PUBLIC;
|
||||
else if (visibility.equals("Local"))
|
||||
composition.visibility = PostVisibility.LOCAL;
|
||||
else if (visibility.equals("Followers"))
|
||||
composition.visibility = PostVisibility.FOLLOWERS;
|
||||
else if (visibility.equals("Mentioned"))
|
||||
composition.visibility = PostVisibility.MENTIONED;
|
||||
else
|
||||
assert false;
|
||||
|
||||
display.match(composition); // (For good measure)
|
||||
|
||||
display.setEnabled(false);
|
||||
// Perform fancy submission
|
||||
display.setEnabled(true);
|
||||
// (悪) Are we going to block the EDT?
|
||||
composition.visibility =
|
||||
visibilityFrom(display.getVisibility());
|
||||
}
|
||||
|
||||
// ---%-@-%---
|
||||
|
||||
ComposeWindow()
|
||||
{
|
||||
//startNewPost();
|
||||
composition = NULL_COMPOSITION;
|
||||
|
||||
getContentPane().setPreferredSize(new Dimension(360, 270));
|
||||
pack();
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
|
||||
display = new ComposeComponent(this);
|
||||
display.match(composition);
|
||||
|
||||
startNewPost();
|
||||
setContentPane(display);
|
||||
}
|
||||
|
||||
// - -%- -
|
||||
|
||||
private static final String
|
||||
stringFor(PostVisibility visibility)
|
||||
{
|
||||
switch (visibility)
|
||||
{
|
||||
case PUBLIC: return "Public";
|
||||
case LOCAL: return "Local";
|
||||
case FOLLOWERS: return "Followers";
|
||||
case MENTIONED: return "Mentioned";
|
||||
}
|
||||
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final PostVisibility
|
||||
visibilityFrom(String string)
|
||||
{
|
||||
if (string.equals("Public"))
|
||||
return PostVisibility.PUBLIC;
|
||||
if (string.equals("Local"))
|
||||
return PostVisibility.LOCAL;
|
||||
if (string.equals("Followers"))
|
||||
return PostVisibility.FOLLOWERS;
|
||||
if (string.equals("Mentioned"))
|
||||
return PostVisibility.MENTIONED;
|
||||
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -119,57 +157,65 @@ implements ActionListener {
|
||||
private JButton
|
||||
submit;
|
||||
|
||||
// - -%- -
|
||||
|
||||
private static final Cursor
|
||||
WAIT_CURSOR = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
|
||||
|
||||
// ---%-@-%---
|
||||
|
||||
public void
|
||||
match(Composition composition)
|
||||
setText(String text)
|
||||
{
|
||||
text.setText(composition.text);
|
||||
this.text.setText(text);
|
||||
}
|
||||
|
||||
switch (composition.visibility)
|
||||
{
|
||||
case PUBLIC:
|
||||
visibility.setSelectedIndex(0);
|
||||
break;
|
||||
case LOCAL:
|
||||
visibility.setSelectedIndex(1);
|
||||
break;
|
||||
case FOLLOWERS:
|
||||
visibility.setSelectedIndex(2);
|
||||
break;
|
||||
case MENTIONED:
|
||||
visibility.setSelectedIndex(3);
|
||||
break;
|
||||
}
|
||||
|
||||
// And we haven't implemented the reply indicator yet.
|
||||
public void
|
||||
setVisibility(String visibility)
|
||||
{
|
||||
if (visibility.equals("Public"))
|
||||
this.visibility.setSelectedIndex(0);
|
||||
else if (visibility.equals("Local"))
|
||||
this.visibility.setSelectedIndex(1);
|
||||
else if (visibility.equals("Followers"))
|
||||
this.visibility.setSelectedIndex(2);
|
||||
else if (visibility.equals("Mentioned"))
|
||||
this.visibility.setSelectedIndex(3);
|
||||
}
|
||||
|
||||
public String
|
||||
getText() { return text.getText(); }
|
||||
getText()
|
||||
{
|
||||
return text.getText();
|
||||
}
|
||||
|
||||
public String
|
||||
getSelectedVisibility()
|
||||
getVisibility()
|
||||
{
|
||||
return (String)visibility.getSelectedItem();
|
||||
}
|
||||
|
||||
public void
|
||||
setEnabled(boolean enabled)
|
||||
setSubmitting(boolean submitting)
|
||||
{
|
||||
text.setEnabled(enabled);
|
||||
visibility.setEnabled(enabled);
|
||||
submit.setEnabled(enabled);
|
||||
|
||||
// If we're disabled, presumably it's because we are
|
||||
// waiting for an existing submission to complete.
|
||||
setCursor(
|
||||
!enabled
|
||||
? Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)
|
||||
: null
|
||||
);
|
||||
if (submitting)
|
||||
{
|
||||
text.setEnabled(false);
|
||||
visibility.setEnabled(false);
|
||||
submit.setEnabled(false);
|
||||
setCursor(WAIT_CURSOR);
|
||||
}
|
||||
else
|
||||
{
|
||||
text.setEnabled(true);
|
||||
visibility.setEnabled(true);
|
||||
submit.setEnabled(true);
|
||||
setCursor(null);
|
||||
}
|
||||
}
|
||||
|
||||
// - -%- -
|
||||
|
||||
public void
|
||||
actionPerformed(ActionEvent eA) { primaire.submit(); }
|
||||
|
||||
@ -186,8 +232,7 @@ implements ActionListener {
|
||||
"Local",
|
||||
"Followers",
|
||||
"Mentioned"
|
||||
// This might be hard to localise.. And, should we
|
||||
// save the strings in the enum instead?
|
||||
// Where should we be saving strings..
|
||||
});
|
||||
visibility.setPreferredSize(new Dimension(64, 24));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user