Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * TweetPanel.java
- *
- * Created on 2011.11.05., 0:00:26
- */
- package net.rothens.twitt3ns.gui;
- import java.awt.Color;
- import java.awt.Desktop;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.IOException;
- import java.net.URI;
- import java.net.URISyntaxException;
- import java.util.Iterator;
- import java.util.LinkedList;
- import java.util.List;
- import javax.swing.JLabel;
- import javax.swing.border.LineBorder;
- import javax.swing.text.html.HTMLEditorKit;
- import net.rothens.twitt3ns.Twitt3ns;
- import twitter4j.Status;
- import twitter4j.URLEntity;
- /**
- *
- * @author Rothens
- */
- public class TweetPanel extends javax.swing.JPanel {
- private Twitt3ns tw = Twitt3ns.tw;
- private Status s;
- public static TweetPanel instance;
- /** Creates new form TweetPanel */
- public TweetPanel(Status s) {
- this.s = s;
- instance = this;
- initComponents();
- picture.setIcon(tw.mw.createImageIcon("/res/default_normal.png", "Profilkép"));
- picture.setIcon(tw.mw.createImageFromURL(s.getUser().getProfileImageURL(), "profilkép", 3));
- displayName.setText(s.getUser().getScreenName());
- lblTime.setText(getTimeAgo(s.getCreatedAt().getTime()));
- tweet.setEditorKit(new HTMLEditorKit());
- String text = s.getText();
- ((TwitterPane)tweet).updateText(s);
- tweets.setText(s.getUser().getStatusesCount() + "");
- btnFav.setSelected(s.isFavorited());
- //RT button
- btnRT.setText(null);
- btnRT.setIcon(tw.mw.createImageIcon("/res/rt.png", "RT"));
- btnRT.setRolloverIcon(tw.mw.createImageIcon("/res/rt_hover.png", "RT"));
- btnRT.setPressedIcon(tw.mw.createImageIcon("/res/rt_selected.png", "RT"));
- btnRT.setActionCommand("RT");
- btnRT.addActionListener(new tweetClick());
- //Reply button
- btnReply.setText(null);
- btnReply.setIcon(tw.mw.createImageIcon("/res/reply_normal.png", "reply"));
- btnReply.setRolloverIcon(tw.mw.createImageIcon("/res/reply_hover.png", "reply"));
- btnReply.setPressedIcon(tw.mw.createImageIcon("/res/reply_selected.png", "reply"));
- btnReply.setActionCommand("Reply");
- btnReply.addActionListener(new tweetClick());
- //Favorite button
- btnFav.setText(null);
- btnFav.setIcon(tw.mw.createImageIcon("/res/fav_off.png", "reply"));
- btnFav.setRolloverIcon(tw.mw.createImageIcon("/res/fav_off_rollover.png", "favorite"));
- btnFav.setSelectedIcon(tw.mw.createImageIcon("/res/fav_on.png", "favorite"));
- btnFav.setRolloverSelectedIcon(tw.mw.createImageIcon("/res/fav_on_rollover.png", "favorite"));
- }
- public String getTimeAgo(long from) {
- long curr = System.currentTimeMillis();
- long diff = curr / 1000 - from / 1000;
- if (diff < 30) {
- return "most";
- } else if (diff < 60) {
- return "fél perce";
- } else if (diff < 1800) {
- return (int) Math.floor(diff / 60) + " perce";
- } else if (diff < 3600) {
- return "fél órája";
- } else if (diff < 86400) {
- return (int) Math.floor(diff / 3600) + " órája";
- } else if (diff < 2592000) {
- return (int) Math.floor(diff / 86400) + " napja";
- } else {
- return "jó rég";
- }
- }
- public class tweetClick implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent e) {
- if (e.getActionCommand() == null) {
- return;
- }
- if (e.getActionCommand().equals("RT")) {
- tw.t.retweetStatus(s.getId());
- } else if (e.getActionCommand().equals("Reply")) {
- ReplyFrame rf = new ReplyFrame(s);
- rf.setVisible(true);
- }
- }
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- picture = new javax.swing.JLabel();
- tweets = new javax.swing.JLabel();
- displayName = new javax.swing.JLabel();
- btnRT = new javax.swing.JButton();
- btnReply = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- tweet = new TwitterPane();
- lblTime = new javax.swing.JLabel();
- btnFav = new javax.swing.JToggleButton();
- setBackground(new java.awt.Color(255, 255, 255));
- setBorder(javax.swing.BorderFactory.createEtchedBorder());
- setAlignmentX(0.0F);
- setAlignmentY(0.0F);
- setMaximumSize(new java.awt.Dimension(500, 120));
- setMinimumSize(new java.awt.Dimension(500, 120));
- picture.setMaximumSize(new java.awt.Dimension(48, 48));
- picture.setMinimumSize(new java.awt.Dimension(48, 48));
- picture.setPreferredSize(new java.awt.Dimension(48, 48));
- tweets.setText("1122");
- displayName.setText("@name");
- displayName.setToolTipText("Profil megtekintése");
- displayName.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- displayNameMouseClicked(evt);
- }
- public void mouseEntered(java.awt.event.MouseEvent evt) {
- displayNameMouseEntered(evt);
- }
- public void mouseExited(java.awt.event.MouseEvent evt) {
- displayNameMouseExited(evt);
- }
- });
- btnRT.setText("RT");
- btnRT.setToolTipText("ReTweet");
- btnRT.setBorder(null);
- btnRT.setContentAreaFilled(false);
- btnReply.setText("Reply");
- btnReply.setToolTipText("válasz");
- btnReply.setBorder(null);
- btnReply.setBorderPainted(false);
- btnReply.setContentAreaFilled(false);
- jScrollPane1.setBorder(null);
- jScrollPane1.setHorizontalScrollBar(null);
- tweet.setBorder(null);
- tweet.setEditable(false);
- tweet.setText("qwertzuiop asdfghjkl qwert zui qwe asdfghjk lqwert zfdscx gerdasdea fd gflrp afde rptlgn adfd sdf vcx ds as df er ddfdqw qwertz asd 112 116");
- tweet.setAlignmentX(0.0F);
- tweet.setAlignmentY(0.0F);
- jScrollPane1.setViewportView(tweet);
- lblTime.setForeground(new java.awt.Color(204, 204, 204));
- lblTime.setText("5 perce");
- btnFav.setText("Favorite");
- btnFav.setToolTipText("tetszik");
- btnFav.setActionCommand("btnFav");
- btnFav.setBorder(null);
- btnFav.setContentAreaFilled(false);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
- this.setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(tweets, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(picture, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(28, 28, 28)
- .addComponent(btnRT)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(btnReply)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btnFav))
- .addGroup(layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1)))
- .addContainerGap())
- .addGroup(layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(displayName)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 260, Short.MAX_VALUE)
- .addComponent(lblTime)
- .addGap(110, 110, 110))))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(picture, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(displayName)
- .addComponent(lblTime))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(tweets)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btnRT)
- .addComponent(btnReply)
- .addComponent(btnFav)))
- .addContainerGap())
- );
- }// </editor-fold>
- private void displayNameMouseClicked(java.awt.event.MouseEvent evt) {
- URI uri = null;
- try {
- uri = new URI("http://twitter.com/" + ((JLabel) evt.getComponent()).getText());
- } catch (URISyntaxException e) {
- }
- if (uri != null) {
- try {
- Desktop.getDesktop().browse(uri);
- } catch (IOException ex) {
- }
- }
- }
- private void displayNameMouseEntered(java.awt.event.MouseEvent evt) {
- displayName.setBorder(new LineBorder(Color.BLACK, 1, true));
- }
- private void displayNameMouseExited(java.awt.event.MouseEvent evt) {
- displayName.setBorder(null);
- }
- public void updateTime() {
- lblTime.setText(getTimeAgo(s.getCreatedAt().getTime()));
- }
- // Variables declaration - do not modify
- private javax.swing.JToggleButton btnFav;
- private javax.swing.JButton btnRT;
- private javax.swing.JButton btnReply;
- private javax.swing.JLabel displayName;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JLabel lblTime;
- private javax.swing.JLabel picture;
- private javax.swing.JEditorPane tweet;
- private javax.swing.JLabel tweets;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement