OSDN Git Service

サイズ入力欄のコンポーネント作成
authoryukihane <yukihane.feather@gmail.com>
Tue, 2 Aug 2011 05:55:23 +0000 (14:55 +0900)
committeryukihane <yukihane.feather@gmail.com>
Tue, 2 Aug 2011 05:55:23 +0000 (14:55 +0900)
frontend/src/saccubus/MainFrame.java
frontend/src/saccubus/NumberFormattedTextField.java [new file with mode: 0644]

index d126d8a..3b4af1c 100644 (file)
@@ -18,6 +18,8 @@ import java.awt.event.KeyEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import javax.swing.BorderFactory;
 import javax.swing.ButtonGroup;
 import javax.swing.GroupLayout;
@@ -38,7 +40,6 @@ import javax.swing.JTabbedPane;
 import javax.swing.JTextField;
 import javax.swing.LayoutStyle.ComponentPlacement;
 import javax.swing.SwingUtilities;
-import javax.swing.border.BevelBorder;
 import nicobrowser.entity.NicoContent;
 import org.apache.commons.lang.StringUtils;
 import saccubus.ConvertStopFlag.State;
@@ -449,6 +450,7 @@ public class MainFrame extends JFrame {
                         .addComponent(mainOptionLabel)
                         .addComponent(inputOptionLabel)
                         .addComponent(outputOptionLabel))
+                    .addPreferredGap(ComponentPlacement.RELATED)
                     .addGroup(layout.createParallelGroup()
                         .addComponent(extOptionField)
                         .addComponent(mainOptionField)
@@ -809,8 +811,12 @@ public class MainFrame extends JFrame {
      *            ActionEvent
      */
     void jMenuFileExit_actionPerformed(ActionEvent actionEvent) {
-        SProperties setting = getSetting();
-        SProperties.saveSetting(setting);
+        try {
+            SProperties setting = getSetting();
+            SProperties.saveSetting(setting);
+        } catch (Throwable t) {
+            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, "設定保存に失敗", t);
+        }
         System.exit(0);
     }
 
@@ -842,9 +848,9 @@ public class MainFrame extends JFrame {
     private final JTextField avfilterOptionField = new JTextField();
     private final JCheckBox resizeCheckBox = new JCheckBox("次のサイズに収まるようリサイズ");
     private final JLabel resizeWidthLabel = new JLabel("横");
-    private final JTextField resizeWidthField = new JTextField();
+    private final JTextField resizeWidthField = new NumberFormattedTextField();
     private final JLabel resizeHeightLabel = new JLabel("縦");
-    private final JTextField resizeHeigitField = new JTextField();
+    private final JTextField resizeHeigitField = new NumberFormattedTextField();
     private final JCheckBox adjustRatioCheckBox = new JCheckBox("アスペクト比を維持");
     private final JCheckBox paddingCheckBox = new JCheckBox("黒幕を付与");
     // FFmpegの設定 ここまで
diff --git a/frontend/src/saccubus/NumberFormattedTextField.java b/frontend/src/saccubus/NumberFormattedTextField.java
new file mode 100644 (file)
index 0000000..27e46fe
--- /dev/null
@@ -0,0 +1,36 @@
+package saccubus;
+
+import java.awt.event.FocusEvent;
+import java.text.DecimalFormat;
+import javax.swing.JFormattedTextField;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+
+/**
+ *
+ * @author yuki
+ */
+public class NumberFormattedTextField extends JFormattedTextField {
+
+    private static final long serialVersionUID = 1L;
+
+    public NumberFormattedTextField() {
+        super(new DecimalFormat("#"));
+        this.setHorizontalAlignment(JTextField.RIGHT);
+        this.addFocusListener(new FocusAdapter());
+    }
+
+    public class FocusAdapter extends java.awt.event.FocusAdapter {
+
+        @Override
+        public void focusGained(FocusEvent e) {
+            SwingUtilities.invokeLater(new Runnable() {
+
+                @Override
+                public void run() {
+                    selectAll();
+                }
+            });
+        }
+    }
+}