SlideShare a Scribd company logo
Creating a Facebook Clone - Part XLII
}
return stats;
}
private static Container createPostBar() {
Button avatar = new Button(ServerAPI.me().getAvatar(6.5f),"Label");
Button writePost = new Button("What's on your mind?",
"NewPostButton");
Button gallery = new Button("Photo", "GalleryButton");
FontImage.setMaterialIcon(gallery,
FontImage.MATERIAL_PHOTO_LIBRARY, 2.9f);
gallery.setTextPosition(BOTTOM);
Container c = BorderLayout.centerEastWest(writePost,gallery,avatar);
c.setUIID("HalfPaddedContainer");
writePost.addActionListener(e -> NewPostForm.createPost().show());
gallery.addActionListener(e -> {
ImagePicker p = new ImagePicker(GALLERY_ALL);
p.pick(
image -> {
NewPostForm.createImagePost(image, p).show();
},
video -> {
NewPostForm.createVideoPost(video, p).show();
});
NewsfeedContainer
}
return stats;
}
private static Container createPostBar() {
Button avatar = new Button(ServerAPI.me().getAvatar(6.5f),"Label");
Button writePost = new Button("What's on your mind?",
"NewPostButton");
Button gallery = new Button("Photo", "GalleryButton");
FontImage.setMaterialIcon(gallery,
FontImage.MATERIAL_PHOTO_LIBRARY, 2.9f);
gallery.setTextPosition(BOTTOM);
Container c = BorderLayout.centerEastWest(writePost,gallery,avatar);
c.setUIID("HalfPaddedContainer");
writePost.addActionListener(e -> NewPostForm.createPost().show());
gallery.addActionListener(e -> {
ImagePicker p = new ImagePicker(GALLERY_ALL);
p.pick(
image -> {
NewPostForm.createImagePost(image, p).show();
},
video -> {
NewPostForm.createVideoPost(video, p).show();
});
NewsfeedContainer
private static Container createPostBar() {
Button avatar = new Button(ServerAPI.me().getAvatar(6.5f),"Label");
Button writePost = new Button("What's on your mind?",
"NewPostButton");
Button gallery = new Button("Photo", "GalleryButton");
FontImage.setMaterialIcon(gallery,
FontImage.MATERIAL_PHOTO_LIBRARY, 2.9f);
gallery.setTextPosition(BOTTOM);
Container c = BorderLayout.centerEastWest(writePost,gallery,avatar);
c.setUIID("HalfPaddedContainer");
writePost.addActionListener(e -> NewPostForm.createPost().show());
gallery.addActionListener(e -> {
ImagePicker p = new ImagePicker(GALLERY_ALL);
p.pick(
image -> {
NewPostForm.createImagePost(image, p).show();
},
video -> {
NewPostForm.createVideoPost(video, p).show();
});
});
return c;
}
}
NewsfeedContainer
return BoxLayout.encloseY(
titleArea, body, createPostStats(p), buttonBar);
}
private static Image placeholder;
private static Component createMediaComponent(String mime, String id) {
if(mime.startsWith("image")) {
if(placeholder == null) {
placeholder = Image.createImage(getDisplayWidth(),
getDisplayHeight() / 2, 0);
}
ScaleImageButton sb = new ScaleImageButton(
URLImage.createCachedImage(id, ServerAPI.mediaUrl(id),
placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL));
return sb;
} else {
try {
Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id),
true);
MediaPlayer mp = new MediaPlayer(media) {
@Override
protected Dimension calcPreferredSize() {
return new Dimension(getDisplayWidth(),
getDisplayHeight() / 2);
NewsfeedContainer
return BoxLayout.encloseY(
titleArea, body, createPostStats(p), buttonBar);
}
private static Image placeholder;
private static Component createMediaComponent(String mime, String id) {
if(mime.startsWith("image")) {
if(placeholder == null) {
placeholder = Image.createImage(getDisplayWidth(),
getDisplayHeight() / 2, 0);
}
ScaleImageButton sb = new ScaleImageButton(
URLImage.createCachedImage(id, ServerAPI.mediaUrl(id),
placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL));
return sb;
} else {
try {
Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id),
true);
MediaPlayer mp = new MediaPlayer(media) {
@Override
protected Dimension calcPreferredSize() {
return new Dimension(getDisplayWidth(),
getDisplayHeight() / 2);
NewsfeedContainer
return BoxLayout.encloseY(
titleArea, body, createPostStats(p), buttonBar);
}
private static Image placeholder;
private static Component createMediaComponent(String mime, String id) {
if(mime.startsWith("image")) {
if(placeholder == null) {
placeholder = Image.createImage(getDisplayWidth(),
getDisplayHeight() / 2, 0);
}
ScaleImageButton sb = new ScaleImageButton(
URLImage.createCachedImage(id, ServerAPI.mediaUrl(id),
placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL));
return sb;
} else {
try {
Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id),
true);
MediaPlayer mp = new MediaPlayer(media) {
@Override
protected Dimension calcPreferredSize() {
return new Dimension(getDisplayWidth(),
getDisplayHeight() / 2);
NewsfeedContainer
return BoxLayout.encloseY(
titleArea, body, createPostStats(p), buttonBar);
}
private static Image placeholder;
private static Component createMediaComponent(String mime, String id) {
if(mime.startsWith("image")) {
if(placeholder == null) {
placeholder = Image.createImage(getDisplayWidth(),
getDisplayHeight() / 2, 0);
}
ScaleImageButton sb = new ScaleImageButton(
URLImage.createCachedImage(id, ServerAPI.mediaUrl(id),
placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL));
return sb;
} else {
try {
Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id),
true);
MediaPlayer mp = new MediaPlayer(media) {
@Override
protected Dimension calcPreferredSize() {
return new Dimension(getDisplayWidth(),
getDisplayHeight() / 2);
NewsfeedContainer
}
ScaleImageButton sb = new ScaleImageButton(
URLImage.createCachedImage(id, ServerAPI.mediaUrl(id),
placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL));
return sb;
} else {
try {
Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id),
true);
MediaPlayer mp = new MediaPlayer(media) {
@Override
protected Dimension calcPreferredSize() {
return new Dimension(getDisplayWidth(),
getDisplayHeight() / 2);
}
};
mp.setLoop(true);
return mp;
} catch(IOException err) {
Log.e(err);
return new Label("Error loading media");
}
}
}
NewsfeedContainer
}
ScaleImageButton sb = new ScaleImageButton(
URLImage.createCachedImage(id, ServerAPI.mediaUrl(id),
placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL));
return sb;
} else {
try {
Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id),
true);
MediaPlayer mp = new MediaPlayer(media) {
@Override
protected Dimension calcPreferredSize() {
return new Dimension(getDisplayWidth(),
getDisplayHeight() / 2);
}
};
mp.setLoop(true);
return mp;
} catch(IOException err) {
Log.e(err);
return new Label("Error loading media");
}
}
}
NewsfeedContainer
titleArea.setUIID("HalfPaddedContainer");
return titleArea;
}
public static Container createNewsItem(User u, Post p) {
Container titleArea = createNewsTitle(u, p);
Component body;
String style = null;
if(p.styling.get() != null && !p.styling.get().equals("Label")) {
style = p.styling.get();
}
if(p.content.get().indexOf('<') > -1) {
if(style != null) {
body = new RichTextView(p.content.get(), "PostStyleText");
((RichTextView)body).setAlignment(CENTER);
body.setUIID(style);
} else {
body = new RichTextView(p.content.get());
body.setUIID("HalfPaddedContainer");
}
} else {
body = new SpanLabel(p.content.get());
if(style != null) {
NewsfeedContainer
like.setUIID("CleanButton");
Button comment = new Button("Comment", "CleanButton");
Button share = new Button("Share", "CleanButton");
FontImage.setMaterialIcon(like, FontImage.MATERIAL_THUMB_UP);
FontImage.setMaterialIcon(comment,
FontImage.MATERIAL_COMMENT);
FontImage.setMaterialIcon(share, FontImage.MATERIAL_SHARE);
Container buttonBar = GridLayout.encloseIn(3, like, comment, share);
buttonBar.setUIID("HalfPaddedContainer");
like.setSelected(p.likes.contains(u));
like.addActionListener(e -> ServerAPI.like(p));
comment.addActionListener(e -> new CommentsForm(p, null).show());
if(p.attachments.size() > 0) {
String key = p.attachments.keySet().iterator().next();
return BoxLayout.encloseY(titleArea, body,
createMediaComponent(p.attachments.get(key), key),
createPostStats(p), buttonBar);
}
return BoxLayout.encloseY(
titleArea, body, createPostStats(p), buttonBar);
}
NewsfeedContainer
like.setUIID("CleanButton");
Button comment = new Button("Comment", "CleanButton");
Button share = new Button("Share", "CleanButton");
FontImage.setMaterialIcon(like, FontImage.MATERIAL_THUMB_UP);
FontImage.setMaterialIcon(comment,
FontImage.MATERIAL_COMMENT);
FontImage.setMaterialIcon(share, FontImage.MATERIAL_SHARE);
Container buttonBar = GridLayout.encloseIn(3, like, comment, share);
buttonBar.setUIID("HalfPaddedContainer");
like.setSelected(p.likes.contains(u));
like.addActionListener(e -> ServerAPI.like(p));
comment.addActionListener(e -> new CommentsForm(p, null).show());
if(p.attachments.size() > 0) {
String key = p.attachments.keySet().iterator().next();
return BoxLayout.encloseY(titleArea, body,
createMediaComponent(p.attachments.get(key), key),
createPostStats(p), buttonBar);
}
return BoxLayout.encloseY(
titleArea, body, createPostStats(p), buttonBar);
}
NewsfeedContainer
return titleArea;
}
public static Container createNewsItem(User u, Post p) {
Container titleArea = createNewsTitle(u, p);
Component body;
String style = null;
if(p.styling.get() != null && !p.styling.get().equals("Label")) {
style = p.styling.get();
}
if(p.content.get().indexOf('<') > -1) {
if(style != null) {
body = new RichTextView(p.content.get(), "PostStyleText");
((RichTextView)body).setAlignment(CENTER);
body.setUIID(style);
} else {
body = new RichTextView(p.content.get());
body.setUIID("HalfPaddedContainer");
}
} else {
body = new SpanLabel(p.content.get());
if(style != null) {
((SpanLabel)body).setTextUIID("PostStyleText");
NewsfeedContainer
String style = null;
if(p.styling.get() != null && !p.styling.get().equals("Label")) {
style = p.styling.get();
}
if(p.content.get().indexOf('<') > -1) {
if(style != null) {
body = new RichTextView(p.content.get(), "PostStyleText");
((RichTextView)body).setAlignment(CENTER);
body.setUIID(style);
} else {
body = new RichTextView(p.content.get());
body.setUIID("HalfPaddedContainer");
}
} else {
body = new SpanLabel(p.content.get());
if(style != null) {
((SpanLabel)body).setTextUIID("PostStyleText");
body.setUIID(style);
} else {
body.setUIID("HalfPaddedContainer");
}
}
CheckBox like = CheckBox.createToggle("Like");
NewsfeedContainer
String style = null;
if(p.styling.get() != null && !p.styling.get().equals("Label")) {
style = p.styling.get();
}
if(p.content.get().indexOf('<') > -1) {
if(style != null) {
body = new RichTextView(p.content.get(), "PostStyleText");
((RichTextView)body).setAlignment(CENTER);
body.setUIID(style);
} else {
body = new RichTextView(p.content.get());
body.setUIID("HalfPaddedContainer");
}
} else {
body = new SpanLabel(p.content.get());
if(style != null) {
((SpanLabel)body).setTextUIID("PostStyleText");
body.setUIID(style);
} else {
body.setUIID("HalfPaddedContainer");
}
}
CheckBox like = CheckBox.createToggle("Like");
NewsfeedContainer
public class RichTextView extends Container {
private String text;
private float fontSize = 2.6f;
private EventDispatcher listeners = new EventDispatcher();
private Font currentFont;
private int currentColor = 0;
private String currentLink;
private Style lastCmp;
private Font defaultFont;
private Font boldFont;
private Font italicFont;
private int sizeOfSpace;
public RichTextView() {
init(null);
}
public RichTextView(String text, String uiid) {
init(uiid);
setText(text);
RichTextView
private Font boldFont;
private Font italicFont;
private int sizeOfSpace;
public RichTextView() {
init(null);
}
public RichTextView(String text, String uiid) {
init(uiid);
setText(text);
}
public RichTextView(String text) {
init(null);
setText(text);
}
private void init(String uiid) {
boldFont = Font.createTrueTypeFont(NATIVE_MAIN_BOLD, fontSize);
italicFont = Font.createTrueTypeFont(NATIVE_ITALIC_LIGHT, fontSize);
if(uiid == null) {
defaultFont = Font.createTrueTypeFont(NATIVE_MAIN_LIGHT,
fontSize);
RichTextView
private Font boldFont;
private Font italicFont;
private int sizeOfSpace;
public RichTextView() {
init(null);
}
public RichTextView(String text, String uiid) {
init(uiid);
setText(text);
}
public RichTextView(String text) {
init(null);
setText(text);
}
private void init(String uiid) {
boldFont = Font.createTrueTypeFont(NATIVE_MAIN_BOLD, fontSize);
italicFont = Font.createTrueTypeFont(NATIVE_ITALIC_LIGHT, fontSize);
if(uiid == null) {
defaultFont = Font.createTrueTypeFont(NATIVE_MAIN_LIGHT,
fontSize);
RichTextView
public RichTextView(String text) {
init(null);
setText(text);
}
private void init(String uiid) {
boldFont = Font.createTrueTypeFont(NATIVE_MAIN_BOLD, fontSize);
italicFont = Font.createTrueTypeFont(NATIVE_ITALIC_LIGHT, fontSize);
if(uiid == null) {
defaultFont = Font.createTrueTypeFont(NATIVE_MAIN_LIGHT,
fontSize);
} else {
Style s = UIManager.getInstance().getComponentStyle(uiid);
defaultFont = s.getFont();
boldFont = boldFont.derive(defaultFont.getHeight(),
Font.STYLE_BOLD);
italicFont = italicFont.derive(defaultFont.getHeight(),
Font.STYLE_ITALIC);
}
sizeOfSpace = defaultFont.charWidth(' ');
currentFont = defaultFont;
}
RichTextView
public RichTextView(String text) {
init(null);
setText(text);
}
private void init(String uiid) {
boldFont = Font.createTrueTypeFont(NATIVE_MAIN_BOLD, fontSize);
italicFont = Font.createTrueTypeFont(NATIVE_ITALIC_LIGHT, fontSize);
if(uiid == null) {
defaultFont = Font.createTrueTypeFont(NATIVE_MAIN_LIGHT,
fontSize);
} else {
Style s = UIManager.getInstance().getComponentStyle(uiid);
defaultFont = s.getFont();
boldFont = boldFont.derive(defaultFont.getHeight(),
Font.STYLE_BOLD);
italicFont = italicFont.derive(defaultFont.getHeight(),
Font.STYLE_ITALIC);
}
sizeOfSpace = defaultFont.charWidth(' ');
currentFont = defaultFont;
}
RichTextView

More Related Content

PDF
Creating a Facebook Clone - Part XLII - Transcript.pdf
PDF
Creating a Facebook Clone - Part XLI.pdf
PDF
Creating a Facebook Clone - Part XLI - Transcript.pdf
PDF
Initial UI Mockup - Part 3.pdf
PDF
Creating a Facebook Clone - Part VII.pdf
PDF
Creating a Facebook Clone - Part XVI.pdf
PDF
Creating a Facebook Clone - Part VI.pdf
PDF
Creating a Facebook Clone - Part XII.pdf
Creating a Facebook Clone - Part XLII - Transcript.pdf
Creating a Facebook Clone - Part XLI.pdf
Creating a Facebook Clone - Part XLI - Transcript.pdf
Initial UI Mockup - Part 3.pdf
Creating a Facebook Clone - Part VII.pdf
Creating a Facebook Clone - Part XVI.pdf
Creating a Facebook Clone - Part VI.pdf
Creating a Facebook Clone - Part XII.pdf

Similar to Creating a Facebook Clone - Part XLII.pdf (20)

PDF
Creating a Facebook Clone - Part VI - Transcript.pdf
PDF
Creating an Uber Clone - Part V.pdf
PDF
Creating a Facebook Clone - Part XVI - Transcript.pdf
PDF
Creating a Facebook Clone - Part XXIX - Transcript.pdf
PDF
Creating an Uber Clone - Part XXXIX.pdf
PDF
Creating a Facebook Clone - Part XIII.pdf
PDF
Creating a Facebook Clone - Part XIII - Transcript.pdf
PDF
i need a remove button to remove the image from my favourites- however.pdf
PDF
Initial UI Mockup - Part 3 - Transcript.pdf
PDF
Creating a Facebook Clone - Part XXVIII.pdf
PDF
UI Design From Scratch - Part 5.pdf
PDF
Creating a Facebook Clone - Part XXXVI.pdf
PDF
Extracting ui Design - part 6 - transcript.pdf
PDF
Creating a Facebook Clone - Part XXXVI - Transcript.pdf
PDF
Getting started with GUI programming in Java_2
PDF
Creating an Uber Clone - Part IX.pdf
PDF
Creating a Facebook Clone - Part XLIII.pdf
PDF
Initial UI Mockup - Part 2.pdf
PDF
UI Design From Scratch - Part 5 - transcript.pdf
PDF
Creating a Facebook Clone - Part XV - Transcript.pdf
Creating a Facebook Clone - Part VI - Transcript.pdf
Creating an Uber Clone - Part V.pdf
Creating a Facebook Clone - Part XVI - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating an Uber Clone - Part XXXIX.pdf
Creating a Facebook Clone - Part XIII.pdf
Creating a Facebook Clone - Part XIII - Transcript.pdf
i need a remove button to remove the image from my favourites- however.pdf
Initial UI Mockup - Part 3 - Transcript.pdf
Creating a Facebook Clone - Part XXVIII.pdf
UI Design From Scratch - Part 5.pdf
Creating a Facebook Clone - Part XXXVI.pdf
Extracting ui Design - part 6 - transcript.pdf
Creating a Facebook Clone - Part XXXVI - Transcript.pdf
Getting started with GUI programming in Java_2
Creating an Uber Clone - Part IX.pdf
Creating a Facebook Clone - Part XLIII.pdf
Initial UI Mockup - Part 2.pdf
UI Design From Scratch - Part 5 - transcript.pdf
Creating a Facebook Clone - Part XV - Transcript.pdf

More from ShaiAlmog1 (20)

PDF
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
PDF
create-netflix-clone-06-client-ui.pdf
PDF
create-netflix-clone-01-introduction_transcript.pdf
PDF
create-netflix-clone-02-server_transcript.pdf
PDF
create-netflix-clone-04-server-continued_transcript.pdf
PDF
create-netflix-clone-01-introduction.pdf
PDF
create-netflix-clone-06-client-ui_transcript.pdf
PDF
create-netflix-clone-03-server.pdf
PDF
create-netflix-clone-04-server-continued.pdf
PDF
create-netflix-clone-05-client-model_transcript.pdf
PDF
create-netflix-clone-03-server_transcript.pdf
PDF
create-netflix-clone-02-server.pdf
PDF
create-netflix-clone-05-client-model.pdf
PDF
Creating a Whatsapp Clone - Part II.pdf
PDF
Creating a Whatsapp Clone - Part IX - Transcript.pdf
PDF
Creating a Whatsapp Clone - Part II - Transcript.pdf
PDF
Creating a Whatsapp Clone - Part V - Transcript.pdf
PDF
Creating a Whatsapp Clone - Part IV - Transcript.pdf
PDF
Creating a Whatsapp Clone - Part IV.pdf
PDF
Creating a Whatsapp Clone - Part I - Transcript.pdf
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-01-introduction.pdf
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-03-server.pdf
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-02-server.pdf
create-netflix-clone-05-client-model.pdf
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
KodekX | Application Modernization Development
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Programs and apps: productivity, graphics, security and other tools
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
20250228 LYD VKU AI Blended-Learning.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
sap open course for s4hana steps from ECC to s4
Unlocking AI with Model Context Protocol (MCP)
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KodekX | Application Modernization Development
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
cuic standard and advanced reporting.pdf
Encapsulation theory and applications.pdf
Big Data Technologies - Introduction.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?

Creating a Facebook Clone - Part XLII.pdf

  • 1. Creating a Facebook Clone - Part XLII
  • 2. } return stats; } private static Container createPostBar() { Button avatar = new Button(ServerAPI.me().getAvatar(6.5f),"Label"); Button writePost = new Button("What's on your mind?", "NewPostButton"); Button gallery = new Button("Photo", "GalleryButton"); FontImage.setMaterialIcon(gallery, FontImage.MATERIAL_PHOTO_LIBRARY, 2.9f); gallery.setTextPosition(BOTTOM); Container c = BorderLayout.centerEastWest(writePost,gallery,avatar); c.setUIID("HalfPaddedContainer"); writePost.addActionListener(e -> NewPostForm.createPost().show()); gallery.addActionListener(e -> { ImagePicker p = new ImagePicker(GALLERY_ALL); p.pick( image -> { NewPostForm.createImagePost(image, p).show(); }, video -> { NewPostForm.createVideoPost(video, p).show(); }); NewsfeedContainer
  • 3. } return stats; } private static Container createPostBar() { Button avatar = new Button(ServerAPI.me().getAvatar(6.5f),"Label"); Button writePost = new Button("What's on your mind?", "NewPostButton"); Button gallery = new Button("Photo", "GalleryButton"); FontImage.setMaterialIcon(gallery, FontImage.MATERIAL_PHOTO_LIBRARY, 2.9f); gallery.setTextPosition(BOTTOM); Container c = BorderLayout.centerEastWest(writePost,gallery,avatar); c.setUIID("HalfPaddedContainer"); writePost.addActionListener(e -> NewPostForm.createPost().show()); gallery.addActionListener(e -> { ImagePicker p = new ImagePicker(GALLERY_ALL); p.pick( image -> { NewPostForm.createImagePost(image, p).show(); }, video -> { NewPostForm.createVideoPost(video, p).show(); }); NewsfeedContainer
  • 4. private static Container createPostBar() { Button avatar = new Button(ServerAPI.me().getAvatar(6.5f),"Label"); Button writePost = new Button("What's on your mind?", "NewPostButton"); Button gallery = new Button("Photo", "GalleryButton"); FontImage.setMaterialIcon(gallery, FontImage.MATERIAL_PHOTO_LIBRARY, 2.9f); gallery.setTextPosition(BOTTOM); Container c = BorderLayout.centerEastWest(writePost,gallery,avatar); c.setUIID("HalfPaddedContainer"); writePost.addActionListener(e -> NewPostForm.createPost().show()); gallery.addActionListener(e -> { ImagePicker p = new ImagePicker(GALLERY_ALL); p.pick( image -> { NewPostForm.createImagePost(image, p).show(); }, video -> { NewPostForm.createVideoPost(video, p).show(); }); }); return c; } } NewsfeedContainer
  • 5. return BoxLayout.encloseY( titleArea, body, createPostStats(p), buttonBar); } private static Image placeholder; private static Component createMediaComponent(String mime, String id) { if(mime.startsWith("image")) { if(placeholder == null) { placeholder = Image.createImage(getDisplayWidth(), getDisplayHeight() / 2, 0); } ScaleImageButton sb = new ScaleImageButton( URLImage.createCachedImage(id, ServerAPI.mediaUrl(id), placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL)); return sb; } else { try { Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id), true); MediaPlayer mp = new MediaPlayer(media) { @Override protected Dimension calcPreferredSize() { return new Dimension(getDisplayWidth(), getDisplayHeight() / 2); NewsfeedContainer
  • 6. return BoxLayout.encloseY( titleArea, body, createPostStats(p), buttonBar); } private static Image placeholder; private static Component createMediaComponent(String mime, String id) { if(mime.startsWith("image")) { if(placeholder == null) { placeholder = Image.createImage(getDisplayWidth(), getDisplayHeight() / 2, 0); } ScaleImageButton sb = new ScaleImageButton( URLImage.createCachedImage(id, ServerAPI.mediaUrl(id), placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL)); return sb; } else { try { Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id), true); MediaPlayer mp = new MediaPlayer(media) { @Override protected Dimension calcPreferredSize() { return new Dimension(getDisplayWidth(), getDisplayHeight() / 2); NewsfeedContainer
  • 7. return BoxLayout.encloseY( titleArea, body, createPostStats(p), buttonBar); } private static Image placeholder; private static Component createMediaComponent(String mime, String id) { if(mime.startsWith("image")) { if(placeholder == null) { placeholder = Image.createImage(getDisplayWidth(), getDisplayHeight() / 2, 0); } ScaleImageButton sb = new ScaleImageButton( URLImage.createCachedImage(id, ServerAPI.mediaUrl(id), placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL)); return sb; } else { try { Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id), true); MediaPlayer mp = new MediaPlayer(media) { @Override protected Dimension calcPreferredSize() { return new Dimension(getDisplayWidth(), getDisplayHeight() / 2); NewsfeedContainer
  • 8. return BoxLayout.encloseY( titleArea, body, createPostStats(p), buttonBar); } private static Image placeholder; private static Component createMediaComponent(String mime, String id) { if(mime.startsWith("image")) { if(placeholder == null) { placeholder = Image.createImage(getDisplayWidth(), getDisplayHeight() / 2, 0); } ScaleImageButton sb = new ScaleImageButton( URLImage.createCachedImage(id, ServerAPI.mediaUrl(id), placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL)); return sb; } else { try { Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id), true); MediaPlayer mp = new MediaPlayer(media) { @Override protected Dimension calcPreferredSize() { return new Dimension(getDisplayWidth(), getDisplayHeight() / 2); NewsfeedContainer
  • 9. } ScaleImageButton sb = new ScaleImageButton( URLImage.createCachedImage(id, ServerAPI.mediaUrl(id), placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL)); return sb; } else { try { Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id), true); MediaPlayer mp = new MediaPlayer(media) { @Override protected Dimension calcPreferredSize() { return new Dimension(getDisplayWidth(), getDisplayHeight() / 2); } }; mp.setLoop(true); return mp; } catch(IOException err) { Log.e(err); return new Label("Error loading media"); } } } NewsfeedContainer
  • 10. } ScaleImageButton sb = new ScaleImageButton( URLImage.createCachedImage(id, ServerAPI.mediaUrl(id), placeholder, URLImage.FLAG_RESIZE_SCALE_TO_FILL)); return sb; } else { try { Media media=MediaManager.createMedia(ServerAPI.mediaUrl(id), true); MediaPlayer mp = new MediaPlayer(media) { @Override protected Dimension calcPreferredSize() { return new Dimension(getDisplayWidth(), getDisplayHeight() / 2); } }; mp.setLoop(true); return mp; } catch(IOException err) { Log.e(err); return new Label("Error loading media"); } } } NewsfeedContainer
  • 11. titleArea.setUIID("HalfPaddedContainer"); return titleArea; } public static Container createNewsItem(User u, Post p) { Container titleArea = createNewsTitle(u, p); Component body; String style = null; if(p.styling.get() != null && !p.styling.get().equals("Label")) { style = p.styling.get(); } if(p.content.get().indexOf('<') > -1) { if(style != null) { body = new RichTextView(p.content.get(), "PostStyleText"); ((RichTextView)body).setAlignment(CENTER); body.setUIID(style); } else { body = new RichTextView(p.content.get()); body.setUIID("HalfPaddedContainer"); } } else { body = new SpanLabel(p.content.get()); if(style != null) { NewsfeedContainer
  • 12. like.setUIID("CleanButton"); Button comment = new Button("Comment", "CleanButton"); Button share = new Button("Share", "CleanButton"); FontImage.setMaterialIcon(like, FontImage.MATERIAL_THUMB_UP); FontImage.setMaterialIcon(comment, FontImage.MATERIAL_COMMENT); FontImage.setMaterialIcon(share, FontImage.MATERIAL_SHARE); Container buttonBar = GridLayout.encloseIn(3, like, comment, share); buttonBar.setUIID("HalfPaddedContainer"); like.setSelected(p.likes.contains(u)); like.addActionListener(e -> ServerAPI.like(p)); comment.addActionListener(e -> new CommentsForm(p, null).show()); if(p.attachments.size() > 0) { String key = p.attachments.keySet().iterator().next(); return BoxLayout.encloseY(titleArea, body, createMediaComponent(p.attachments.get(key), key), createPostStats(p), buttonBar); } return BoxLayout.encloseY( titleArea, body, createPostStats(p), buttonBar); } NewsfeedContainer
  • 13. like.setUIID("CleanButton"); Button comment = new Button("Comment", "CleanButton"); Button share = new Button("Share", "CleanButton"); FontImage.setMaterialIcon(like, FontImage.MATERIAL_THUMB_UP); FontImage.setMaterialIcon(comment, FontImage.MATERIAL_COMMENT); FontImage.setMaterialIcon(share, FontImage.MATERIAL_SHARE); Container buttonBar = GridLayout.encloseIn(3, like, comment, share); buttonBar.setUIID("HalfPaddedContainer"); like.setSelected(p.likes.contains(u)); like.addActionListener(e -> ServerAPI.like(p)); comment.addActionListener(e -> new CommentsForm(p, null).show()); if(p.attachments.size() > 0) { String key = p.attachments.keySet().iterator().next(); return BoxLayout.encloseY(titleArea, body, createMediaComponent(p.attachments.get(key), key), createPostStats(p), buttonBar); } return BoxLayout.encloseY( titleArea, body, createPostStats(p), buttonBar); } NewsfeedContainer
  • 14. return titleArea; } public static Container createNewsItem(User u, Post p) { Container titleArea = createNewsTitle(u, p); Component body; String style = null; if(p.styling.get() != null && !p.styling.get().equals("Label")) { style = p.styling.get(); } if(p.content.get().indexOf('<') > -1) { if(style != null) { body = new RichTextView(p.content.get(), "PostStyleText"); ((RichTextView)body).setAlignment(CENTER); body.setUIID(style); } else { body = new RichTextView(p.content.get()); body.setUIID("HalfPaddedContainer"); } } else { body = new SpanLabel(p.content.get()); if(style != null) { ((SpanLabel)body).setTextUIID("PostStyleText"); NewsfeedContainer
  • 15. String style = null; if(p.styling.get() != null && !p.styling.get().equals("Label")) { style = p.styling.get(); } if(p.content.get().indexOf('<') > -1) { if(style != null) { body = new RichTextView(p.content.get(), "PostStyleText"); ((RichTextView)body).setAlignment(CENTER); body.setUIID(style); } else { body = new RichTextView(p.content.get()); body.setUIID("HalfPaddedContainer"); } } else { body = new SpanLabel(p.content.get()); if(style != null) { ((SpanLabel)body).setTextUIID("PostStyleText"); body.setUIID(style); } else { body.setUIID("HalfPaddedContainer"); } } CheckBox like = CheckBox.createToggle("Like"); NewsfeedContainer
  • 16. String style = null; if(p.styling.get() != null && !p.styling.get().equals("Label")) { style = p.styling.get(); } if(p.content.get().indexOf('<') > -1) { if(style != null) { body = new RichTextView(p.content.get(), "PostStyleText"); ((RichTextView)body).setAlignment(CENTER); body.setUIID(style); } else { body = new RichTextView(p.content.get()); body.setUIID("HalfPaddedContainer"); } } else { body = new SpanLabel(p.content.get()); if(style != null) { ((SpanLabel)body).setTextUIID("PostStyleText"); body.setUIID(style); } else { body.setUIID("HalfPaddedContainer"); } } CheckBox like = CheckBox.createToggle("Like"); NewsfeedContainer
  • 17. public class RichTextView extends Container { private String text; private float fontSize = 2.6f; private EventDispatcher listeners = new EventDispatcher(); private Font currentFont; private int currentColor = 0; private String currentLink; private Style lastCmp; private Font defaultFont; private Font boldFont; private Font italicFont; private int sizeOfSpace; public RichTextView() { init(null); } public RichTextView(String text, String uiid) { init(uiid); setText(text); RichTextView
  • 18. private Font boldFont; private Font italicFont; private int sizeOfSpace; public RichTextView() { init(null); } public RichTextView(String text, String uiid) { init(uiid); setText(text); } public RichTextView(String text) { init(null); setText(text); } private void init(String uiid) { boldFont = Font.createTrueTypeFont(NATIVE_MAIN_BOLD, fontSize); italicFont = Font.createTrueTypeFont(NATIVE_ITALIC_LIGHT, fontSize); if(uiid == null) { defaultFont = Font.createTrueTypeFont(NATIVE_MAIN_LIGHT, fontSize); RichTextView
  • 19. private Font boldFont; private Font italicFont; private int sizeOfSpace; public RichTextView() { init(null); } public RichTextView(String text, String uiid) { init(uiid); setText(text); } public RichTextView(String text) { init(null); setText(text); } private void init(String uiid) { boldFont = Font.createTrueTypeFont(NATIVE_MAIN_BOLD, fontSize); italicFont = Font.createTrueTypeFont(NATIVE_ITALIC_LIGHT, fontSize); if(uiid == null) { defaultFont = Font.createTrueTypeFont(NATIVE_MAIN_LIGHT, fontSize); RichTextView
  • 20. public RichTextView(String text) { init(null); setText(text); } private void init(String uiid) { boldFont = Font.createTrueTypeFont(NATIVE_MAIN_BOLD, fontSize); italicFont = Font.createTrueTypeFont(NATIVE_ITALIC_LIGHT, fontSize); if(uiid == null) { defaultFont = Font.createTrueTypeFont(NATIVE_MAIN_LIGHT, fontSize); } else { Style s = UIManager.getInstance().getComponentStyle(uiid); defaultFont = s.getFont(); boldFont = boldFont.derive(defaultFont.getHeight(), Font.STYLE_BOLD); italicFont = italicFont.derive(defaultFont.getHeight(), Font.STYLE_ITALIC); } sizeOfSpace = defaultFont.charWidth(' '); currentFont = defaultFont; } RichTextView
  • 21. public RichTextView(String text) { init(null); setText(text); } private void init(String uiid) { boldFont = Font.createTrueTypeFont(NATIVE_MAIN_BOLD, fontSize); italicFont = Font.createTrueTypeFont(NATIVE_ITALIC_LIGHT, fontSize); if(uiid == null) { defaultFont = Font.createTrueTypeFont(NATIVE_MAIN_LIGHT, fontSize); } else { Style s = UIManager.getInstance().getComponentStyle(uiid); defaultFont = s.getFont(); boldFont = boldFont.derive(defaultFont.getHeight(), Font.STYLE_BOLD); italicFont = italicFont.derive(defaultFont.getHeight(), Font.STYLE_ITALIC); } sizeOfSpace = defaultFont.charWidth(' '); currentFont = defaultFont; } RichTextView