/* 
 * Created on 2004/10/08 
 * Author aki@www.xucker.jpn.org 
 * License Apache2.0 or Common Public License 
 */ 
package org.jpn.xucker.dualsubmit; 
 
import org.eclipse.swt.SWT; 
import org.eclipse.swt.events.KeyEvent; 
import org.eclipse.swt.events.KeyListener; 
import org.eclipse.swt.events.SelectionEvent; 
import org.eclipse.swt.events.SelectionListener; 
import org.eclipse.swt.graphics.Color; 
import org.eclipse.swt.graphics.Image; 
import org.eclipse.swt.widgets.Button; 
import org.eclipse.swt.widgets.Composite; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Label; 
import org.eclipse.swt.widgets.Shell; 
import org.eclipse.swt.widgets.Text; 
 
/** 
 *  
 * 
 */ 
public class DualSubmitMenuImp implements DualSubmitMenu,KeyListener ,SelectionListener{ 
private DualSubmitBrowser browser; 
private boolean visible=true; 
private Text wordText; 
private Text urlText; 
private Button arrowLeft; 
private Button arrowRight; 
private Button moveUp; 
private Button moveDown; 
private Button moveLeft; 
private Button moveRight; 
    public DualSubmitMenuImp(Shell shell){ 
        Composite composite=new Composite(shell,SWT.NULL); 
        composite.setBounds(0,0,800,DualSubmit.MENU_HEIGHT); 
        composite.setBackground(new Color(null,0x00,0x66,0x33)); 
       // composite.setLayout(new RowLayout()); 
        wordText = new Text(composite,SWT.SINGLE|SWT.BORDER); 
        wordText.setBounds(10,10,100,16); 
        wordText.addKeyListener(this); 
         
        urlText=new Text(composite,SWT.SINGLE|SWT.READ_ONLY); 
        urlText.setBackground(new Color(null,240,240,240)); 
        urlText.setBounds(10+100+10,10,400,16); 
         
        arrowLeft = new Button(composite,SWT.BORDER); 
        arrowLeft.setImage(toImage(shell.getDisplay(),"left_arrow.png")); 
        arrowLeft.setBounds(10+10+100+10+400,8,20,20); 
        arrowLeft.addSelectionListener(this); 
         
        arrowRight = new Button(composite,SWT.BORDER); 
        arrowRight.setImage(toImage(shell.getDisplay(),"right_arrow.png")); 
        arrowRight.setBounds(10+10+100+10+400+20+5,8,20,20); 
        arrowRight.addSelectionListener(this); 
         
        moveUp = new Button(composite,SWT.BORDER); 
        moveUp.setImage(toImage(shell.getDisplay(),"up_move.png")); 
        moveUp.setBounds(10+10+100+10+400+40+10,8,20,20); 
        moveUp.addSelectionListener(this); 
         
        moveDown = new Button(composite,SWT.BORDER); 
        moveDown.setImage(toImage(shell.getDisplay(),"down_move.png")); 
        moveDown.setBounds(10+10+100+10+400+60+15,8,20,20); 
        moveDown.addSelectionListener(this); 
         
        moveLeft = new Button(composite,SWT.BORDER); 
        moveLeft.setImage(toImage(shell.getDisplay(),"left_move.png")); 
        moveLeft.setBounds(10+10+100+10+400+80+20,8,20,20); 
        moveLeft.addSelectionListener(this); 
         
        moveRight = new Button(composite,SWT.BORDER); 
        moveRight.setImage(toImage(shell.getDisplay(),"right_move.png")); 
        moveRight.setBounds(10+10+100+10+400+100+25,8,20,20); 
        moveRight.addSelectionListener(this); 
         
        Label markLabel =new Label(composite,SWT.NULL); 
        markLabel.setImage(toImage(shell.getDisplay(),"mark.png")); 
        markLabel.setBounds(10+10+100+10+400+120+30,8,20,20); 
        //wordText.add 
    } 
    /** 
     * @param string 
     * @return 
     */ 
    private Image toImage(Display display,String string) { 
       return new Image(display,this.getClass().getResourceAsStream("/org/jpn/xucker/dualsubmit/resource/"+string)); 
       
    } 
    /* (non-Javadoc) 
     * @see org.jpn.xucker.dualsubmit.DualSubmitMenu#setBrowser(org.jpn.xucker.dualsubmit.DualSubmitBrowser) 
     */ 
    public void setBrowser(DualSubmitBrowser browser) { 
        // TODO Auto-generated method stub 
        this.browser=browser; 
        buttonUpdate(); 
    } 
 
