EPSDialog.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 package com.generalrobotix.ui.view.graph;
11 
12 import java.awt.*;
13 import java.awt.event.*;
14 import javax.swing.*;
15 
17 
24 public class EPSDialog extends JDialog {
25 
26  // -----------------------------------------------------------------
27  // 定数
28  // 配置
29  private static final int BORDER_GAP = 12;
30  private static final int LABEL_GAP = 12;
31  private static final int BUTTON_GAP = 5;
32  private static final int ITEM_GAP = 11;
33  private static final int CONTENTS_GAP = 17;
34 
35  // -----------------------------------------------------------------
36  // インスタンス変数
37  String path_; // パス
38  boolean colorOutput_; // カラー出力フラグ
39  boolean graphOutput_; // グラフ出力フラグ
40  boolean legendOutput_; // 凡例出力グラフ
41  boolean updated_; // 更新フラグ
42  JTextField pathField_; // パス入力フィールド
43  JCheckBox colorCheck_; // カラーチェックボックス
44  JCheckBox graphCheck_; // グラフ出力チェックボックス
45  JCheckBox legendCheck_; // 凡例出力チェックボックス
46  JButton okButton_; // OKボタン
47  JFileChooser chooser_; // ファイル選択ダイアログ
48 
49  // -----------------------------------------------------------------
50  // コンストラクタ
56  public EPSDialog(Frame owner) {
57  super(owner, MessageBundle.get("dialog.graph.eps.title"), true);
58 
59  chooser_ = new JFileChooser(System.getProperty("user.dir"));
60 
61  // 1行目(パス)
62  JLabel outputLabel = new JLabel(MessageBundle.get("dialog.graph.eps.outputto"));
63  int labelWidth = outputLabel.getMinimumSize().width;
64  pathField_ = new JTextField("", 20);
65  pathField_.setPreferredSize(new Dimension(400, 26));
66  pathField_.setMaximumSize(new Dimension(400, 26));
67  JButton browseButton = new JButton(MessageBundle.get("dialog.graph.eps.browse"));
68  browseButton.addActionListener(
69  new ActionListener() {
70  public void actionPerformed(ActionEvent evt) {
71  //int result = chooser_.showSaveDialog(EPSDialog.this);
72  int result = chooser_.showDialog(EPSDialog.this, MessageBundle.get("dialog.okButton"));
73  if (result == JFileChooser.APPROVE_OPTION) {
74  pathField_.setText(
75  chooser_.getSelectedFile().getPath()
76  );
77  }
78  }
79  }
80  );
81  JPanel line1 = new JPanel();
82  line1.setLayout(new BoxLayout(line1, BoxLayout.X_AXIS));
83  line1.add(Box.createHorizontalStrut(BORDER_GAP));
84  line1.add(outputLabel);
85  //line1.add(Box.createHorizontalGlue());
86  line1.add(Box.createHorizontalStrut(LABEL_GAP));
87  line1.add(pathField_);
88  line1.add(Box.createHorizontalStrut(5));
89  line1.add(browseButton);
90  //line1.add(Box.createHorizontalStrut(7)); // (注)調整箇所
91  line1.add(Box.createHorizontalStrut(BORDER_GAP));
92  line1.setAlignmentX(Component.LEFT_ALIGNMENT);
93 
94  // チェックボックスリスナ
95  ItemListener checkListener = new ItemListener() {
96  public void itemStateChanged(ItemEvent evt) {
97  okButton_.setEnabled(
98  graphCheck_.isSelected()
99  || legendCheck_.isSelected()
100  );
101  }
102  };
103 
104  // 2行目(グラフチェック)
105  colorCheck_ = new JCheckBox(MessageBundle.get("dialog.graph.eps.color"));
106  graphCheck_ = new JCheckBox(MessageBundle.get("dialog.graph.eps.graph"));
107  graphCheck_.addItemListener(checkListener);
108  legendCheck_ = new JCheckBox(MessageBundle.get("dialog.graph.eps.legend"));
109  legendCheck_.addItemListener(checkListener);
110  JPanel line2 = new JPanel();
111  line2.setLayout(new BoxLayout(line2, BoxLayout.X_AXIS));
112  line2.add(Box.createHorizontalStrut(BORDER_GAP));
113  line2.add(Box.createHorizontalStrut(labelWidth));
114  line2.add(Box.createHorizontalStrut(LABEL_GAP));
115  line2.add(colorCheck_);
116  line2.add(Box.createHorizontalStrut(LABEL_GAP));
117  line2.add(graphCheck_);
118  line2.add(Box.createHorizontalStrut(ITEM_GAP));
119  line2.add(legendCheck_);
120  line2.setAlignmentX(Component.LEFT_ALIGNMENT);
121 
122  // ボタン行
123  okButton_ = new JButton(MessageBundle.get("dialog.okButton"));
124  this.getRootPane().setDefaultButton(okButton_);
125  okButton_.addActionListener(
126  new ActionListener() {
127  public void actionPerformed(ActionEvent evt) {
128  // パスのチェック
129  String path = pathField_.getText().trim();
130  // (不正なパスならエラーダイアログ表示)
131  // 値更新
132  if (!path.equals("") && !path.endsWith(".eps")) {
133  path += ".eps";
134  }
135  path_ = path;
136  colorOutput_ = colorCheck_.isSelected();
137  graphOutput_ = graphCheck_.isSelected();
138  legendOutput_ = legendCheck_.isSelected();
139  updated_ = true;
140  EPSDialog.this.setVisible(false);
141  }
142  }
143  );
144  JButton cancelButton = new JButton(MessageBundle.get("dialog.cancelButton"));
145  cancelButton.addActionListener(
146  new ActionListener() {
147  public void actionPerformed(ActionEvent evt) {
148  EPSDialog.this.setVisible(false);
149  }
150  }
151  );
152  this.addKeyListener(
153  new KeyAdapter() {
154  public void keyPressed(KeyEvent evt) {
155  if (evt.getID() == KeyEvent.KEY_PRESSED
156  && evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
157  EPSDialog.this.setVisible(false);
158  }
159  }
160  }
161  );
162  JPanel bLine = new JPanel();
163  bLine.setLayout(new BoxLayout(bLine, BoxLayout.X_AXIS));
164  bLine.add(Box.createHorizontalGlue());
165  bLine.add(okButton_);
166  bLine.add(Box.createHorizontalStrut(BUTTON_GAP));
167  bLine.add(cancelButton);
168  bLine.add(Box.createHorizontalStrut(BORDER_GAP));
169  bLine.setAlignmentX(Component.LEFT_ALIGNMENT);
170 
171  // パネル構築
172  Container pane = getContentPane();
173  pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
174  pane.add(Box.createVerticalStrut(BORDER_GAP));
175  pane.add(line1);
176  pane.add(Box.createVerticalStrut(ITEM_GAP));
177  pane.add(line2);
178  pane.add(Box.createVerticalStrut(CONTENTS_GAP));
179  pane.add(bLine);
180  pane.add(Box.createVerticalStrut(BORDER_GAP));
181 
182  // その他
183  setResizable(false); // リサイズ不可
184  }
185 
186  // -----------------------------------------------------------------
187  // メソッド
193  public void setVisible(
194  boolean visible
195  ) {
196  if (visible) {
197  pathField_.setText(path_);
198  colorCheck_.setSelected(colorOutput_);
199  graphCheck_.setSelected(graphOutput_);
200  legendCheck_.setSelected(legendOutput_);
201  okButton_.setEnabled(graphOutput_ || legendOutput_);
202  pathField_.requestFocus(); // 初期フォーカス設定
203  updated_ = false;
204  pack();
205  }
206  super.setVisible(visible);
207  }
208 
214  public void setPath(
215  String path
216  ) {
217  path_ = path;
218  }
219 
225  public void setColorOutput(
226  boolean color
227  ) {
228  colorOutput_ = color;
229  }
230 
231 
237  public void setGraphOutput(
238  boolean output
239  ) {
240  graphOutput_ = output;
241  }
242 
248  public void setLegendOutput(
249  boolean output
250  ) {
251  legendOutput_ = output;
252  }
253 
259  public String getPath() {
260  return path_;
261  }
262 
268  public boolean isColorOutput() {
269  return colorOutput_;
270  }
271 
277  public boolean isGraphOutput() {
278  return graphOutput_;
279  }
280 
286  public boolean isLegendOutput() {
287  return legendOutput_;
288  }
289 
295  public boolean isUpdated() {
296  return updated_;
297  }
298 }
static final String get(String key)
path
output(gif_dest_ptr dinfo, int code)
Definition: wrgif.c:105


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:37