mirror of
https://gitlab.com/biskuteri-cafe/JKomasto2.git
synced 2024-11-20 06:34:49 +01:00
Added temporary profile open featurs
Temporarily enabled scrolling for PostWindow
This commit is contained in:
parent
100f11c6e2
commit
a033a23ab9
@ -351,6 +351,29 @@ MastodonApi {
|
||||
catch (IOException eIo) { handler.connectionFailed(eIo); }
|
||||
}
|
||||
|
||||
public void
|
||||
getAccounts(String query, RequestListener handler)
|
||||
{
|
||||
assert query != null;
|
||||
String token = accessToken.get("access_token").value;
|
||||
|
||||
String url = instanceUrl + "/api/v1/accounts/search";
|
||||
url += "?q=" + encode(query);
|
||||
|
||||
try
|
||||
{
|
||||
URL endpoint = new URL(url);
|
||||
HttpURLConnection conn;
|
||||
conn = (HttpURLConnection)endpoint.openConnection();
|
||||
String s1 = "Bearer " + token;
|
||||
conn.setRequestProperty("Authorization", s1);
|
||||
conn.connect();
|
||||
|
||||
doStandardJsonReturn(conn, handler);
|
||||
}
|
||||
catch (IOException eIo) { handler.connectionFailed(eIo); }
|
||||
}
|
||||
|
||||
public void
|
||||
monitorTimeline(
|
||||
TimelineType type, ServerSideEventsListener handler)
|
||||
|
@ -6,6 +6,8 @@ import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JScrollBar;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.BorderFactory;
|
||||
@ -400,7 +402,7 @@ implements ActionListener {
|
||||
b = b.image(image, node.value);
|
||||
}
|
||||
catch (MalformedURLException eMu) {
|
||||
b = b.text(":×:");
|
||||
b = b.text(":" + shortcode + ":");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -504,6 +506,14 @@ implements ActionListener {
|
||||
FontMetrics fm2 = getFontMetrics(body.getFont());
|
||||
authorName.setText(RichTextPane.layout(authorNameOr, fm1, w1));
|
||||
body.setText(RichTextPane.layout(bodyOr, fm2, w2));
|
||||
|
||||
List<RichTextPane.Segment> lay;
|
||||
lay = RichTextPane.layout(bodyOr, fm2, w2);
|
||||
int height = 0; for (RichTextPane.Segment s: lay)
|
||||
{
|
||||
if ((s.y + 10) > height) height = s.y + 10;
|
||||
}
|
||||
body.setPreferredSize(new Dimension(1, height));
|
||||
}
|
||||
|
||||
// ---%-@-%---
|
||||
@ -517,6 +527,7 @@ implements ActionListener {
|
||||
Border b = BorderFactory.createEmptyBorder(10, 10, 10, 10);
|
||||
Font f1 = new Font("IPAGothic", Font.PLAIN, 16);
|
||||
Font f2 = new Font("IPAGothic", Font.PLAIN, 13);
|
||||
Font f3 = getFont().deriveFont(14f);
|
||||
|
||||
profile = new RoundButton();
|
||||
favouriteBoost = new TwoToggleButton("favourite", "boost");
|
||||
@ -568,13 +579,24 @@ implements ActionListener {
|
||||
top.add(top2);
|
||||
|
||||
body = new RichTextPane();
|
||||
body.setFont(getFont().deriveFont(14f));
|
||||
body.setFont(f3);
|
||||
|
||||
JScrollPane scroll = new JScrollPane(
|
||||
body,
|
||||
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER
|
||||
);
|
||||
JScrollBar vsb = scroll.getVerticalScrollBar();
|
||||
vsb.setPreferredSize(new Dimension(0, 0));
|
||||
vsb.setUnitIncrement(16);
|
||||
scroll.setBorder(null);
|
||||
scroll.setFocusable(true);
|
||||
|
||||
JPanel centre = new JPanel();
|
||||
centre.setOpaque(false);
|
||||
centre.setLayout(new BorderLayout(0, 8));
|
||||
centre.add(top, BorderLayout.NORTH);
|
||||
centre.add(body);
|
||||
centre.add(scroll);
|
||||
|
||||
setLayout(new BorderLayout(8, 0));
|
||||
add(left, BorderLayout.WEST);
|
||||
|
@ -5,6 +5,7 @@ import java.awt.Graphics;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Image;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ListIterator;
|
||||
@ -34,9 +35,11 @@ RichTextPane extends JComponent {
|
||||
if (segment.image != null) {
|
||||
int ow = segment.image.getIconWidth();
|
||||
int oh = segment.image.getIconHeight();
|
||||
int h = fm.getHeight();
|
||||
int h = fm.getAscent() + fm.getDescent();
|
||||
int w = h * ow / oh;
|
||||
int x = segment.x, y = segment.y;
|
||||
int x = segment.x;
|
||||
int y = segment.y + fm.getDescent();
|
||||
// Interpret segment.y as specifying text baseline
|
||||
Image img = segment.image.getImage();
|
||||
g.drawImage(img, x, y - h, w, h, this);
|
||||
continue;
|
||||
@ -67,7 +70,8 @@ RichTextPane extends JComponent {
|
||||
if (curr.image != null) {
|
||||
int ow = curr.image.getIconWidth();
|
||||
int oh = curr.image.getIconHeight();
|
||||
dx = dy * ow / oh;
|
||||
int nh = fm.getAscent() + fm.getDescent();
|
||||
dx = nh * ow / oh;
|
||||
}
|
||||
else if (curr.text != null) {
|
||||
dx = fm.stringWidth(curr.text);
|
||||
|
@ -59,6 +59,7 @@ RudimentaryHTMLParser {
|
||||
if (s.equals("&")) text.append('&');
|
||||
if (s.equals(""")) text.append('"');
|
||||
if (s.equals("'")) text.append('\'');
|
||||
if (s.equals("'")) text.append('\'');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BorderFactory;
|
||||
import java.awt.BorderLayout;
|
||||
@ -66,6 +69,8 @@ implements ActionListener {
|
||||
openLocal,
|
||||
openFederated,
|
||||
openNotifications,
|
||||
openOwnProfile,
|
||||
openProfile,
|
||||
createPost,
|
||||
openAutoPostView,
|
||||
quit;
|
||||
@ -249,6 +254,125 @@ implements ActionListener {
|
||||
display.setCursor(null);
|
||||
}
|
||||
|
||||
public void
|
||||
openOwnProfile()
|
||||
{
|
||||
Tree<String> accountDetails = api.getAccountDetails();
|
||||
String id = accountDetails.get("id").value;
|
||||
assert id != null;
|
||||
|
||||
TimelineWindow w = new TimelineWindow(primaire);
|
||||
w.showAuthorPosts(id);
|
||||
w.showLatestPage();
|
||||
w.setLocationRelativeTo(this);
|
||||
w.setVisible(true);
|
||||
}
|
||||
|
||||
public void
|
||||
openProfile()
|
||||
{
|
||||
String query = JOptionPane.showInputDialog(
|
||||
this,
|
||||
"Whose account do you want to see?\n"
|
||||
+ "Type an account name with the instance,\n"
|
||||
+ "or a display name if you can't remember.\n",
|
||||
"Profile search",
|
||||
JOptionPane.PLAIN_MESSAGE
|
||||
);
|
||||
if (query == null) return;
|
||||
|
||||
class Handler implements RequestListener {
|
||||
|
||||
public Tree<String>
|
||||
json;
|
||||
|
||||
// -=%=-
|
||||
|
||||
public void
|
||||
connectionFailed(IOException eIo)
|
||||
{
|
||||
JOptionPane.showMessageDialog(
|
||||
TimelineWindow.this,
|
||||
"Tried to fetch accounts, but it failed.."
|
||||
+ "\n" + eIo.getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
public void
|
||||
requestFailed(int httpCode, Tree<String> json)
|
||||
{
|
||||
JOptionPane.showMessageDialog(
|
||||
TimelineWindow.this,
|
||||
"Tried to fetch accounts, but it failed.."
|
||||
+ "\n" + json.get("error").value
|
||||
+ "\n(HTTP code: " + httpCode + ")"
|
||||
);
|
||||
}
|
||||
|
||||
public void
|
||||
requestSucceeded(Tree<String> json) { this.json = json; }
|
||||
|
||||
}
|
||||
// (知) Have to create a named class because
|
||||
// it has to hold the variable.
|
||||
Handler handler = new Handler();
|
||||
api.getAccounts(query, handler);
|
||||
if (handler.json == null) return;
|
||||
|
||||
if (handler.json.size() == 0) {
|
||||
JOptionPane.showMessageDialog(
|
||||
this,
|
||||
"There were no results from the query.. ☹️"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
String id = null;
|
||||
if (query.startsWith("@")) query = query.substring(1);
|
||||
|
||||
List<Object> message = new ArrayList<>();
|
||||
message.add("Maybe one of these?");
|
||||
ButtonGroup selGroup = new ButtonGroup();
|
||||
for (Tree<String> account: handler.json)
|
||||
{
|
||||
String dname = account.get("display_name").value;
|
||||
String acct = account.get("acct").value;
|
||||
if (query.equals(acct)) {
|
||||
id = account.get("id").value;
|
||||
break;
|
||||
}
|
||||
JRadioButton b = new JRadioButton();
|
||||
b.setText(dname + " (" + acct + ")");
|
||||
selGroup.add(b);
|
||||
message.add(b);
|
||||
}
|
||||
if (id == null)
|
||||
{
|
||||
int response = JOptionPane.showConfirmDialog(
|
||||
this,
|
||||
message.toArray(),
|
||||
"Search results",
|
||||
JOptionPane.OK_CANCEL_OPTION
|
||||
);
|
||||
if (response == JOptionPane.CANCEL_OPTION) return;
|
||||
for (int o = 1; o < message.size(); ++o)
|
||||
{
|
||||
JRadioButton b = (JRadioButton)message.get(o);
|
||||
if (selGroup.isSelected(b.getModel()))
|
||||
{
|
||||
id = handler.json.get(o - 1).get("id").value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TimelineWindow w = new TimelineWindow(primaire);
|
||||
w.showAuthorPosts(id);
|
||||
w.showLatestPage();
|
||||
w.setLocationRelativeTo(this);
|
||||
w.setVisible(true);
|
||||
}
|
||||
|
||||
// - -%- -
|
||||
|
||||
public void
|
||||
@ -285,6 +409,14 @@ implements ActionListener {
|
||||
{
|
||||
setTimelineType(TimelineType.LOCAL);
|
||||
showLatestPage();
|
||||
}
|
||||
if (src == openOwnProfile)
|
||||
{
|
||||
openOwnProfile();
|
||||
}
|
||||
if (src == openProfile)
|
||||
{
|
||||
openProfile();
|
||||
}
|
||||
if (src == createPost)
|
||||
{
|
||||
@ -402,7 +534,8 @@ implements ActionListener {
|
||||
a2.type = a1.get("type").value;
|
||||
String u1 = a1.get("remote_url").value;
|
||||
String u2 = a1.get("text_url").value;
|
||||
a2.url = u1 == null ? u2 : u1;
|
||||
String u3 = a1.get("url").value;
|
||||
a2.url = u1 != null ? u1 : u2 != null ? u2 : u3;
|
||||
a2.description = a1.get("description").value;
|
||||
a2.image = null;
|
||||
if (a2.type.equals("image"))
|
||||
@ -458,12 +591,16 @@ implements ActionListener {
|
||||
openHome = new JMenuItem("Open home timeline");
|
||||
openFederated = new JMenuItem("Open federated timeline");
|
||||
openNotifications = new JMenuItem("Open notifications");
|
||||
openOwnProfile = new JMenuItem("Open own profile");
|
||||
openProfile = new JMenuItem("Open profile..");
|
||||
createPost = new JMenuItem("Create a post");
|
||||
openAutoPostView = new JMenuItem("Open auto post view");
|
||||
quit = new JMenuItem("Quit");
|
||||
openHome.addActionListener(this);
|
||||
openFederated.addActionListener(this);
|
||||
openNotifications.addActionListener(this);
|
||||
openOwnProfile.addActionListener(this);
|
||||
openProfile.addActionListener(this);
|
||||
createPost.addActionListener(this);
|
||||
openAutoPostView.addActionListener(this);
|
||||
quit.addActionListener(this);
|
||||
@ -476,6 +613,8 @@ implements ActionListener {
|
||||
programMenu.add(openHome);
|
||||
programMenu.add(openFederated);
|
||||
programMenu.add(openNotifications);
|
||||
programMenu.add(openOwnProfile);
|
||||
programMenu.add(openProfile);
|
||||
programMenu.add(new JSeparator());
|
||||
programMenu.add(createPost);
|
||||
programMenu.add(openAutoPostView);
|
||||
|
Loading…
Reference in New Issue
Block a user