    /* (non-Javadoc) 
     * @see org.jpn.xucker.dualsubmit.DualSubmitMenu#setPlugins(org.jpn.xucker.dualsubmit.DualSubmitPlugin[]) 
     */ 
    public void setPlugins(DualSubmitPlugin[] plugins) { 
        // TODO Auto-generated method stub 
 
    } 
 
    /* (non-Javadoc) 
     * @see org.jpn.xucker.dualsubmit.DualSubmitMenu#getCurrentPlugin() 
     */ 
    public DualSubmitPlugin getCurrentPlugin() { 
        // TODO Auto-generated method stub 
        return null; 
    } 
 
    /* (non-Javadoc) 
     * @see org.jpn.xucker.dualsubmit.DualSubmitMenu#submit(java.lang.String) 
     */ 
    public void sendText(String word) { 
        // TODO Auto-generated method stub 
        //valid check. 
        doSubmit(word); 
    } 
 
    /* (non-Javadoc) 
     * @see org.jpn.xucker.dualsubmit.DualSubmitMenu#isVisible() 
     */ 
    public boolean isVisible() { 
        return visible; 
    } 
 
    /* (non-Javadoc) 
     * @see org.jpn.xucker.dualsubmit.DualSubmitMenu#setVisible(boolean) 
     */ 
    public void setVisible(boolean bool) { 
        visible=bool; 
    } 
 
    public static void main(String[] args) { 
    } 
    /* (non-Javadoc) 
     * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent) 
     */ 
    public void keyPressed(KeyEvent e) { 
        // TODO Auto-generated method stub 
         
    } 
    /* (non-Javadoc) 
     * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent) 
     */ 
    public void keyReleased(KeyEvent e) { 
        // TODO Auto-generated method stub 
        if(e.keyCode=='\r'){ 
            doSubmit(wordText.getText()); 
        } 
    } 
    /** 
     * @param text 
     */ 
    private void doSubmit(String text) { 
        //plugin-parse. 
        String url="http://dictionary.goo.ne.jp/search.php?MT="+text; 
        urlText.setText(url); 
        browser.submit(url); //test 
    } 
    /* (non-Javadoc) 
     * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) 
     */ 
    public void widgetSelected(SelectionEvent e) { 
        if(e.getSource()==arrowLeft){ 
            browser.prev(); 
            buttonUpdate(); 
        }else if(e.getSource()==arrowRight){ 
            browser.next(); 
            buttonUpdate(); 
        }else if(e.getSource()==moveUp){ 
            browser.doUp(); 
            buttonUpdate(); 
        }else if(e.getSource()==moveDown){ 
            browser.doDown(); 
            buttonUpdate(); 
        }else if(e.getSource()==moveLeft){ 
            browser.doLeft(); 
            buttonUpdate(); 
        }else if(e.getSource()==moveRight){ 
            browser.doRight(); 
            buttonUpdate(); 
        } 
    } 
     
    public void update(){ 
        buttonUpdate(); 
        if(browser.getCurrentUrl()!=null){ 
            urlText.setText(browser.getCurrentUrl()); 
        } 
    } 
     
    private void buttonUpdate(){ 
         
        arrowLeft.setEnabled(browser.canPrev()); 
        arrowRight.setEnabled(browser.canNext()); 
        moveUp.setEnabled(browser.canUp()); 
        moveRight.setEnabled(browser.canRight()); 
         
    } 
    
    /* (non-Javadoc) 
     * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) 
     */ 
    public void widgetDefaultSelected(SelectionEvent e) { 
        // TODO Auto-generated method stub 
         
    } 
}
    
    |