This repository has been archived by the owner on Aug 9, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added GUI components to choose a presentation file
- Loading branch information
Showing
5 changed files
with
66 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(ns L5.file | ||
(:import [javax.swing JFrame JLabel JButton JSplitPane JFileChooser] | ||
[java.io File] | ||
[java.awt.event ActionListener])) | ||
|
||
(defn- file-dialog [action parent callback] | ||
(let [chooser (JFileChooser.)] | ||
(.setCurrentDirectory chooser (.. (File. ".") getAbsoluteFile getParentFile)) | ||
(when (= JFileChooser/APPROVE_OPTION | ||
(if (= :save action) | ||
(.showSaveDialog chooser parent) | ||
(.showOpenDialog chooser parent))) | ||
(callback (.. chooser getSelectedFile getPath))))) | ||
|
||
(defn choose-dialog [parent callback] | ||
(file-dialog :open parent callback)) | ||
|
||
(defn save-dialog [parent callback] | ||
(file-dialog :save parent callback)) | ||
|
||
(defn open-chooser [name callback] | ||
(let [frame (JFrame. name) | ||
split-pane (JSplitPane. JSplitPane/VERTICAL_SPLIT) | ||
button-action (proxy [ActionListener] [] | ||
(actionPerformed [e] | ||
(choose-dialog frame callback)))] | ||
(let [button (JButton. "Open presentation")] | ||
(.addActionListener button button-action) | ||
(doto split-pane | ||
(.add (JLabel. "Welcome to L5")) | ||
(.add button))) | ||
(doto frame | ||
(.add split-pane) | ||
(.setSize 200 200) | ||
(.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE) | ||
(.setVisible true)))) |