/*
* Created on 2004/10/08
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package org.jpn.xucker.dualsubmit;
import java.util.List;
import java.util.Vector;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.widgets.Shell;
/**
*
*
*/
public class DualSubmitBrowserImp implements DualSubmitBrowser,ControlListener {
private DualSubmitMenu menu;
private Browser browser;
private Shell shell;
private int moveSize=10;
private int slideHeight=0;
private int slideWidth=0;
private List historyList=new Vector();
private int historyIndex=-1;
private String currentUrl;
public DualSubmitBrowserImp(Shell shell){
this.shell=shell;
shell.addControlListener(this);
browser = new Browser(shell,SWT.NONE);
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#submit(java.lang.String)
*/
public void submit(String url) {
historyList.add(url);
moveHistoryLast();
// TODO Auto-generated method stub
setUrl(url);
//System.out.println(historyList.size());
}
private void setUrl(String url){
browser.setUrl(url);
currentUrl=url;
menu.update();
}
/**
*
*/
private void moveHistoryLast() {
historyIndex=historyList.size()-1;
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#getCurrentUrl()
*/
public String getCurrentUrl() {
// TODO Auto-generated method stub
return currentUrl;
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#canPrev()
*/
public boolean canPrev() {
return historyList.size()>0 && historyIndex>0;
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#canNext()
*/
public boolean canNext() {
return historyList.size()>0 && historyIndex!=historyList.size()-1;
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#next()
*/
public void next() {
if(canNext()){
historyIndex++;
String url=(String)historyList.get(historyIndex);
setUrl(url);
}
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#prev()
*/
public void prev() {
if(canPrev()){
historyIndex--;
String url=(String)historyList.get(historyIndex);
setUrl(url);
}
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent)
*/
public void controlMoved(ControlEvent e) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.ControlListener#controlResized(org.eclipse.swt.events.ControlEvent)
*/
public void controlResized(ControlEvent e) {
update();
}
public void update(){
int height=0;
if(menu!=null && menu.isVisible()){
height=DualSubmit.MENU_HEIGHT;
}
browser.setBounds(0-slideWidth,height-slideHeight,shell.getClientArea().width+slideWidth,shell.getClientArea().height-height+slideHeight);
System.out.println(browser.getClientArea()+","+height);
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#setMenu(org.jpn.xucker.dualsubmit.DualSubmitMenu)
*/
public void setMenu(DualSubmitMenu menu) {
this.menu=menu;
update();
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#canUp()
*/
public boolean canUp() {
return slideHeight>0;
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#doUp()
*/
public void doUp() {
if(canUp()){
slideHeight-=moveSize;
update();
}
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#doDown()
*/
public void doDown() {
slideHeight+=moveSize;
update();
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#doLeft()
*/
public void doLeft() {
// TODO Auto-generated method stub
slideWidth+=moveSize;
update();
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#doRight()
*/
public void doRight() {
// TODO Auto-generated method stub
if(canRight()){
slideWidth-=moveSize;
update();
}
}
/* (non-Javadoc)
* @see org.jpn.xucker.dualsubmit.DualSubmitBrowser#canLeft()
*/
public boolean canRight() {
return slideWidth>0;
}
}
|