package com.suwish.pc.ui;
import static com.suwish.pc.util.ResourceUtils._Icon;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.plaf.ToolBarUI;
import com.android.ddmlib.IDevice;
import com.suwish.pc.phone.PhoneManager;
import com.suwish.pc.ui.dialog.DdmsDeviceSelectDialog;
import com.suwish.pc.ui.dialog.ShellDialog;
import com.suwish.pc.ui.main.MainFrame;
import com.suwish.pc.ui.util.UIHelper;
/**
*
* @author Min
*
*/
public class MainFrameToolBar extends JToolBar {
/**
*
*/
private static final long serialVersionUID = 1L;
// private static final String uiClassID = "ToolBarUI";
private JButton connectButton = null;
private JButton shellButton = null;
private JButton preferenceButton = null;
private JButton supportButton = null;
private JButton exitButton = null;
private MainFrame mainFrame = null;
public MainFrameToolBar(MainFrame mainFrame){
this.mainFrame = mainFrame;
initUI();
initEvent();
}
private void initEvent(){
connectButton.addActionListener(new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
DdmsDeviceSelectDialog dialog = new DdmsDeviceSelectDialog(mainFrame);
dialog.setVisible(true);
IDevice device = dialog.getSelectedDevice();
if(device == null)return;
mainFrame.addTabCard(device);
}
});
preferenceButton.addActionListener(new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
PhoneManager.getInstance().getPerferenceManager().showDialog();
}
});
supportButton.addActionListener(new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
UIHelper.openSupportWebsite();
}
});
exitButton.addActionListener(new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
PhoneManager.getInstance().exitSystem();
}
});
}
private void initUI(){
connectButton = new JButton( _Icon("gtk-new_32x32.png"));
connectButton.setToolTipText("Connect to device");
add(connectButton);
addSeparator();
shellButton = new JButton(_Icon("Gnome-Utilities-Terminal_32x32.png"));
shellButton.setToolTipText("Shell");
shellButton.addActionListener(new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
new ShellDialog(mainFrame, "Shell - command line").setVisible(true);
}
});
add(shellButton);
preferenceButton = new JButton(_Icon("Gnome-Preferences-System_32x32.png"));
preferenceButton.setToolTipText("Preferences");
add(preferenceButton);
addSeparator();
supportButton = new JButton(_Icon("Gnome-Web-Browser_32x32.png"));
supportButton.setToolTipText("Support online");
add(supportButton);
exitButton = new JButton(_Icon("Gnome-Application-Exi_32x32.png"));
exitButton.setToolTipText("Exit");
add(exitButton);
}
}