mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added bitchin' cloud animation
This commit is contained in:
@@ -2,9 +2,13 @@ package org.diylc.plugins.cloud.presenter;
|
|||||||
|
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.channels.Channels;
|
||||||
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@@ -212,12 +216,25 @@ public class CloudPresenter {
|
|||||||
LOG.info(String.format("search(%1$s,%2$s,%3$s,%4$d,%5$d)", criteria, category, sortOrder, pageNumber, itemsPerPage));
|
LOG.info(String.format("search(%1$s,%2$s,%3$s,%4$d,%5$d)", criteria, category, sortOrder, pageNumber, itemsPerPage));
|
||||||
try {
|
try {
|
||||||
Object res = service.search(criteria, category, "json", pageNumber, itemsPerPage, sortOrder);
|
Object res = service.search(criteria, category, "json", pageNumber, itemsPerPage, sortOrder);
|
||||||
|
// Thread.sleep(2000);
|
||||||
if (res == null)
|
if (res == null)
|
||||||
throw new CloudException("Failed to retreive search results.");
|
throw new CloudException("Failed to retreive search results.");
|
||||||
if (res instanceof String)
|
if (res instanceof String)
|
||||||
throw new CloudException(res.toString());
|
throw new CloudException(res.toString());
|
||||||
if (res instanceof List<?>)
|
if (res instanceof List<?>) {
|
||||||
return (List<ProjectEntity>) res;
|
List<ProjectEntity> projects = (List<ProjectEntity>) res;
|
||||||
|
// Download thumbnails and replace urls with local paths
|
||||||
|
for (int i = 0; i < projects.size(); i++) {
|
||||||
|
String url = projects.get(i).getThumbnailUrl();
|
||||||
|
URL website = new URL(url);
|
||||||
|
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
|
||||||
|
File temp = File.createTempFile("thumbnail", ".png");
|
||||||
|
FileOutputStream fos = new FileOutputStream(temp);
|
||||||
|
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
|
projects.get(i).setThumbnailUrl(temp.getAbsolutePath());
|
||||||
|
}
|
||||||
|
return projects;
|
||||||
|
}
|
||||||
throw new CloudException("Unexpected server response received for search results: " + res.getClass().getName());
|
throw new CloudException("Unexpected server response received for search results: " + res.getClass().getName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CloudException(e);
|
throw new CloudException(e);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public enum IconLoader {
|
|||||||
"arrow.png"), Cloud("cloud.png"), CloudUp("cloud_up.png"), CloudGear("cloud_gear.png"), IdCardEdit(
|
"arrow.png"), Cloud("cloud.png"), CloudUp("cloud_up.png"), CloudGear("cloud_gear.png"), IdCardEdit(
|
||||||
"id_card_edit.png"), KeyEdit("key_edit.png"), Find("find.png"), Dashboard("dashboard.png"), DataFind(
|
"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(
|
"data_find.png"), CloudDownload("cloud-download.png"), NavLeftBlue("nav_left_blue.png"), NavRightBlue(
|
||||||
"nav_right_blue.png");
|
"nav_right_blue.png"), MissingImage("missing_image.png"), CloudBg("cloud_bg.png");
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 7.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
@@ -5,13 +5,12 @@ import java.awt.Cursor;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.Image;
|
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
@@ -28,11 +27,13 @@ import javax.swing.JFrame;
|
|||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JRootPane;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JSeparator;
|
import javax.swing.JSeparator;
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
@@ -46,7 +47,6 @@ import org.diylc.plugins.cloud.model.ProjectEntity;
|
|||||||
import org.diylc.plugins.cloud.presenter.CloudException;
|
import org.diylc.plugins.cloud.presenter.CloudException;
|
||||||
import org.diylc.plugins.cloud.presenter.CloudPresenter;
|
import org.diylc.plugins.cloud.presenter.CloudPresenter;
|
||||||
import org.diylc.swing.ISwingUI;
|
import org.diylc.swing.ISwingUI;
|
||||||
import org.diylc.swing.gui.CustomGlassPane;
|
|
||||||
import org.diylc.swing.gui.DialogFactory;
|
import org.diylc.swing.gui.DialogFactory;
|
||||||
import org.diylc.swing.plugins.file.FileFilterEnum;
|
import org.diylc.swing.plugins.file.FileFilterEnum;
|
||||||
|
|
||||||
@@ -73,6 +73,12 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
private IPlugInPort plugInPort;
|
private IPlugInPort plugInPort;
|
||||||
private CloudPresenter cloudPresenter;
|
private CloudPresenter cloudPresenter;
|
||||||
|
|
||||||
|
private JPanel navigationPanel;
|
||||||
|
private JButton prevPageButton;
|
||||||
|
private JButton nextPageButton;
|
||||||
|
private JLabel pageLabel;
|
||||||
|
private List<ProjectEntity> currentResults;
|
||||||
|
|
||||||
// search criteria
|
// search criteria
|
||||||
private String searchFor;
|
private String searchFor;
|
||||||
private String category;
|
private String category;
|
||||||
@@ -90,7 +96,10 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
setContentPane(getMainPanel());
|
setContentPane(getMainPanel());
|
||||||
this.pack();
|
this.pack();
|
||||||
this.setLocationRelativeTo(owner);
|
this.setLocationRelativeTo(owner);
|
||||||
this.setGlassPane(new CustomGlassPane());
|
this.setGlassPane(new CloudGlassPane());
|
||||||
|
|
||||||
|
JRootPane rootPane = SwingUtilities.getRootPane(getGoButton());
|
||||||
|
rootPane.setDefaultButton(getGoButton());
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getMainPanel() {
|
public JPanel getMainPanel() {
|
||||||
@@ -155,6 +164,15 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
gbc.weighty = 1;
|
gbc.weighty = 1;
|
||||||
gbc.fill = GridBagConstraints.BOTH;
|
gbc.fill = GridBagConstraints.BOTH;
|
||||||
browsePanel.add(getResultsScrollPane(), gbc);
|
browsePanel.add(getResultsScrollPane(), gbc);
|
||||||
|
|
||||||
|
gbc.anchor = GridBagConstraints.NORTHWEST;
|
||||||
|
gbc.insets = new Insets(2, 2, 2, 2);
|
||||||
|
gbc.gridx = 0;
|
||||||
|
gbc.gridy++;
|
||||||
|
gbc.fill = GridBagConstraints.BOTH;
|
||||||
|
gbc.weighty = 0;
|
||||||
|
gbc.gridwidth = 3;
|
||||||
|
browsePanel.add(getNavigationPanel(), gbc);
|
||||||
}
|
}
|
||||||
return browsePanel;
|
return browsePanel;
|
||||||
}
|
}
|
||||||
@@ -253,7 +271,7 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
CloudBrowserFrame.this.pageNumber = 1;
|
setPageNumber(1);
|
||||||
CloudBrowserFrame.this.searchFor = getSearchField().getText();
|
CloudBrowserFrame.this.searchFor = getSearchField().getText();
|
||||||
CloudBrowserFrame.this.category =
|
CloudBrowserFrame.this.category =
|
||||||
getCategoryBox().getSelectedItem() == null ? "" : getCategoryBox().getSelectedItem().toString();
|
getCategoryBox().getSelectedItem() == null ? "" : getCategoryBox().getSelectedItem().toString();
|
||||||
@@ -283,6 +301,7 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void complete(List<ProjectEntity> result) {
|
public void complete(List<ProjectEntity> result) {
|
||||||
|
CloudBrowserFrame.this.currentResults = result;
|
||||||
getResultsPanel().removeAll();
|
getResultsPanel().removeAll();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Iterator<ProjectEntity> i = result.iterator(); i.hasNext();) {
|
for (Iterator<ProjectEntity> i = result.iterator(); i.hasNext();) {
|
||||||
@@ -293,7 +312,7 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
showNoMatches();
|
showNoMatches();
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
addNavigationPanel(count);
|
// addNavigationPanel(count);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -443,11 +462,37 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
getResultsPanel().add(new JSeparator(), gbc);
|
getResultsPanel().add(new JSeparator(), gbc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNavigationPanel(int location) {
|
private JPanel getNavigationPanel() {
|
||||||
JPanel navigationPanel = new JPanel(new GridBagLayout());
|
if (navigationPanel == null) {
|
||||||
|
navigationPanel = new JPanel(new GridBagLayout());
|
||||||
navigationPanel.setBackground(Color.white);
|
navigationPanel.setBackground(Color.white);
|
||||||
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
|
gbc.anchor = GridBagConstraints.SOUTHWEST;
|
||||||
|
gbc.insets = new Insets(2, 2, 2, 2);
|
||||||
|
gbc.gridx = 0;
|
||||||
|
gbc.weightx = 0;
|
||||||
|
gbc.fill = GridBagConstraints.NONE;
|
||||||
|
navigationPanel.add(getPrevPageButton(), gbc);
|
||||||
|
|
||||||
JButton prevPageButton = new JButton(IconLoader.NavLeftBlue.getIcon());
|
gbc.gridx++;
|
||||||
|
gbc.weightx = 1;
|
||||||
|
gbc.anchor = GridBagConstraints.LINE_START;
|
||||||
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
navigationPanel.add(getPageLabel(), gbc);
|
||||||
|
|
||||||
|
gbc.gridx++;
|
||||||
|
gbc.weightx = 0;
|
||||||
|
gbc.anchor = GridBagConstraints.SOUTHWEST;
|
||||||
|
gbc.fill = GridBagConstraints.NONE;
|
||||||
|
navigationPanel.add(getNextPageButton(), gbc);
|
||||||
|
|
||||||
|
}
|
||||||
|
return navigationPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JButton getPrevPageButton() {
|
||||||
|
if (prevPageButton == null) {
|
||||||
|
prevPageButton = new JButton(IconLoader.NavLeftBlue.getIcon());
|
||||||
prevPageButton.setBorderPainted(false);
|
prevPageButton.setBorderPainted(false);
|
||||||
prevPageButton.setContentAreaFilled(false);
|
prevPageButton.setContentAreaFilled(false);
|
||||||
prevPageButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
prevPageButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
@@ -456,13 +501,18 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (CloudBrowserFrame.this.pageNumber > 1) {
|
if (CloudBrowserFrame.this.pageNumber > 1) {
|
||||||
CloudBrowserFrame.this.pageNumber--;
|
setPageNumber(CloudBrowserFrame.this.pageNumber - 1);
|
||||||
CloudBrowserFrame.this.search();
|
CloudBrowserFrame.this.search();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
return prevPageButton;
|
||||||
|
}
|
||||||
|
|
||||||
JButton nextPageButton = new JButton(IconLoader.NavRightBlue.getIcon());
|
private JButton getNextPageButton() {
|
||||||
|
if (nextPageButton == null) {
|
||||||
|
nextPageButton = new JButton(IconLoader.NavRightBlue.getIcon());
|
||||||
nextPageButton.setBorderPainted(false);
|
nextPageButton.setBorderPainted(false);
|
||||||
nextPageButton.setContentAreaFilled(false);
|
nextPageButton.setContentAreaFilled(false);
|
||||||
nextPageButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
nextPageButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
@@ -470,37 +520,41 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
CloudBrowserFrame.this.pageNumber++;
|
if (CloudBrowserFrame.this.currentResults != null && !CloudBrowserFrame.this.currentResults.isEmpty()) {
|
||||||
|
setPageNumber(CloudBrowserFrame.this.pageNumber + 1);
|
||||||
CloudBrowserFrame.this.search();
|
CloudBrowserFrame.this.search();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
GridBagConstraints gbc = new GridBagConstraints();
|
|
||||||
gbc.anchor = GridBagConstraints.SOUTHWEST;
|
|
||||||
gbc.insets = new Insets(2, 2, 2, 2);
|
|
||||||
gbc.gridx = 0;
|
|
||||||
gbc.weightx = 0;
|
|
||||||
gbc.fill = GridBagConstraints.NONE;
|
|
||||||
navigationPanel.add(prevPageButton, gbc);
|
|
||||||
|
|
||||||
gbc.gridx++;
|
|
||||||
gbc.weightx = 1;
|
|
||||||
navigationPanel.add(new JLabel(), gbc);
|
|
||||||
|
|
||||||
gbc.gridx++;
|
|
||||||
gbc.weightx = 0;
|
|
||||||
navigationPanel.add(nextPageButton, gbc);
|
|
||||||
|
|
||||||
gbc = new GridBagConstraints();
|
|
||||||
gbc.anchor = GridBagConstraints.NORTHWEST;
|
|
||||||
gbc.insets = new Insets(2, 2, 2, 2);
|
|
||||||
gbc.gridx = 0;
|
|
||||||
gbc.gridy = location * 6;
|
|
||||||
gbc.fill = GridBagConstraints.BOTH;
|
|
||||||
gbc.weighty = 100;
|
|
||||||
gbc.gridwidth = 3;
|
|
||||||
getResultsPanel().add(navigationPanel, gbc);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return nextPageButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPageNumber(int pageNumber) {
|
||||||
|
this.pageNumber = pageNumber;
|
||||||
|
getPageLabel().setText("Page " + pageNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JLabel getPageLabel() {
|
||||||
|
if (pageLabel == null) {
|
||||||
|
pageLabel = new JLabel();
|
||||||
|
pageLabel.setFont(pageLabel.getFont().deriveFont(12f));
|
||||||
|
pageLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
}
|
||||||
|
return pageLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
// private void addNavigationPanel(int location) {
|
||||||
|
// GridBagConstraints gbc = new GridBagConstraints();
|
||||||
|
// gbc.anchor = GridBagConstraints.NORTHWEST;
|
||||||
|
// gbc.insets = new Insets(2, 2, 2, 2);
|
||||||
|
// gbc.gridx = 0;
|
||||||
|
// gbc.gridy = location * 6;
|
||||||
|
// gbc.fill = GridBagConstraints.BOTH;
|
||||||
|
// gbc.weighty = 100;
|
||||||
|
// gbc.gridwidth = 3;
|
||||||
|
// getResultsPanel().add(getNavigationPanel(), gbc);
|
||||||
|
// }
|
||||||
|
|
||||||
public <T extends Object> void executeBackgroundTask(final ITask<T> task) {
|
public <T extends Object> void executeBackgroundTask(final ITask<T> task) {
|
||||||
getGlassPane().setVisible(true);
|
getGlassPane().setVisible(true);
|
||||||
@@ -513,16 +567,14 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void done() {
|
protected void done() {
|
||||||
|
getGlassPane().setVisible(false);
|
||||||
try {
|
try {
|
||||||
T result = get();
|
T result = get();
|
||||||
task.complete(result);
|
task.complete(result);
|
||||||
getGlassPane().setVisible(false);
|
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
LOG.error("Background task execution failed", e);
|
LOG.error("Background task execution failed", e);
|
||||||
getGlassPane().setVisible(false);
|
|
||||||
task.failed(e);
|
task.failed(e);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
getGlassPane().setVisible(false);
|
|
||||||
LOG.error("Background task execution interrupted", e);
|
LOG.error("Background task execution interrupted", e);
|
||||||
task.failed(e);
|
task.failed(e);
|
||||||
}
|
}
|
||||||
@@ -539,13 +591,19 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
return JOptionPane.showConfirmDialog(this, message, title, optionType, messageType);
|
return JOptionPane.showConfirmDialog(this, message, title, optionType, messageType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Icon downloadImage(String imageUrl) {
|
private Icon downloadImage(String imageFile) {
|
||||||
Image image = null;
|
// Image image = null;
|
||||||
|
// try {
|
||||||
|
// URL url = new URL(imageUrl);
|
||||||
|
// image = ImageIO.read(url);
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// }
|
||||||
|
// return image == null ? IconLoader.MissingImage.getIcon() : new ImageIcon(image);
|
||||||
try {
|
try {
|
||||||
URL url = new URL(imageUrl);
|
BufferedImage img = ImageIO.read(new File(imageFile));
|
||||||
image = ImageIO.read(url);
|
return new ImageIcon(img);
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
|
return IconLoader.MissingImage.getIcon();
|
||||||
}
|
}
|
||||||
return new ImageIcon(image);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package org.diylc.swing.plugins.cloud.view;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Cursor;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.KeyListener;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.Timer;
|
||||||
|
|
||||||
|
import org.diylc.images.IconLoader;
|
||||||
|
|
||||||
|
public class CloudGlassPane extends JPanel implements MouseListener, KeyListener {
|
||||||
|
|
||||||
|
public static final CloudGlassPane GLASS_PANE = new CloudGlassPane();
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -5344758920442881290L;
|
||||||
|
|
||||||
|
private long startTime;
|
||||||
|
private final int msPerPx = 5;
|
||||||
|
|
||||||
|
private Timer animationTimer;
|
||||||
|
|
||||||
|
public CloudGlassPane() {
|
||||||
|
addKeyListener(this);
|
||||||
|
addMouseListener(this);
|
||||||
|
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||||
|
setOpaque(false);
|
||||||
|
setBackground(new Color(192, 222, 237));
|
||||||
|
|
||||||
|
animationTimer = new Timer(20, new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVisible(boolean aFlag) {
|
||||||
|
if (aFlag) {
|
||||||
|
startTime = System.currentTimeMillis();
|
||||||
|
animationTimer.start();
|
||||||
|
} else
|
||||||
|
animationTimer.stop();
|
||||||
|
super.setVisible(aFlag);
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(java.awt.Graphics g) {
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
// g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
|
||||||
|
|
||||||
|
Image cloud = IconLoader.CloudBg.getImage();
|
||||||
|
|
||||||
|
g2d.setColor(new Color(192, 222, 237));
|
||||||
|
g2d.fillRect(0, cloud.getHeight(null), getWidth(), getHeight());
|
||||||
|
|
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
|
long ellapsed = System.currentTimeMillis() - startTime;
|
||||||
|
long dx = (ellapsed / msPerPx) % cloud.getWidth(null);
|
||||||
|
g2d.drawImage(cloud, -(int) dx, 0, null);
|
||||||
|
if (cloud.getWidth(null) - dx < getWidth()) {
|
||||||
|
g2d.drawImage(cloud, (int) (cloud.getWidth(null) - dx), 0, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
g2d.setColor(Color.white);
|
||||||
|
g2d.setFont(g2d.getFont().deriveFont(22f));
|
||||||
|
String text = "Querying the cloud, please hold on...";
|
||||||
|
FontMetrics metrics = g.getFontMetrics(g2d.getFont());
|
||||||
|
Rectangle rect = new Rectangle(getSize());
|
||||||
|
int x = (rect.width - metrics.stringWidth(text)) / 2;
|
||||||
|
int y = ((rect.height - metrics.getHeight()) / 2) + metrics.getAscent();
|
||||||
|
g.drawString(text, x, y);
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(final MouseEvent pArg0) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(final MouseEvent pArg0) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(final MouseEvent pArg0) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(final MouseEvent pArg0) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(final MouseEvent pArg0) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e) {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user