EPSDialog.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00010 package com.generalrobotix.ui.view.graph;
00011 
00012 import java.awt.*;
00013 import java.awt.event.*;
00014 import javax.swing.*;
00015 
00016 import com.generalrobotix.ui.util.MessageBundle;
00017 
00024 public class EPSDialog extends JDialog {
00025 
00026     // -----------------------------------------------------------------
00027     // 定数
00028     // 配置
00029     private static final int BORDER_GAP = 12;
00030     private static final int LABEL_GAP = 12;
00031     private static final int BUTTON_GAP = 5;
00032     private static final int ITEM_GAP = 11;
00033     private static final int CONTENTS_GAP = 17;
00034 
00035     // -----------------------------------------------------------------
00036     // インスタンス変数
00037     String path_;           // パス
00038     boolean colorOutput_;   // カラー出力フラグ
00039     boolean graphOutput_;   // グラフ出力フラグ
00040     boolean legendOutput_;  // 凡例出力グラフ
00041     boolean updated_;       // 更新フラグ
00042     JTextField pathField_;  // パス入力フィールド
00043     JCheckBox colorCheck_;  // カラーチェックボックス
00044     JCheckBox graphCheck_;  // グラフ出力チェックボックス
00045     JCheckBox legendCheck_; // 凡例出力チェックボックス
00046     JButton okButton_;      // OKボタン
00047     JFileChooser chooser_;  // ファイル選択ダイアログ
00048 
00049     // -----------------------------------------------------------------
00050     // コンストラクタ
00056     public EPSDialog(Frame owner) {
00057         super(owner, MessageBundle.get("dialog.graph.eps.title"), true);
00058 
00059         chooser_ = new JFileChooser(System.getProperty("user.dir"));
00060 
00061         // 1行目(パス)
00062         JLabel outputLabel = new JLabel(MessageBundle.get("dialog.graph.eps.outputto"));
00063         int labelWidth = outputLabel.getMinimumSize().width;
00064         pathField_ = new JTextField("", 20);
00065         pathField_.setPreferredSize(new Dimension(400, 26));
00066         pathField_.setMaximumSize(new Dimension(400, 26));
00067         JButton browseButton = new JButton(MessageBundle.get("dialog.graph.eps.browse"));
00068         browseButton.addActionListener(
00069             new ActionListener() {
00070                 public void actionPerformed(ActionEvent evt) {
00071                     //int result = chooser_.showSaveDialog(EPSDialog.this);
00072                     int result = chooser_.showDialog(EPSDialog.this, MessageBundle.get("dialog.okButton"));
00073                     if (result == JFileChooser.APPROVE_OPTION) {
00074                         pathField_.setText(
00075                             chooser_.getSelectedFile().getPath()
00076                         );
00077                     }
00078                 }
00079             }
00080         );
00081         JPanel line1 = new JPanel();
00082         line1.setLayout(new BoxLayout(line1, BoxLayout.X_AXIS));
00083         line1.add(Box.createHorizontalStrut(BORDER_GAP));
00084         line1.add(outputLabel);
00085         //line1.add(Box.createHorizontalGlue());
00086         line1.add(Box.createHorizontalStrut(LABEL_GAP));
00087         line1.add(pathField_);
00088         line1.add(Box.createHorizontalStrut(5));
00089         line1.add(browseButton);
00090         //line1.add(Box.createHorizontalStrut(7));   // (注)調整箇所
00091         line1.add(Box.createHorizontalStrut(BORDER_GAP));
00092         line1.setAlignmentX(Component.LEFT_ALIGNMENT);
00093 
00094         // チェックボックスリスナ
00095         ItemListener checkListener = new ItemListener() {
00096             public void itemStateChanged(ItemEvent evt) {
00097                 okButton_.setEnabled(
00098                     graphCheck_.isSelected()
00099                     || legendCheck_.isSelected()
00100                 );
00101             }
00102         };
00103 
00104         // 2行目(グラフチェック)
00105         colorCheck_ = new JCheckBox(MessageBundle.get("dialog.graph.eps.color"));
00106         graphCheck_ = new JCheckBox(MessageBundle.get("dialog.graph.eps.graph"));
00107         graphCheck_.addItemListener(checkListener);
00108         legendCheck_ = new JCheckBox(MessageBundle.get("dialog.graph.eps.legend"));
00109         legendCheck_.addItemListener(checkListener);
00110         JPanel line2 = new JPanel();
00111         line2.setLayout(new BoxLayout(line2, BoxLayout.X_AXIS));
00112         line2.add(Box.createHorizontalStrut(BORDER_GAP));
00113         line2.add(Box.createHorizontalStrut(labelWidth));
00114         line2.add(Box.createHorizontalStrut(LABEL_GAP));
00115         line2.add(colorCheck_);
00116         line2.add(Box.createHorizontalStrut(LABEL_GAP));
00117         line2.add(graphCheck_);
00118         line2.add(Box.createHorizontalStrut(ITEM_GAP));
00119         line2.add(legendCheck_);
00120         line2.setAlignmentX(Component.LEFT_ALIGNMENT);
00121 
00122         // ボタン行
00123         okButton_ = new JButton(MessageBundle.get("dialog.okButton"));
00124         this.getRootPane().setDefaultButton(okButton_);
00125         okButton_.addActionListener(
00126             new ActionListener() {
00127                 public void actionPerformed(ActionEvent evt) {
00128                     // パスのチェック
00129                     String path = pathField_.getText().trim();
00130                     // (不正なパスならエラーダイアログ表示)
00131                     // 値更新
00132                     if (!path.equals("") && !path.endsWith(".eps")) {
00133                         path += ".eps";
00134                     }
00135                     path_ = path;
00136                     colorOutput_ = colorCheck_.isSelected();
00137                     graphOutput_ = graphCheck_.isSelected();
00138                     legendOutput_ = legendCheck_.isSelected();
00139                     updated_ = true;
00140                     EPSDialog.this.setVisible(false);
00141                 }
00142             }
00143         );
00144         JButton cancelButton = new JButton(MessageBundle.get("dialog.cancelButton"));
00145         cancelButton.addActionListener(
00146             new ActionListener() {
00147                 public void actionPerformed(ActionEvent evt) {
00148                     EPSDialog.this.setVisible(false);
00149                 }
00150             }
00151         );
00152         this.addKeyListener(
00153             new KeyAdapter() {
00154                 public void keyPressed(KeyEvent evt) {
00155                     if (evt.getID() == KeyEvent.KEY_PRESSED
00156                         && evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
00157                         EPSDialog.this.setVisible(false);
00158                     }
00159                 }
00160             }
00161         );
00162         JPanel bLine = new JPanel();
00163         bLine.setLayout(new BoxLayout(bLine, BoxLayout.X_AXIS));
00164         bLine.add(Box.createHorizontalGlue());
00165         bLine.add(okButton_);
00166         bLine.add(Box.createHorizontalStrut(BUTTON_GAP));
00167         bLine.add(cancelButton);
00168         bLine.add(Box.createHorizontalStrut(BORDER_GAP));
00169         bLine.setAlignmentX(Component.LEFT_ALIGNMENT);
00170 
00171         // パネル構築
00172         Container pane = getContentPane();
00173         pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
00174         pane.add(Box.createVerticalStrut(BORDER_GAP));
00175         pane.add(line1);
00176         pane.add(Box.createVerticalStrut(ITEM_GAP));
00177         pane.add(line2);
00178         pane.add(Box.createVerticalStrut(CONTENTS_GAP));
00179         pane.add(bLine);
00180         pane.add(Box.createVerticalStrut(BORDER_GAP));
00181 
00182         // その他
00183         setResizable(false);  // リサイズ不可
00184     }
00185 
00186     // -----------------------------------------------------------------
00187     // メソッド
00193     public void setVisible(
00194         boolean visible
00195     ) {
00196         if (visible) {
00197             pathField_.setText(path_);
00198             colorCheck_.setSelected(colorOutput_);
00199             graphCheck_.setSelected(graphOutput_);
00200             legendCheck_.setSelected(legendOutput_);
00201             okButton_.setEnabled(graphOutput_ || legendOutput_);
00202             pathField_.requestFocus();   // 初期フォーカス設定
00203             updated_ = false;
00204             pack();
00205         }
00206         super.setVisible(visible);
00207     }
00208 
00214     public void setPath(
00215         String path
00216     ) {
00217         path_ = path;
00218     }
00219 
00225     public void setColorOutput(
00226         boolean color
00227     ) {
00228         colorOutput_ = color;
00229     }
00230 
00231 
00237     public void setGraphOutput(
00238         boolean output
00239     ) {
00240         graphOutput_ = output;
00241     }
00242 
00248     public void setLegendOutput(
00249         boolean output
00250     ) {
00251         legendOutput_ = output;
00252     }
00253 
00259     public String getPath() {
00260         return path_;
00261     }
00262 
00268     public boolean isColorOutput() {
00269         return colorOutput_;
00270     }
00271 
00277     public boolean isGraphOutput() {
00278         return graphOutput_;
00279     }
00280 
00286     public boolean isLegendOutput() {
00287         return legendOutput_;
00288     }
00289 
00295     public boolean isUpdated() {
00296         return updated_;
00297     }
00298 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16