Permalink
Browse files

(fixes #32) added "Create" button to generate a skelton

  • Loading branch information...
1 parent fc2fdc3 commit 9a3acbba8faf9e1c61e997fdc017991bf1aa267a @fukamachi committed Nov 14, 2010
Showing with 60 additions and 10 deletions.
  1. +22 −0 skelton.clj
  2. +1 −1 src/L5.clj
  3. +37 −9 src/L5/file.clj
View
@@ -0,0 +1,22 @@
+(ns L5.presentation
+ (:use L5 L5.layout))
+
+(defcontext
+ {:width 640 :height 480
+ :font-family "Gill Sans"
+ :font-size 30})
+
+(defslides
+ ;; Title page
+ [(t "タイトルを入力")
+ (with {:font-size 15
+ :position :fixed
+ :padding {:top 360}}
+ (lines "アリエル・ネットワーク"
+ "深町英太郎"))]
+ ;; Itemize slide
+ [(title "タイトルを入力")
+ (item "箇条書き1"
+ "箇条書き2")]
+ ;; Extra large letters
+ [(t "入力")])
View
@@ -83,7 +83,7 @@
(dosync (ref-set *run-file* file))
(reload)
(attach-event KeyEvent/VK_R #(reload))
- (attach-event KeyEvent/VK_E (fn [] (file/save-dialog @(:frame (context)) #(export %))))
+ (attach-event KeyEvent/VK_E (fn [] (file/save-dialog @(:frame (context)) #(export %) file/pdf-filter)))
(attach-event KeyEvent/VK_Q #(System/exit 0))
(context/start (context)))
View
@@ -1,10 +1,14 @@
(ns L5.file
+ (:require [clojure.contrib.io :as io])
(:import [java.io File]
[javax.swing JFrame JPanel JLabel JButton JFileChooser SwingConstants]
[javax.swing.filechooser FileNameExtensionFilter]
[java.awt GridLayout]
[java.awt.event ActionListener]))
+(def presen-filter (FileNameExtensionFilter. "Presentation (.clj .lgo)" (into-array ["clj" "lgo"])))
+(def pdf-filter (FileNameExtensionFilter. "PDF (.pdf)" (into-array ["pdf"])))
+
(defn- file-dialog [action parent callback filter]
(let [chooser (JFileChooser.)]
(.setCurrentDirectory chooser (.. (File. ".") getAbsoluteFile getParentFile))
@@ -19,25 +23,49 @@
(file-dialog :open parent callback
(FileNameExtensionFilter. "Presentation (.clj .lgo)" (into-array ["clj" "lgo"]))))
-(defn save-dialog [parent callback]
- (file-dialog :save parent callback
- (FileNameExtensionFilter. "PDF (.pdf)" (into-array ["pdf"]))))
+(defn save-dialog [parent callback filter]
+ (file-dialog :save parent callback filter))
+
+(defn open-file [file]
+ (try
+ ;; open with the specifiled program
+ (.open (java.awt.Desktop/getDesktop) file)
+ (catch java.io.IOException e
+ ;; open with $EDITOR
+ (let [editor (System/getenv "EDITOR")]
+ (when editor
+ (.exec (Runtime/getRuntime)
+ (format "%s %s" editor (.getAbsolutePath file))))))))
+
+(defn- get-create-button [frame]
+ (let [button (JButton. "Create")
+ action (proxy [ActionListener] []
+ (actionPerformed [e]
+ (save-dialog frame
+ #(let [file (File. %)]
+ (io/copy (File. "skelton.clj") file)
+ (open-file file))
+ presen-filter)))]
+ (.addActionListener button action)
+ button))
(defn open-chooser [name callback]
(let [frame (JFrame. name)
- panel (JPanel. (GridLayout. 3 1))
- button-action (proxy [ActionListener] []
+ panel (JPanel. (GridLayout. 4 1))
+ open-action (proxy [ActionListener] []
(actionPerformed [e]
(choose-dialog frame callback)))]
- (let [button (JButton. "Open")]
- (.addActionListener button button-action)
+ (let [create-button (get-create-button frame)
+ open-button (JButton. "Open")]
+ (.addActionListener open-button open-action)
(doto panel
(.add (JLabel. "<html><p style=\"font-weight: bold; padding-left: 20px;\">Welcome to L5!</p></html>"))
- (.add button)
+ (.add create-button)
+ (.add open-button)
(.add (doto (JLabel. "Copyright (c) 2010 深町英太郎")
(.setHorizontalAlignment SwingConstants/CENTER)))))
(doto frame
(.add panel)
- (.setSize 250 150)
+ (.setSize 250 180)
(.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
(.setVisible true))))

0 comments on commit 9a3acbb

Please sign in to comment.