1 30 31 package it.businesslogic.ireport.rmi; 32 36 import it.businesslogic.ireport.Report; 37 import it.businesslogic.ireport.gui.JReportFrame; 38 import it.businesslogic.ireport.gui.MainFrame; 39 import it.businesslogic.ireport.gui.WizardDialog; 40 import it.businesslogic.ireport.util.PageSize; 41 import java.io.File ; 42 import java.rmi.*; 43 import java.rmi.server.*; 44 import java.rmi.registry.*; 45 import javax.swing.JOptionPane ; 46 import javax.swing.SwingUtilities ; 47 48 public class IReportServerImpl extends UnicastRemoteObject 49 implements IReportServer, Runnable 50 { 51 static IReportServerImpl mainInstance = null; 52 53 public static IReportServerImpl getMainInstance() 54 { 55 if (mainInstance == null) 56 { 57 try { 58 mainInstance = new IReportServerImpl(); 59 } catch (Exception ex) 60 { 61 ex.printStackTrace(); 62 } 63 } 64 65 return mainInstance; 66 } 67 68 IReportServerImpl() throws RemoteException 69 { 70 super(); 71 } 72 73 74 75 public static void runServer() 76 { 77 System.setSecurityManager(new RMISecurityManager()); 80 Thread t = new Thread ( IReportServerImpl.getMainInstance() ); 81 t.start(); 82 } 84 85 public void run() 86 { 87 try 89 { 90 int port = 2100; 91 try { 92 port = Integer.parseInt( MainFrame.getMainInstance().getProperties().getProperty( "RMIServerPort" ,"2100")); 93 } 94 catch (Exception ex) 95 { 96 ex.printStackTrace(); 97 } 98 Registry reg =LocateRegistry.createRegistry( port ); 99 100 reg.bind("iReportServer" , this); 103 System.out.println("RMI iReportServer waiting on port " + port + "....."); 104 } 105 catch (java.rmi.AlreadyBoundException abe) 106 { 107 System.out.println("Service already bound! Is another iReport instance running?"); 108 } 109 catch (RemoteException re) 110 { 111 System.out.println("Remote exception: " + re.toString()); 112 } 113 114 } 115 116 118 121 public boolean ping() 122 { 123 return true; 124 } 125 126 129 public boolean setVisible(boolean b) 130 { 131 MainFrame.getMainInstance().setVisible(b); 132 if (MainFrame.getMainInstance().getState() == java.awt.Frame.ICONIFIED) 133 { 134 MainFrame.getMainInstance().setState( java.awt.Frame.NORMAL ); 135 } 136 return MainFrame.getMainInstance().requestFocusInWindow(); 137 } 138 139 142 public boolean openFile(String file) 143 { 144 setVisible(true); 145 try { 146 JReportFrame jrf = MainFrame.getMainInstance().openFile( file ); 147 jrf.setSelected(true); 148 return true; 149 } catch (Exception ex){ 150 return false; 151 } 152 } 153 154 155 public boolean runWizard(String destFile) 156 { 157 MainFrame mainFrame = MainFrame.getMainInstance(); 158 159 if (mainFrame == null) return false; 160 161 162 163 mainFrame.logOnConsole("Invocato wizard"); 164 mainFrame.logOnConsole("Pronto ad invocare la nuova finestra..." + Thread.currentThread().getName()); 165 166 167 try { 168 171 WizardDialog wd = new WizardDialog(mainFrame,true); 172 173 mainFrame.logOnConsole("Lancio wizard"); 174 wd.setVisible(true); 175 wd.requestFocus(); 176 177 178 Report report = null; 179 if (wd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { 180 report = wd.getReport(); 181 if (report == null) 182 { 183 report = createBlankReport(); 184 } 185 } 186 else 187 { 188 report = createBlankReport(); 189 } 190 191 if (report != null) 192 { 193 mainFrame.openNewReportWindow(report); 194 report.setFilename(destFile); 195 report.saveXMLFile(); 196 setVisible(true); 197 } 198 199 } catch (Exception ex) 200 { 201 System.out.println(ex.getMessage()); 202 ex.printStackTrace(); 203 } 204 205 206 return true; 207 } 208 209 private Report createBlankReport() 210 { 211 Report newReport = new Report(); 212 213 newReport.setName(it.businesslogic.ireport.util.I18n.getString("untitledReport", "untitled_report_")+"1"); 214 newReport.setUsingMultiLineExpressions(false); newReport.setWidth( PageSize.A4.x); 216 newReport.setHeight( PageSize.A4.y); 217 newReport.setTopMargin(20); 218 newReport.setLeftMargin(30); 219 newReport.setRightMargin(30); 220 newReport.setBottomMargin(20); 221 newReport.setColumnCount(1); 222 newReport.setColumnWidth( newReport.getWidth() - newReport.getLeftMargin() - newReport.getRightMargin() ); 223 newReport.setColumnSpacing(0); 224 225 return newReport; 226 } 227 228 229 } 230 231 232 233 | Popular Tags |