001 package org.springframework.richclient.samples.dataeditor.ui; 002 003 import java.awt.Color; 004 import java.awt.Component; 005 import java.awt.Dimension; 006 import java.awt.geom.Ellipse2D; 007 import java.awt.geom.RoundRectangle2D; 008 import java.io.IOException; 009 010 import javax.imageio.ImageIO; 011 import javax.swing.BorderFactory; 012 import javax.swing.JFrame; 013 import javax.swing.JProgressBar; 014 import javax.swing.SwingUtilities; 015 import javax.swing.UIManager; 016 017 import org.jdesktop.swingx.JXBusyLabel; 018 import org.jdesktop.swingx.JXFrame; 019 import org.jdesktop.swingx.JXImagePanel; 020 import org.jdesktop.swingx.JXLabel; 021 import org.jdesktop.swingx.JXPanel; 022 import org.jdesktop.swingx.JXRootPane; 023 import org.jdesktop.swingx.icon.EmptyIcon; 024 import org.jdesktop.swingx.painter.BusyPainter; 025 import org.springframework.core.io.Resource; 026 import org.springframework.richclient.application.splash.MonitoringSplashScreen; 027 import org.springframework.richclient.progress.ProgressMonitor; 028 import org.springframework.richclient.util.WindowUtils; 029 030 import com.jgoodies.forms.layout.CellConstraints; 031 import com.jgoodies.forms.layout.FormLayout; 032 033 public class DataEditorSplash implements MonitoringSplashScreen 034 { 035 private JXBusyLabel busyLabel = new JXBusyLabel(new Dimension(180,180)); 036 private JXLabel titleLabel = new JXLabel("Data Editor"); 037 private JProgressBar progressBar = new JProgressBar(); 038 private JXLabel progressLabel = new JXLabel(); 039 private JXFrame frame; 040 041 private Resource image; 042 043 public DataEditorSplash() 044 { 045 BusyPainter painter = new BusyPainter( 046 new RoundRectangle2D.Float(0, 0,28.0f,8.6f,10.0f,10.0f), 047 new Ellipse2D.Float(15.0f,15.0f,70.0f,70.0f)); 048 painter.setTrailLength(4); 049 painter.setPoints(8); 050 painter.setFrame(7); 051 painter.setHighlightColor(new Color(30,42,102)); 052 busyLabel.setPreferredSize(new Dimension(100,100)); 053 busyLabel.setIcon(new EmptyIcon(100,100)); 054 busyLabel.setBusyPainter(painter); 055 busyLabel.setDelay(75); 056 057 titleLabel.setFont(titleLabel.getFont().deriveFont(30f)); 058 titleLabel.setForeground(Color.BLACK); 059 progressBar.setStringPainted(true); 060 progressBar.setPreferredSize(new Dimension(170,20)); 061 // titleLabel.setBackground(new Color(0x425DA9)); 062 // titleLabel.setOpaque(false); 063 // progressLabel.setBackground(new Color(0x425DA9)); 064 } 065 066 public ProgressMonitor getProgressMonitor() 067 { 068 return new ProgressMonitor() 069 { 070 private int currentWork = 0; 071 072 public void taskStarted(String name, int totalWork) 073 { 074 progressBar.setMaximum(totalWork); 075 progressBar.setValue(0); 076 this.currentWork = 0; 077 busyLabel.setBusy(true); 078 progressBar.setString(name); 079 } 080 081 public void subTaskStarted(String name) 082 { 083 progressBar.setString(name); 084 } 085 086 public void worked(int work) 087 { 088 currentWork += work; 089 progressBar.setValue(currentWork); 090 } 091 092 public void done() 093 { 094 busyLabel.setBusy(false); 095 } 096 097 public boolean isCanceled() 098 { 099 return false; 100 } 101 102 public void setCanceled(boolean b) 103 { 104 } 105 }; 106 } 107 108 protected Component createContentPane() 109 { 110 JXPanel panel = new JXPanel(new FormLayout("center:200px:nogrow, left:3dlu:nogrow, fill:200px:nogrow", "center:200px:nogrow, center:20px:nogrow")); 111 JXImagePanel ip = new JXImagePanel(); 112 try 113 { 114 ip.setImage(ImageIO.read(image.getInputStream())); 115 } 116 catch (IOException e) 117 { 118 e.printStackTrace(); 119 } 120 ip.setStyle(JXImagePanel.Style.SCALED); 121 //panel.setBackground(new Color(0x425DA9)); 122 panel.add(busyLabel, new CellConstraints(1,1)); 123 JXPanel panel2 = new JXPanel(new FormLayout("center:195px:nogrow", "center:98px:nogrow, center:4dlu:nogrow, center:98px:nogrow")); 124 //panel2.setBackground(new Color(0x425DA9)); 125 panel2.add(titleLabel, new CellConstraints(1, 1)); 126 panel2.setOpaque(false); 127 panel.add(progressBar, new CellConstraints(1, 2, 3, 1)); 128 panel.add(panel2, new CellConstraints(3,1)); 129 panel.add(ip, new CellConstraints(1, 1, 3, 1, CellConstraints.FILL, CellConstraints.FILL)); 130 panel.setBorder(BorderFactory.createLineBorder(Color.black, 4)); 131 return panel; 132 } 133 134 public void splash() 135 { 136 frame = new JXFrame(); 137 frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 138 frame.setUndecorated(true); 139 frame.setRootPane(new JXRootPane()); 140 frame.getRootPaneExt().setDoubleBuffered(true); 141 frame.getRootPaneExt().setBackground(new Color(255,255,255,255)); 142 frame.getRootPaneExt().setOpaque(false); 143 frame.getContentPane().add(createContentPane()); 144 frame.pack(); 145 WindowUtils.centerOnScreen(frame); 146 try 147 { 148 UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); 149 } 150 catch (Exception e) 151 { 152 e.printStackTrace(); 153 } 154 SwingUtilities.updateComponentTreeUI(frame); 155 frame.setVisible(true); 156 } 157 158 public void dispose() 159 { 160 if (frame != null) { 161 frame.dispose(); 162 frame = null; 163 } 164 } 165 166 public void setImage(Resource image) 167 { 168 this.image = image; 169 } 170 }