mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
add announcements
This commit is contained in:
@@ -34,7 +34,7 @@ public enum IconLoader {
|
||||
"id_card_edit.png"), KeyEdit("key_edit.png"), Find("find.png"), Dashboard("dashboard.png"), DataFind(
|
||||
"data_find.png"), CloudDownload("cloud-download.png"), NavLeftBlue("nav_left_blue.png"), NavRightBlue(
|
||||
"nav_right_blue.png"), MissingImage("missing_image.png"), CloudBg("cloud_bg.png"), CloudBig("cloud_big.png"), CloudWait(
|
||||
"cloud_wait.png"), Spinning("spinning.gif");
|
||||
"cloud_wait.png"), Spinning("spinning.gif"), Megaphone("megaphone.png");
|
||||
|
||||
protected String name;
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 854 B |
+15
-3
@@ -6,6 +6,8 @@ import java.awt.Graphics;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -28,7 +30,9 @@ import javax.swing.JScrollPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
@@ -139,11 +143,21 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
JLabel thumbnailLabel = new JLabel(loadImage(project.getThumbnailUrl()));
|
||||
JLabel nameLabel = new JLabel("<html><b>" + project.getName() + "</b></html>");
|
||||
nameLabel.setFont(nameLabel.getFont().deriveFont(12f));
|
||||
|
||||
// JLabel descriptionArea = new JLabel("<html><p align='justify'>" + project.getDescription() +
|
||||
// "</p></html>");
|
||||
JTextArea descriptionArea = new JTextArea(project.getDescription().replace("<br>", "\n"));
|
||||
descriptionArea.setEditable(false);
|
||||
descriptionArea.setFont(thumbnailLabel.getFont());
|
||||
descriptionArea.setLineWrap(true);
|
||||
descriptionArea.setWrapStyleWord(true);
|
||||
descriptionArea.setFocusable(false);
|
||||
descriptionArea.setRequestFocusEnabled(false);
|
||||
DefaultCaret caret = (DefaultCaret) descriptionArea.getCaret();
|
||||
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
|
||||
descriptionArea.setEnabled(false);
|
||||
// descriptionArea.setDisabledTextColor(descriptionArea.getSelectionColor());
|
||||
|
||||
JLabel categoryLabel = new JLabel("<html>Category: <b>" + project.getCategory() + "</b></html>");
|
||||
JLabel authorLabel = new JLabel("<html>Author: <b>" + project.getOwner() + "</b></html>");
|
||||
JLabel updatedLabel = new JLabel("<html>Last updated: <b>" + project.getUpdated() + "</b></html>");
|
||||
@@ -271,9 +285,7 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
gbc.insets = new Insets(2, 2, 2, 2);
|
||||
getResultsPanel().add(new JSeparator(), gbc);
|
||||
|
||||
getResultsPanel().invalidate();
|
||||
|
||||
return thumbnailLabel;
|
||||
return nameLabel;
|
||||
}
|
||||
|
||||
private JLabel getLoadMoreLabel() {
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package org.diylc.swing.plugins.statusbar;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.Format;
|
||||
import java.util.ArrayList;
|
||||
@@ -27,6 +30,8 @@ import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.announcements.Announcement;
|
||||
import org.diylc.announcements.AnnouncementProvider;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.Utils;
|
||||
import org.diylc.common.BadPositionException;
|
||||
@@ -34,7 +39,9 @@ import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ITask;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.ISwingUI;
|
||||
@@ -53,11 +60,13 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
|
||||
private JComboBox zoomBox;
|
||||
private UpdateLabel updateLabel;
|
||||
private JLabel announcementLabel;
|
||||
private MemoryBar memoryPanel;
|
||||
private JLabel statusLabel;
|
||||
private JLabel sizeLabel;
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
private ISwingUI swingUI;
|
||||
|
||||
// State variables
|
||||
private ComponentType componentSlot;
|
||||
@@ -67,8 +76,13 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
private List<String> stuckComponentNames;
|
||||
private String statusMessage;
|
||||
|
||||
private AnnouncementProvider announcementProvider;
|
||||
|
||||
public StatusBar(ISwingUI swingUI) {
|
||||
super();
|
||||
this.swingUI = swingUI;
|
||||
|
||||
this.announcementProvider = new AnnouncementProvider();
|
||||
|
||||
setLayout(new GridBagLayout());
|
||||
|
||||
@@ -77,6 +91,29 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
} catch (BadPositionException e) {
|
||||
LOG.error("Could not install status bar", e);
|
||||
}
|
||||
|
||||
swingUI.executeBackgroundTask(new ITask<String>() {
|
||||
|
||||
@Override
|
||||
public String doInBackground() throws Exception {
|
||||
Thread.sleep(1000);
|
||||
return announcementProvider.getCurrentAnnouncements();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
LOG.error("Error while fetching announcements", e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(String result) {
|
||||
if (result != null && result.length() > 0) {
|
||||
StatusBar.this.swingUI.showMessage(result, "Public Announcements", IView.INFORMATION_MESSAGE);
|
||||
announcementProvider.dismissed();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private JComboBox getZoomBox() {
|
||||
@@ -107,6 +144,45 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
return updateLabel;
|
||||
}
|
||||
|
||||
public JLabel getAnnouncementLabel() {
|
||||
if (announcementLabel == null) {
|
||||
announcementLabel = new JLabel(IconLoader.Megaphone.getIcon());
|
||||
announcementLabel.setToolTipText("Check for public announcements");
|
||||
announcementLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
announcementLabel.addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
swingUI.executeBackgroundTask(new ITask<String>() {
|
||||
|
||||
@Override
|
||||
public String doInBackground() throws Exception {
|
||||
return announcementProvider.getCurrentAnnouncements();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
LOG.error("Error while fetching announcements", e);
|
||||
swingUI.showMessage("Could not fetch public announcements.", "Error", IView.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(String result) {
|
||||
if (result != null && result.length() > 0) {
|
||||
swingUI.showMessage(result, "Public Announcements", IView.INFORMATION_MESSAGE);
|
||||
announcementProvider.dismissed();
|
||||
} else
|
||||
swingUI.showMessage("No new public announcements available.", "Public Announcements",
|
||||
IView.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return announcementLabel;
|
||||
}
|
||||
|
||||
private MemoryBar getMemoryPanel() {
|
||||
if (memoryPanel == null) {
|
||||
memoryPanel = new MemoryBar(false);
|
||||
@@ -165,19 +241,25 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
// 4)));
|
||||
zoomPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));
|
||||
|
||||
gbc.gridx = 1;
|
||||
gbc.gridx++;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.weightx = 0;
|
||||
add(zoomPanel, gbc);
|
||||
|
||||
gbc.gridx = 2;
|
||||
gbc.gridx++;
|
||||
gbc.insets = new Insets(0, 2, 0, 2);
|
||||
add(getSizeLabel(), gbc);
|
||||
|
||||
gbc.gridx = 3;
|
||||
gbc.gridx++;
|
||||
add(getAnnouncementLabel(), gbc);
|
||||
|
||||
gbc.gridx++;
|
||||
gbc.insets = new Insets(0, 0, 0, 0);
|
||||
add(getUpdateLabel(), gbc);
|
||||
|
||||
gbc.gridx = 4;
|
||||
gbc.gridx++;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.insets = new Insets(0, 0, 0, 4);
|
||||
add(getMemoryPanel(), gbc);
|
||||
|
||||
gbc.gridx = 5;
|
||||
|
||||
Reference in New Issue
Block a user