• R/O
  • SSH
  • HTTPS

pdf-brewer: コミット


コミットメタ情報

リビジョン28 (tree)
日時2020-11-18 15:58:45
作者hirukawa_ryo

ログメッセージ

* pdf-brewer-javafx 0.4.5
依存ライブラリ fx-util 0.3.8 -> 0.4.0
SingletonApplicationを継承したMainクラスをMainAppクラスにリネームしてエントリーメソッドmainのみを持つMainクラスを追加しました。

変更サマリ

差分

--- pdf-brewer-javafx/trunk/src/main/java/net/osdn/pdf_brewer/ui/Main.css (revision 27)
+++ pdf-brewer-javafx/trunk/src/main/java/net/osdn/pdf_brewer/ui/Main.css (nonexistent)
@@ -1,12 +0,0 @@
1-.root {
2- -fx-font-family: "Meiryo";
3- -fx-font-size: 12px;
4-}
5-
6-FontIcon {
7- -fx-icon-size: 17;
8- -fx-icon-color: -fx-selection-bar;
9-}
10-.menu-item:focused FontIcon {
11- -fx-icon-color: -fx-selection-bar-text;
12-}
--- pdf-brewer-javafx/trunk/src/main/java/net/osdn/pdf_brewer/ui/Main.java (revision 27)
+++ pdf-brewer-javafx/trunk/src/main/java/net/osdn/pdf_brewer/ui/Main.java (revision 28)
@@ -1,252 +1,12 @@
11 package net.osdn.pdf_brewer.ui;
22
3-import java.io.File;
4-import java.io.IOException;
5-import java.lang.Thread.UncaughtExceptionHandler;
6-import java.net.URL;
7-import java.util.List;
8-import java.util.ResourceBundle;
9-import java.util.prefs.Preferences;
10-
11-import javafx.beans.binding.StringBinding;
12-import javafx.beans.property.ObjectProperty;
13-import javafx.beans.property.SimpleObjectProperty;
3+import javafx.application.Platform;
144 import net.osdn.util.javafx.application.SingletonApplication;
15-import net.osdn.util.javafx.fxml.Fxml;
16-import net.osdn.util.javafx.scene.control.pdf.Pager;
17-import net.osdn.util.javafx.scene.control.pdf.PdfView;
18-import net.osdn.util.javafx.stage.StageUtil;
195
20-import javafx.application.Platform;
21-import javafx.beans.binding.Bindings;
22-import javafx.event.ActionEvent;
23-import javafx.fxml.FXML;
24-import javafx.fxml.Initializable;
25-import javafx.scene.Parent;
26-import javafx.scene.Scene;
27-import javafx.scene.control.MenuItem;
28-import javafx.scene.image.Image;
29-import javafx.scene.input.DragEvent;
30-import javafx.scene.input.TransferMode;
31-import javafx.stage.FileChooser;
32-import javafx.stage.Stage;
33-import net.osdn.util.fx.toast.Toast;
6+public class Main {
347
35-public class Main extends SingletonApplication implements Initializable {
36-
37- public static final String APPLICATION_NAME = "PDF BREWER";
38- public static final String APPLICATION_VERSION;
39-
40- static {
41- System.setProperty("org.apache.commons.logging.LogFactory", "net.osdn.pdf_brewer.ui.LogFilter");
42- LogFilter.setLevel("org.apache.pdfbox", LogFilter.Level.ERROR);
43- LogFilter.setLevel("org.apache.fontbox", LogFilter.Level.ERROR);
44-
45- int[] version = Datastore.getApplicationVersion();
46- if(version != null) {
47- if (version[2] == 0) {
48- APPLICATION_VERSION = String.format("%d.%d", version[0], version[1]);
49- } else {
50- APPLICATION_VERSION = String.format("%d.%d.%d", version[0], version[1], version[2]);
51- }
52- } else {
53- APPLICATION_VERSION = "";
54- }
8+ public static void main(String[] args) {
9+ Platform.setImplicitExit(false);
10+ SingletonApplication.launch(MainApp.class, args);
5511 }
56-
57- public static void main(String[] args) throws Throwable {
58- launch(args);
59- }
60-
61- private String title = "PDF BREWER";
62- private File inputFile;
63- private File lastSaveFolder;
64-
65- @Override
66- public void start(Stage primaryStage) throws Exception {
67- primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/img/app-icon-48px.png")));
68- primaryStage.titleProperty().bind(new StringBinding() {
69- {
70- bind(inputFileProperty);
71- }
72- @Override
73- protected String computeValue() {
74- return (inputFileProperty.get() != null ? inputFileProperty.get().getAbsolutePath() + " - " : "")
75- + APPLICATION_NAME + " " + APPLICATION_VERSION;
76- }
77- });
78-
79- Parent root = Fxml.load(this);
80-
81- Scene scene = new Scene(root);
82- scene.setOnDragOver(wrap(this::scene_onDragOver));
83- scene.setOnDragDropped(wrap(this::scene_onDragDropped));
84- scene.getAccelerators().putAll(pager.createDefaultAccelerators());
85-
86- StageUtil.setRestorable(primaryStage, Preferences.userNodeForPackage(getClass()));
87- primaryStage.setMinWidth(320);
88- primaryStage.setMinHeight(320);
89- primaryStage.setScene(scene);
90- primaryStage.show();
91-
92- Thread.currentThread().setUncaughtExceptionHandler(handler);
93- }
94-
95- protected UncaughtExceptionHandler handler = new UncaughtExceptionHandler() {
96- @Override
97- public void uncaughtException(Thread t, Throwable e) {
98- if(e instanceof Exception) {
99- showException((Exception)e);
100- } else if(Thread.getDefaultUncaughtExceptionHandler() != null) {
101- Thread.getDefaultUncaughtExceptionHandler().uncaughtException(t, e);
102- } else {
103- e.printStackTrace();
104- }
105- }
106- };
107-
108- protected void showException(Throwable exception) {
109- exception.printStackTrace();
110-
111- Runnable r = ()-> {
112- String title = exception.getClass().getName();
113- String message = exception.getLocalizedMessage();
114- if(message != null) {
115- message = message.trim();
116- }
117- toast.show(Toast.RED, title, message, null);
118- };
119- if(Platform.isFxApplicationThread()) {
120- r.run();
121- } else {
122- Platform.runLater(r);
123- }
124- }
125-
126- @FXML MenuItem menuFileOpen;
127- @FXML MenuItem menuFileSave;
128- @FXML MenuItem menuFileExit;
129- @FXML Pager pager;
130- @FXML PdfView pdfView;
131- @FXML Toast toast;
132- ObjectProperty<File> inputFileProperty = new SimpleObjectProperty<File>();
133-
134- @Override
135- public void initialize(URL location, ResourceBundle resources) {
136-
137- //
138- // event handlers
139- //
140- menuFileOpen.setOnAction(wrap(this::menuFileOpen_onAction));
141- menuFileSave.setOnAction(wrap(this::menuFileSave_onAction));
142- menuFileExit.setOnAction(wrap(this::menuFileExit_onAction));
143-
144- //
145- // bindings
146- //
147- menuFileSave.disableProperty().bind(Bindings.isNull(pdfView.documentProperty()));
148-
149- pager.maxPageIndexProperty().bind(pdfView.maxPageIndexProperty());
150- pager.pageIndexProperty().bindBidirectional(pdfView.pageIndexProperty());
151-
152- toast.maxWidthProperty().bind(getPrimaryStage().widthProperty().subtract(32));
153- toast.maxHeightProperty().bind(getPrimaryStage().heightProperty().subtract(32));
154- }
155-
156- protected File getFile(DragEvent event) {
157- if(event.getDragboard().hasFiles()) {
158- List<File> files = event.getDragboard().getFiles();
159- if(files.size() == 1) {
160- return files.get(0);
161- }
162- }
163- return null;
164- }
165-
166- protected boolean isAcceptable(File file) {
167- return file != null && file.getName().matches("(?i).+(\\.pdf|\\.yml|\\.yaml|\\.pb)");
168- }
169-
170- void scene_onDragOver(DragEvent event) {
171- if(isAcceptable(getFile(event))) {
172- event.acceptTransferModes(TransferMode.COPY);
173- } else {
174- event.consume();
175- }
176- }
177-
178- void scene_onDragDropped(DragEvent event) {
179- File file = getFile(event);
180- if(isAcceptable(file)) {
181- getPrimaryStage().toFront();
182- toast.hide();
183- lastSaveFolder = null;
184- inputFileProperty.set(file);
185- pdfView.load(new DocumentLoader(file.toPath()));
186- event.setDropCompleted(true);
187- }
188- event.consume();
189- }
190-
191- void menuFileOpen_onAction(ActionEvent event) {
192- toast.hide();
193- Preferences preferences = Preferences.userNodeForPackage(getClass());
194-
195- FileChooser fc = new FileChooser();
196- fc.setTitle("開く");
197- fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF Brewer", "*.pb"));
198- fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF", "*.pdf"));
199- fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("YAML", "*.yml", ".yaml"));
200-
201- String lastOpenDirectory = preferences.get("lastOpenDirectory", null);
202- if(lastOpenDirectory != null) {
203- File dir = new File(lastOpenDirectory);
204- if(dir.isDirectory()) {
205- fc.setInitialDirectory(dir);
206- }
207- }
208- File file = fc.showOpenDialog(getPrimaryStage());
209- if(file != null) {
210- preferences.put("lastOpenDirectory", file.getParentFile().getAbsolutePath());
211- if(isAcceptable(file)) {
212- toast.hide();
213- lastSaveFolder = null;
214- inputFileProperty.set(file);
215- pdfView.load(new DocumentLoader(file.toPath()));
216- }
217- }
218- }
219-
220- void menuFileSave_onAction(ActionEvent event) throws IOException {
221- toast.hide();
222- String defaultName = inputFileProperty.get().getName();
223- int i = defaultName.lastIndexOf('.');
224- if(i > 0) {
225- defaultName = defaultName.substring(0, i);
226- }
227- defaultName += ".pdf";
228-
229- FileChooser fc = new FileChooser();
230- fc.setTitle("名前を付けて保存");
231- fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF", "*.pdf"));
232- if(lastSaveFolder != null) {
233- fc.setInitialDirectory(lastSaveFolder);
234- } else {
235- fc.setInitialDirectory(inputFileProperty.get().getParentFile());
236- }
237- fc.setInitialFileName(defaultName);
238-
239- File file = fc.showSaveDialog(getPrimaryStage());
240- if(file != null) {
241- lastSaveFolder = file.getParentFile();
242- if(pdfView.getDocument() != null) {
243- pdfView.getDocument().save(file);
244- toast.show(Toast.GREEN, "保存しました", file.getAbsolutePath(), Toast.LONG);
245- }
246- }
247- }
248-
249- void menuFileExit_onAction(ActionEvent event) {
250- Platform.exit();
251- }
25212 }
--- pdf-brewer-javafx/trunk/src/main/java/net/osdn/pdf_brewer/ui/MainApp.css (nonexistent)
+++ pdf-brewer-javafx/trunk/src/main/java/net/osdn/pdf_brewer/ui/MainApp.css (revision 28)
@@ -0,0 +1,12 @@
1+.root {
2+ -fx-font-family: "Meiryo";
3+ -fx-font-size: 12px;
4+}
5+
6+FontIcon {
7+ -fx-icon-size: 17;
8+ -fx-icon-color: -fx-selection-bar;
9+}
10+.menu-item:focused FontIcon {
11+ -fx-icon-color: -fx-selection-bar-text;
12+}
--- pdf-brewer-javafx/trunk/src/main/java/net/osdn/pdf_brewer/ui/MainApp.java (nonexistent)
+++ pdf-brewer-javafx/trunk/src/main/java/net/osdn/pdf_brewer/ui/MainApp.java (revision 28)
@@ -0,0 +1,254 @@
1+package net.osdn.pdf_brewer.ui;
2+
3+import java.io.File;
4+import java.io.IOException;
5+import java.lang.Thread.UncaughtExceptionHandler;
6+import java.net.URL;
7+import java.util.List;
8+import java.util.ResourceBundle;
9+import java.util.prefs.Preferences;
10+
11+import javafx.beans.binding.StringBinding;
12+import javafx.beans.property.ObjectProperty;
13+import javafx.beans.property.SimpleObjectProperty;
14+import net.osdn.util.javafx.application.SingletonApplication;
15+import net.osdn.util.javafx.fxml.Fxml;
16+import net.osdn.util.javafx.scene.control.pdf.Pager;
17+import net.osdn.util.javafx.scene.control.pdf.PdfView;
18+import net.osdn.util.javafx.stage.StageUtil;
19+
20+import javafx.application.Platform;
21+import javafx.beans.binding.Bindings;
22+import javafx.event.ActionEvent;
23+import javafx.fxml.FXML;
24+import javafx.fxml.Initializable;
25+import javafx.scene.Parent;
26+import javafx.scene.Scene;
27+import javafx.scene.control.MenuItem;
28+import javafx.scene.image.Image;
29+import javafx.scene.input.DragEvent;
30+import javafx.scene.input.TransferMode;
31+import javafx.stage.FileChooser;
32+import javafx.stage.Stage;
33+import net.osdn.util.fx.toast.Toast;
34+
35+public class MainApp extends SingletonApplication implements Initializable {
36+
37+ public static final String APPLICATION_NAME = "PDF BREWER";
38+ public static final String APPLICATION_VERSION;
39+
40+ static {
41+ System.setProperty("org.apache.commons.logging.LogFactory", "net.osdn.pdf_brewer.ui.LogFilter");
42+ LogFilter.setLevel("org.apache.pdfbox", LogFilter.Level.ERROR);
43+ LogFilter.setLevel("org.apache.fontbox", LogFilter.Level.ERROR);
44+
45+ int[] version = Datastore.getApplicationVersion();
46+ if(version != null) {
47+ if (version[2] == 0) {
48+ APPLICATION_VERSION = String.format("%d.%d", version[0], version[1]);
49+ } else {
50+ APPLICATION_VERSION = String.format("%d.%d.%d", version[0], version[1], version[2]);
51+ }
52+ } else {
53+ APPLICATION_VERSION = "";
54+ }
55+ }
56+
57+ private String title = "PDF BREWER";
58+ private File inputFile;
59+ private File lastSaveFolder;
60+
61+ @Override
62+ public void start(Stage primaryStage) throws Exception {
63+ primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/img/app-icon-48px.png")));
64+ primaryStage.titleProperty().bind(new StringBinding() {
65+ {
66+ bind(inputFileProperty);
67+ }
68+ @Override
69+ protected String computeValue() {
70+ return (inputFileProperty.get() != null ? inputFileProperty.get().getAbsolutePath() + " - " : "")
71+ + APPLICATION_NAME + " " + APPLICATION_VERSION;
72+ }
73+ });
74+
75+ primaryStage.showingProperty().addListener((observable, oldValue, newValue) -> {
76+ if(oldValue == true && newValue == false) {
77+ Platform.exit();
78+ }
79+ });
80+
81+ Parent root = Fxml.load(this);
82+
83+ Scene scene = new Scene(root);
84+ scene.setOnDragOver(wrap(this::scene_onDragOver));
85+ scene.setOnDragDropped(wrap(this::scene_onDragDropped));
86+ scene.getAccelerators().putAll(pager.createDefaultAccelerators());
87+
88+ StageUtil.setRestorable(primaryStage, Preferences.userNodeForPackage(getClass()));
89+ primaryStage.setMinWidth(320);
90+ primaryStage.setMinHeight(320);
91+ primaryStage.setScene(scene);
92+ primaryStage.show();
93+
94+ Thread.currentThread().setUncaughtExceptionHandler(handler);
95+ }
96+
97+ protected UncaughtExceptionHandler handler = new UncaughtExceptionHandler() {
98+ @Override
99+ public void uncaughtException(Thread t, Throwable e) {
100+ if(e instanceof Exception) {
101+ showException((Exception)e);
102+ } else if(Thread.getDefaultUncaughtExceptionHandler() != null) {
103+ Thread.getDefaultUncaughtExceptionHandler().uncaughtException(t, e);
104+ } else {
105+ e.printStackTrace();
106+ }
107+ }
108+ };
109+
110+ protected void showException(Throwable exception) {
111+ exception.printStackTrace();
112+
113+ Runnable r = ()-> {
114+ String title = exception.getClass().getName();
115+ String message = exception.getLocalizedMessage();
116+ if(message != null) {
117+ message = message.trim();
118+ }
119+ toast.show(Toast.RED, title, message, null);
120+ };
121+ if(Platform.isFxApplicationThread()) {
122+ r.run();
123+ } else {
124+ Platform.runLater(r);
125+ }
126+ }
127+
128+ @FXML MenuItem menuFileOpen;
129+ @FXML MenuItem menuFileSave;
130+ @FXML MenuItem menuFileExit;
131+ @FXML Pager pager;
132+ @FXML PdfView pdfView;
133+ @FXML Toast toast;
134+ ObjectProperty<File> inputFileProperty = new SimpleObjectProperty<File>();
135+
136+ @Override
137+ public void initialize(URL location, ResourceBundle resources) {
138+
139+ //
140+ // event handlers
141+ //
142+ menuFileOpen.setOnAction(wrap(this::menuFileOpen_onAction));
143+ menuFileSave.setOnAction(wrap(this::menuFileSave_onAction));
144+ menuFileExit.setOnAction(wrap(this::menuFileExit_onAction));
145+
146+ //
147+ // bindings
148+ //
149+ menuFileSave.disableProperty().bind(Bindings.isNull(pdfView.documentProperty()));
150+
151+ pager.maxPageIndexProperty().bind(pdfView.maxPageIndexProperty());
152+ pager.pageIndexProperty().bindBidirectional(pdfView.pageIndexProperty());
153+
154+ toast.maxWidthProperty().bind(getPrimaryStage().widthProperty().subtract(32));
155+ toast.maxHeightProperty().bind(getPrimaryStage().heightProperty().subtract(32));
156+ }
157+
158+ protected File getFile(DragEvent event) {
159+ if(event.getDragboard().hasFiles()) {
160+ List<File> files = event.getDragboard().getFiles();
161+ if(files.size() == 1) {
162+ return files.get(0);
163+ }
164+ }
165+ return null;
166+ }
167+
168+ protected boolean isAcceptable(File file) {
169+ return file != null && file.getName().matches("(?i).+(\\.pdf|\\.yml|\\.yaml|\\.pb)");
170+ }
171+
172+ void scene_onDragOver(DragEvent event) {
173+ if(isAcceptable(getFile(event))) {
174+ event.acceptTransferModes(TransferMode.COPY);
175+ } else {
176+ event.consume();
177+ }
178+ }
179+
180+ void scene_onDragDropped(DragEvent event) {
181+ File file = getFile(event);
182+ if(isAcceptable(file)) {
183+ getPrimaryStage().toFront();
184+ toast.hide();
185+ lastSaveFolder = null;
186+ inputFileProperty.set(file);
187+ pdfView.load(new DocumentLoader(file.toPath()));
188+ event.setDropCompleted(true);
189+ }
190+ event.consume();
191+ }
192+
193+ void menuFileOpen_onAction(ActionEvent event) {
194+ toast.hide();
195+ Preferences preferences = Preferences.userNodeForPackage(getClass());
196+
197+ FileChooser fc = new FileChooser();
198+ fc.setTitle("開く");
199+ fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF Brewer", "*.pb"));
200+ fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF", "*.pdf"));
201+ fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("YAML", "*.yml", ".yaml"));
202+
203+ String lastOpenDirectory = preferences.get("lastOpenDirectory", null);
204+ if(lastOpenDirectory != null) {
205+ File dir = new File(lastOpenDirectory);
206+ if(dir.isDirectory()) {
207+ fc.setInitialDirectory(dir);
208+ }
209+ }
210+ File file = fc.showOpenDialog(getPrimaryStage());
211+ if(file != null) {
212+ preferences.put("lastOpenDirectory", file.getParentFile().getAbsolutePath());
213+ if(isAcceptable(file)) {
214+ toast.hide();
215+ lastSaveFolder = null;
216+ inputFileProperty.set(file);
217+ pdfView.load(new DocumentLoader(file.toPath()));
218+ }
219+ }
220+ }
221+
222+ void menuFileSave_onAction(ActionEvent event) throws IOException {
223+ toast.hide();
224+ String defaultName = inputFileProperty.get().getName();
225+ int i = defaultName.lastIndexOf('.');
226+ if(i > 0) {
227+ defaultName = defaultName.substring(0, i);
228+ }
229+ defaultName += ".pdf";
230+
231+ FileChooser fc = new FileChooser();
232+ fc.setTitle("名前を付けて保存");
233+ fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF", "*.pdf"));
234+ if(lastSaveFolder != null) {
235+ fc.setInitialDirectory(lastSaveFolder);
236+ } else {
237+ fc.setInitialDirectory(inputFileProperty.get().getParentFile());
238+ }
239+ fc.setInitialFileName(defaultName);
240+
241+ File file = fc.showSaveDialog(getPrimaryStage());
242+ if(file != null) {
243+ lastSaveFolder = file.getParentFile();
244+ if(pdfView.getDocument() != null) {
245+ pdfView.getDocument().save(file);
246+ toast.show(Toast.GREEN, "保存しました", file.getAbsolutePath(), Toast.LONG);
247+ }
248+ }
249+ }
250+
251+ void menuFileExit_onAction(ActionEvent event) {
252+ getPrimaryStage().close();
253+ }
254+}
旧リポジトリブラウザで表示