mirror of
https://gitlab.com/biskuteri-cafe/JKomasto2.git
synced 2024-11-20 06:24:50 +01:00
Hooked up new text pane..
This commit is contained in:
parent
bcf852cdc9
commit
dc980c153c
112
PostWindow.java
112
PostWindow.java
@ -61,12 +61,6 @@ PostWindow extends JFrame {
|
||||
private PostComponent
|
||||
display;
|
||||
|
||||
private static JFrame
|
||||
test;
|
||||
|
||||
private static RichTextPane3
|
||||
test2;
|
||||
|
||||
// - -%- -
|
||||
|
||||
private static final DateTimeFormatter
|
||||
@ -123,24 +117,6 @@ PostWindow extends JFrame {
|
||||
|
||||
display.resetFocus();
|
||||
repaint();
|
||||
|
||||
if (test == null)
|
||||
{
|
||||
test = new JFrame();
|
||||
test.setSize(340, 256);
|
||||
test2 = new RichTextPane3();
|
||||
test2.setFont(new Font("Dialog", Font.PLAIN, 18));
|
||||
test.setContentPane(test2);
|
||||
test.setVisible(true);
|
||||
}
|
||||
test2.setText(BasicHTMLParser.parse(post.text));
|
||||
Map<String, Image> emojis = new HashMap<>();
|
||||
for (String[] entry: post.emojiUrls)
|
||||
{
|
||||
emojis.put(entry[0], ImageApi.remote(entry[1]));
|
||||
}
|
||||
test2.setEmojis(emojis);
|
||||
test2.requestFocusInWindow();
|
||||
}
|
||||
|
||||
public void
|
||||
@ -249,8 +225,11 @@ PostWindow extends JFrame {
|
||||
Composition c = Composition.reply(this.post, ownId);
|
||||
ComposeWindow w = primaire.getComposeWindow();
|
||||
w.setComposition(c);
|
||||
w.setLocation(getX(), getY() + 100);
|
||||
w.setVisible(true);
|
||||
if (!w.isVisible())
|
||||
{
|
||||
w.setLocation(getX(), getY() + 100);
|
||||
w.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void
|
||||
@ -396,10 +375,13 @@ implements ActionListener {
|
||||
// - -%- -
|
||||
|
||||
private List<RichTextPane.Segment>
|
||||
authorNameOr, bodyOr;
|
||||
authorNameOr;
|
||||
|
||||
private RichTextPane
|
||||
authorName, body;
|
||||
authorName;
|
||||
|
||||
private RichTextPane3
|
||||
body;
|
||||
|
||||
private JScrollPane
|
||||
bodyScrollPane;
|
||||
@ -450,57 +432,22 @@ implements ActionListener {
|
||||
setTime(String n) { time.setText(n); }
|
||||
|
||||
public void
|
||||
setEmojiUrls(String[][] n) { emojiUrls = n; }
|
||||
setEmojiUrls(String[][] n)
|
||||
{
|
||||
emojiUrls = n;
|
||||
|
||||
Map<String, Image> emojis = new HashMap<>();
|
||||
for (String[] entry: n)
|
||||
{
|
||||
emojis.put(entry[0], ImageApi.remote(entry[1]));
|
||||
}
|
||||
body.setEmojis(emojis);
|
||||
}
|
||||
|
||||
public void
|
||||
setHtml(String n)
|
||||
{
|
||||
RichTextPane.Builder b = new RichTextPane.Builder();
|
||||
Tree<String> nodes = RudimentaryHTMLParser.depthlessRead(n);
|
||||
for (Tree<String> node: nodes)
|
||||
{
|
||||
if (node.key.equals("tag"))
|
||||
{
|
||||
String tagName = node.get(0).key;
|
||||
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(node.get("href").value, null).spacer(" ");
|
||||
}
|
||||
if (node.key.equals("text"))
|
||||
{
|
||||
BreakIterator it = BreakIterator.getWordInstance(Locale.ROOT);
|
||||
String text = node.value;
|
||||
it.setText(text);
|
||||
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[] entry: emojiUrls)
|
||||
if (entry[0].equals(shortcode)) url = entry[1];
|
||||
try {
|
||||
ImageIcon image = new ImageIcon(new URL(url));
|
||||
b = b.image(image, node.value);
|
||||
}
|
||||
catch (MalformedURLException eMu) {
|
||||
b = b.text(":" + shortcode + ":");
|
||||
}
|
||||
}
|
||||
}
|
||||
bodyOr = b.finish();
|
||||
body.setText(BasicHTMLParser.parse(n));
|
||||
}
|
||||
|
||||
public void
|
||||
@ -615,21 +562,10 @@ implements ActionListener {
|
||||
g.clearRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
int w1 = authorName.getWidth();
|
||||
int w2 = body.getWidth();
|
||||
FontMetrics fm1 = getFontMetrics(authorName.getFont());
|
||||
FontMetrics fm2 = getFontMetrics(body.getFont());
|
||||
List<RichTextPane.Segment> lay1, lay2;
|
||||
List<RichTextPane.Segment> lay1;
|
||||
lay1 = RichTextPane.layout(authorNameOr, fm1, w1);
|
||||
lay2 = RichTextPane.layout(bodyOr, fm2, w2);
|
||||
|
||||
authorName.setText(lay1);
|
||||
body.setText(lay2);
|
||||
|
||||
int maxY = 0; for (RichTextPane.Segment s: lay2)
|
||||
{
|
||||
if (s.y > maxY) maxY = s.y;
|
||||
}
|
||||
body.setPreferredSize(new Dimension(1, maxY + 10));
|
||||
|
||||
((java.awt.Graphics2D)g).setRenderingHint(
|
||||
java.awt.RenderingHints.KEY_ANTIALIASING,
|
||||
@ -720,7 +656,7 @@ implements ActionListener {
|
||||
top.add(Box.createVerticalStrut(2));
|
||||
top.add(top2);
|
||||
|
||||
body = new RichTextPane();
|
||||
body = new RichTextPane3();
|
||||
body.setFont(f3);
|
||||
|
||||
bodyScrollPane = new JScrollPane(
|
||||
|
@ -6,6 +6,7 @@ import java.awt.FontMetrics;
|
||||
import java.awt.Font;
|
||||
import java.awt.Image;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
@ -49,6 +50,7 @@ implements
|
||||
|
||||
if (!isValid()) return;
|
||||
|
||||
assert html.key != null;
|
||||
assert html.key.equals("tag");
|
||||
assert html.get("children") != null;
|
||||
|
||||
@ -76,6 +78,8 @@ implements
|
||||
layout(html, fm, cursor);
|
||||
layout.put(layoutEnd, new Point(cursor));
|
||||
repaint();
|
||||
|
||||
setPreferredSize(new Dimension(1, cursor.y));
|
||||
}
|
||||
|
||||
public void
|
||||
@ -515,7 +519,13 @@ implements
|
||||
layout = new HashMap<>();
|
||||
layoutEnd = new Tree<>("text", "");
|
||||
emojis = new HashMap<>();
|
||||
setText(new Tree<String>());
|
||||
|
||||
Tree<String> blank = new Tree<>();
|
||||
blank.key = "tag";
|
||||
blank.add(new Tree<>("html", null));
|
||||
blank.add(new Tree<>("children", null));
|
||||
setText(blank);
|
||||
|
||||
this.addComponentListener(this);
|
||||
this.addMouseListener(this);
|
||||
this.addMouseMotionListener(this);
|
||||
|
@ -70,6 +70,15 @@ WindowUpdater {
|
||||
userConn.reevaluate();
|
||||
}
|
||||
|
||||
// - -%- -
|
||||
|
||||
public static void
|
||||
printStackTrace(Thread thread)
|
||||
{
|
||||
for (StackTraceElement e: thread.getStackTrace())
|
||||
System.err.println(e);
|
||||
}
|
||||
|
||||
// ---%-@-%---
|
||||
|
||||
private class
|
||||
@ -97,6 +106,7 @@ WindowUpdater {
|
||||
{
|
||||
stopping = false;
|
||||
thread = new Thread(this);
|
||||
thread.setDaemon(true);
|
||||
try
|
||||
{
|
||||
synchronized (thread)
|
||||
@ -118,17 +128,18 @@ WindowUpdater {
|
||||
thread.interrupt();
|
||||
try
|
||||
{
|
||||
thread.join();
|
||||
thread.join(3000);
|
||||
/*
|
||||
* That thread should notice it is
|
||||
* interrupted ppromptly, and close.
|
||||
*/
|
||||
if (thread.isAlive()) printStackTrace(thread);
|
||||
}
|
||||
catch (InterruptedException eIt)
|
||||
{
|
||||
assert false;
|
||||
}
|
||||
thread = null;
|
||||
/*
|
||||
* That thread should notice it is interrupted
|
||||
* promptly, and close.
|
||||
*/
|
||||
}
|
||||
|
||||
public void
|
||||
@ -162,6 +173,10 @@ WindowUpdater {
|
||||
// the connection is closed, or this thread
|
||||
// is interrupted.
|
||||
|
||||
System.err.println(
|
||||
"Stopped monitoring."
|
||||
+ thread + " " + Thread.currentThread()
|
||||
);
|
||||
if (thread == Thread.currentThread()) thread = null;
|
||||
/*
|
||||
* This isn't thread safe. But I'd like the
|
||||
@ -279,8 +294,7 @@ WindowUpdater {
|
||||
void
|
||||
loadNotificationSound()
|
||||
{
|
||||
//URL url = getClass().getResource("KDE_Dialog_Appear.wav");
|
||||
URL url = getClass().getResource("LinkinPark.wav");
|
||||
URL url = getClass().getResource("KDE_Dialog_Appear.wav");
|
||||
try {
|
||||
Clip clip = AudioSystem.getClip();
|
||||
clip.open(AudioSystem.getAudioInputStream(url));
|
||||
|
Loading…
Reference in New Issue
Block a user