2 * Web-browser invoke button
4 * License : The MIT License
5 * Copyright(c) 2009 olyutorskii
8 package jp.sfjp.jindolf.dxchg;
10 import java.awt.Frame;
11 import java.awt.GridBagConstraints;
12 import java.awt.GridBagLayout;
13 import java.awt.Insets;
14 import java.awt.event.ActionEvent;
15 import java.awt.event.ActionListener;
16 import java.net.MalformedURLException;
19 import javax.swing.BorderFactory;
20 import javax.swing.JButton;
21 import javax.swing.JLabel;
22 import javax.swing.JPanel;
23 import javax.swing.SwingUtilities;
24 import jp.sfjp.jindolf.util.GUIUtils;
25 import jp.sfjp.jindolf.util.Monodizer;
30 @SuppressWarnings("serial")
31 public class WebButton extends JPanel implements ActionListener{
33 private static final String ACTION_SHOWWEB = "SHOWWEB";
35 private final JLabel caption;
36 private final JButton button;
37 private String webUrlText;
45 this.caption = new JLabel();
46 this.button = new JButton("Web");
48 Monodizer.monodize(this.caption);
49 this.button.setIcon(GUIUtils.getWWWIcon());
50 this.button.setMargin(new Insets(1, 1, 1, 1));
51 this.button.setActionCommand(ACTION_SHOWWEB);
52 this.button.addActionListener(this);
53 this.button.setToolTipText("Webブラウザで表示");
63 private void design(){
64 setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
66 GridBagLayout layout = new GridBagLayout();
69 GridBagConstraints constraints = new GridBagConstraints();
70 constraints.fill = GridBagConstraints.NONE;
71 constraints.gridwidth = GridBagConstraints.RELATIVE;
72 constraints.insets = new Insets(0, 0, 0, 10);
74 add(this.caption, constraints);
75 add(this.button, constraints);
82 * @param b {@inheritDoc}
85 public void setEnabled(boolean b){
87 this.button.setEnabled(b);
94 * @param seq キャプション文字列
96 public void setCaption(CharSequence seq){
97 this.caption.setText(seq.toString());
102 * Webブラウザに表示させるURLを設定する。
106 public void setURL(URL url){
107 setURLText(url.toString());
112 * Webブラウザに表示させるURIを設定する。
116 public void setURI(URI uri){
117 setURLText(uri.toString());
122 * Webブラウザに表示させるURL文字列を設定する。
124 * @param urlText URL文字列
126 public void setURLText(CharSequence urlText){
127 String str = urlText.toString();
132 }catch(MalformedURLException e){
136 this.webUrlText = str;
137 setCaption(this.webUrlText);
145 public void showDialog(){
147 (Frame) SwingUtilities.getAncestorOfClass(Frame.class, this);
148 WebIPCDialog.showDialog(frame, this.webUrlText);
156 public void actionPerformed(ActionEvent event){
157 if(event.getSource() != this.button) return;
159 String command = event.getActionCommand();
160 if(command.equals(ACTION_SHOWWEB)){