package org.jpn.xucker.dualsubmit;
import java.io.File;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
import org.jpn.xucker.commons.util.ApplicationUtil;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.Parameter;
import org.picocontainer.defaults.ConstantParameter;
import org.picocontainer.defaults.DefaultPicoContainer;
public class DualSubmit implements ClipboardTextListener
{
/**
* @param shell
*/
Shell shell;
public final static int MENU_HEIGHT = 50;
MutablePicoContainer container;
private DualSubmitBrowser browser;
private DualSubmitMenu menu;
private DualSubmitPluginLoader loader;
private Composite composite;
private ClipboardTextMonitor monitor;
private LoopControler loopControler;
private DefaultApplication defaultApplication;
public void setFullDualMonitorSize() {
Monitor monitors[] = shell.getDisplay().getMonitors();
for (int i = 0; i < monitors.length; i++) {
if (i == 0) {
//if(i==monitors.length-1){
shell.setBounds(monitors[i].getBounds());
}
}
}
public DualSubmit(Shell shell) {
this.shell = shell;
}
public void init() {
shell.setImage(new Image(shell.getDisplay(),this.getClass().getResourceAsStream("/org/jpn/xucker/dualsubmit/resource/"+"icon.png")));
setFullDualMonitorSize();
container = loadContainer();
menu = (DualSubmitMenu) container
.getComponentInstanceOfType(DualSubmitMenu.class);
browser = (DualSubmitBrowser) container
.getComponentInstanceOfType(DualSubmitBrowser.class);
browser.setMenu(menu);
loader = (DualSubmitPluginLoader) container
.getComponentInstanceOfType(DualSubmitPluginLoader.class);
menu.setBrowser(browser);
menu.setPlugins(loader.loadPlugins());
//start clipboard monitor
shell.addShellListener((ShellListener)container
.getComponentInstanceOfType(ShellListener.class));
monitor = (ClipboardTextMonitor) container
.getComponentInstanceOfType(ClipboardTextMonitor.class);
monitor.addClipboardTextListener(this);
defaultApplication=new DefaultApplication(shell);
defaultApplication.setApplicationName("Dual専用 Clipboardサブミッター");
defaultApplication.setHomePageUrl("http://www.xucker.jpn.org/");
defaultApplication.setVersion(0.1);
defaultApplication.setExeName("dualsubmit.exe");
loopControler=(LoopControler)container
.getComponentInstanceOfType(LoopControler.class);
loopControler.addThread(new ClipMonitorCaller());
loopControler.start();
}
public MutablePicoContainer loadContainer() {
MutablePicoContainer container = new DefaultPicoContainer();
File pluginDir = new File(ApplicationUtil.searchFileAroundClass(
"build.xml").getParent(), "dualsubmit/plugin");
container.registerComponentInstance(pluginDir);
container.registerComponentInstance(shell);
container.registerComponentImplementation(DualSubmitBrowserImp.class);
container.registerComponentImplementation(DualSubmitMenuImp.class);
container
.registerComponentImplementation(DualSubmitPluginLoaderImp.class);
container
.registerComponentImplementation(ClipboardTextMonitorImp.class);
container.registerComponentImplementation(LoopControler.class);
container.registerComponentImplementation(SimpleWindowCloser.class);
return container;
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display, SWT.CLOSE | SWT.MIN | SWT.RESIZE
| SWT.MAX);
try {
DualSubmit main = new DualSubmit(shell);
main.init();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (!shell.isDisposed()) {
shell.close();
}
display.dispose();
//System.exit(0);
}
}
/*
* (non-Javadoc)
*
* @see org.jpn.xucker.dualsubmit.ClipboardTextListener#clipboardChanged(java.lang.String)
*/
public void clipboardChanged(String text) {
menu.sendText(text);
}
public class ClipMonitorCaller extends Thread {
public void run() {
if (!shell.isDisposed()) {
monitor.monitor();
}
}
}
}
|