diff --git a/src/main/java/org/darisadesigns/polyglotlina/CustHandlerFactory.java b/src/main/java/org/darisadesigns/polyglotlina/CustHandlerFactory.java index 1b6b79ba..2d996114 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/CustHandlerFactory.java +++ b/src/main/java/org/darisadesigns/polyglotlina/CustHandlerFactory.java @@ -894,7 +894,7 @@ public void characters(char[] ch, int start, int length) } else if (blangRegexFontOvr) { propertiesManager.setOverrideRegexFont(new String(ch, start, length).equals(PGTUtil.TRUE)); } else if (bfontSize) { - propertiesManager.setFontSize(Integer.parseInt(new String(ch, start, length))); + propertiesManager.setFontSize(Double.valueOf(new String(ch, start, length))); bfontSize = false; } else if (bfontStyle) { propertiesManager.setFontStyle(Integer.parseInt(new String(ch, start, length))); diff --git a/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PCellEditor.java b/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PCellEditor.java index ff1298bb..bf65ac18 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PCellEditor.java +++ b/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PCellEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019, Draque Thompson, draquemail@gmail.com + * Copyright (c) 2014-2020, Draque Thompson, draquemail@gmail.com * All rights reserved. * * Licensed under: MIT Licence @@ -55,8 +55,7 @@ public final class PCellEditor extends AbstractCellEditor implements TableCellEd public PCellEditor(boolean _useConFont, DictCore _core) { core = _core; useConFont = _useConFont; - Integer preSize = core.getPropertiesManager().getFontSize(); - preSize = preSize == null ? 0 : preSize; + double preSize = core.getPropertiesManager().getFontSize(); Font defFont = useConFont ? core.getPropertiesManager().getFontCon() : core.getPropertiesManager().getFontLocal(); @@ -227,7 +226,7 @@ public void mouseReleased(MouseEvent e) { } /** - * @param ignoreListenerSilencing the ignoreListenerSilencing to set + * @param _ignoreListenerSilencing the ignoreListenerSilencing to set */ public void setIgnoreListenerSilencing(boolean _ignoreListenerSilencing) { this.ignoreListenerSilencing = _ignoreListenerSilencing; diff --git a/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PCellRenderer.java b/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PCellRenderer.java index 1773b5ac..e8124d5a 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PCellRenderer.java +++ b/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PCellRenderer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019, Draque Thompson, draquemail@gmail.com + * Copyright (c) 2014-2020, Draque Thompson, draquemail@gmail.com * All rights reserved. * * Licensed under: MIT Licence @@ -49,8 +49,7 @@ public class PCellRenderer implements TableCellRenderer { public PCellRenderer(boolean _useConFont, DictCore _core) { core = _core; useConFont = _useConFont; - Integer preSize = core.getPropertiesManager().getFontSize(); - preSize = preSize == null ? 0 : preSize; + double preSize = core.getPropertiesManager().getFontSize(); Font selectedFont = useConFont ? core.getPropertiesManager().getFontCon() : diff --git a/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PGrammarPane.java b/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PGrammarPane.java index ab33c037..3b5b34f0 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PGrammarPane.java +++ b/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PGrammarPane.java @@ -75,7 +75,7 @@ private void setupRightClickMenu() { insertImage.addActionListener((ActionEvent ae) -> { try { ImageNode image = core.getImageCollection() - .openNewImage((Window) parentPane.getTopLevelAncestor()); + .openNewImage((Window) parentPane.getTopLevelAncestor(), core.getWorkingDirectory()); if (image != null) { // null node means user cancelled process addImage(image); diff --git a/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PTextFieldFilter.java b/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PTextFieldFilter.java index a413a140..b9fecdb6 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PTextFieldFilter.java +++ b/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PTextFieldFilter.java @@ -32,10 +32,7 @@ */ public class PTextFieldFilter extends DocumentFilter { - private final Window parent; - - public PTextFieldFilter(Window _parent) { - parent = _parent; + public PTextFieldFilter() { } @Override @@ -49,8 +46,6 @@ public void insertString(FilterBypass fb, int offset, String insert, if (test(sb.toString())) { super.insertString(fb, offset, insert, attr); - } else { - InfoBox.warning("Numbers Only", "This field allows only numeric values.", parent); } } @@ -82,8 +77,6 @@ public void replace(FilterBypass fb, int offset, int length, String text, if (test(sb.toString())) { super.replace(fb, offset, length, text, attrs); - } else { - InfoBox.warning("Numbers Only", "This field allows only numeric values.", parent); } } @@ -98,8 +91,6 @@ public void remove(FilterBypass fb, int offset, int length) if (test(sb.toString())) { super.remove(fb, offset, length); - } else { - InfoBox.warning("Numbers Only", "This field allows only numeric values.", parent); } } } diff --git a/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PTextPane.java b/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PTextPane.java index c066c759..77f91f75 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PTextPane.java +++ b/src/main/java/org/darisadesigns/polyglotlina/CustomControls/PTextPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019, Draque Thompson + * Copyright (c) 2016-2020, Draque Thompson, draquemail@gmail.com * All rights reserved. * * Licensed under: MIT Licence @@ -201,7 +201,7 @@ private void setupRightClickMenu() { insertImage.addActionListener((ActionEvent ae) -> { try { ImageNode image = core.getImageCollection() - .openNewImage((Window)parentPane.getTopLevelAncestor()); + .openNewImage((Window)parentPane.getTopLevelAncestor(), core.getWorkingDirectory()); if (image != null) { // null node means user cancelled process addImage(image); diff --git a/src/main/java/org/darisadesigns/polyglotlina/DictCore.java b/src/main/java/org/darisadesigns/polyglotlina/DictCore.java index ce96165d..efc150b4 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/DictCore.java +++ b/src/main/java/org/darisadesigns/polyglotlina/DictCore.java @@ -22,7 +22,6 @@ import java.awt.Desktop; import org.darisadesigns.polyglotlina.CustomControls.InfoBox; import org.darisadesigns.polyglotlina.CustomControls.PAlphaMap; -import org.darisadesigns.polyglotlina.CustomControls.PFrame; import org.darisadesigns.polyglotlina.ManagersCollections.PropertiesManager; import org.darisadesigns.polyglotlina.ManagersCollections.GrammarManager; import org.darisadesigns.polyglotlina.ManagersCollections.PronunciationMgr; @@ -273,7 +272,7 @@ public void pushUpdateWithCore(DictCore _core) { * * @return */ - public PFrame getRootWindow() { + public ScrMainMenu getRootWindow() { return rootWindow; } diff --git a/src/main/java/org/darisadesigns/polyglotlina/IOHandler.java b/src/main/java/org/darisadesigns/polyglotlina/IOHandler.java index d682956d..960fcbe5 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/IOHandler.java +++ b/src/main/java/org/darisadesigns/polyglotlina/IOHandler.java @@ -220,17 +220,18 @@ public static CustHandler getHandlerFromByteArray(byte[] byteArray, DictCore _co * cancels. * * @param parent parent window of operation + * @param workingDirectory * @return buffered image selected by user * @throws IOException on file read error */ - public static BufferedImage openImage(Window parent) throws IOException { + public static BufferedImage openImage(Window parent, File workingDirectory) throws IOException { BufferedImage ret = null; JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Select Image"); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "jpg", "jpeg", "tiff", "bmp", "png"); chooser.setFileFilter(filter); String fileName; - chooser.setCurrentDirectory(new File(".")); + chooser.setCurrentDirectory(workingDirectory); if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { fileName = chooser.getSelectedFile().getAbsolutePath(); diff --git a/src/main/java/org/darisadesigns/polyglotlina/ManagersCollections/ImageCollection.java b/src/main/java/org/darisadesigns/polyglotlina/ManagersCollections/ImageCollection.java index a8a51c08..b0861a20 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/ManagersCollections/ImageCollection.java +++ b/src/main/java/org/darisadesigns/polyglotlina/ManagersCollections/ImageCollection.java @@ -25,6 +25,7 @@ import org.darisadesigns.polyglotlina.PGTUtil; import java.awt.Window; import java.awt.image.BufferedImage; +import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; @@ -54,13 +55,14 @@ public ImageNode[] getAllImages() { * Pulls in new image from user selected file * Returns null if user cancels process * @param parent parent form + * @param workingDirectory * @return ImageNode inserted into collection with populated image * @throws IOException on file read error */ - public ImageNode openNewImage(Window parent) throws Exception { + public ImageNode openNewImage(Window parent, File workingDirectory) throws Exception { ImageNode image = null; try { - BufferedImage buffImg = IOHandler.openImage(parent); + BufferedImage buffImg = IOHandler.openImage(parent, workingDirectory); if (buffImg != null) { image = new ImageNode(); diff --git a/src/main/java/org/darisadesigns/polyglotlina/ManagersCollections/PropertiesManager.java b/src/main/java/org/darisadesigns/polyglotlina/ManagersCollections/PropertiesManager.java index 8401e546..a03483e9 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/ManagersCollections/PropertiesManager.java +++ b/src/main/java/org/darisadesigns/polyglotlina/ManagersCollections/PropertiesManager.java @@ -46,7 +46,7 @@ public class PropertiesManager { private Font conFont = null; private Integer conFontStyle = Font.PLAIN; - private Integer conFontSize = 12; + private double conFontSize = 12; private double localFontSize = 12; private final PAlphaMap alphaOrder; private String alphaPlainText = ""; @@ -216,7 +216,8 @@ public byte[] getCachedLocalFont() { } public void setFontFromFile(String fontPath) throws IOException, FontFormatException { - setFontCon(PFontHandler.getFontFromFile(fontPath).deriveFont(conFontStyle, conFontSize), conFontStyle, conFontSize); + setFontCon(PFontHandler.getFontFromFile(fontPath) + .deriveFont(conFontStyle, (float)conFontSize), conFontStyle, (float)conFontSize); cachedConFont = IOHandler.getFileByteArray(fontPath); } @@ -284,7 +285,7 @@ public boolean syncCachedFontCon() throws Exception { * @param _fontStyle The style of the font (bold, underlined, etc.) * @param _fontSize Size of font */ - public void setFontCon(Font _fontCon, Integer _fontStyle, Integer _fontSize) { + public void setFontCon(Font _fontCon, Integer _fontStyle, double _fontSize) { setFontConRaw(_fontCon); setFontSize(_fontSize); setFontStyle(_fontStyle); @@ -330,7 +331,7 @@ public Font getFontCon() { return retFont == null ? PGTUtil.CHARIS_UNICODE.deriveFont((float)core.getOptionsManager().getMenuFontSize()) : - retFont.deriveFont(conFontStyle, conFontSize); + retFont.deriveFont(conFontStyle, (float)conFontSize); } /** @@ -361,13 +362,13 @@ public Integer getFontStyle() { */ public void setFontStyle(Integer _fontStyle) { conFontStyle = _fontStyle; - conFont = conFont.deriveFont(conFontStyle, conFontSize); + conFont = conFont.deriveFont(conFontStyle, (float)conFontSize); } /** * @return the fontSize */ - public Integer getFontSize() { + public double getFontSize() { return conFontSize; } @@ -376,11 +377,9 @@ public Integer getFontSize() { * * @param _fontSize the fontSize to set */ - public void setFontSize(Integer _fontSize) { - if (_fontSize != null) { - conFontSize = _fontSize < 0 ? 12 : _fontSize; - conFont = conFont.deriveFont(conFontStyle, conFontSize); - } + public void setFontSize(double _fontSize) { + conFontSize = _fontSize < 0 ? 12 : _fontSize; + conFont = conFont.deriveFont(conFontStyle, (float)conFontSize); } /** @@ -571,7 +570,7 @@ public void writeXML(Document doc, Element rootElement) { // store font size wordValue = doc.createElement(PGTUtil.LANG_PROP_FONT_SIZE_XID); - wordValue.appendChild(doc.createTextNode(conFontSize.toString())); + wordValue.appendChild(doc.createTextNode(Double.toString(conFontSize))); propContainer.appendChild(wordValue); // store font size for local language font @@ -800,7 +799,7 @@ public void refreshFonts() throws Exception { if (updatedConFont != null) { conFont = PFontHandler.getFontFromFile(updatedConFont.getAbsolutePath()); - conFont = conFont.deriveFont(conFontStyle, conFontSize); + conFont = conFont.deriveFont(conFontStyle, (float)conFontSize); cachedConFont = IOHandler.getByteArrayFromFile(updatedConFont); } @@ -839,7 +838,7 @@ public boolean equals(Object comp) { PropertiesManager prop = (PropertiesManager) comp; ret = ((conFont == null) && (prop.conFont == null)) || conFont.equals(prop.conFont); ret = ret && conFontStyle.equals(prop.conFontStyle); - ret = ret && conFontSize.equals(prop.conFontSize); + ret = ret && conFontSize == prop.conFontSize; ret = ret && localFontSize == prop.localFontSize; ret = ret && alphaPlainText.equals(prop.alphaPlainText); ret = ret && langName.equals(prop.langName); diff --git a/src/main/java/org/darisadesigns/polyglotlina/PGoogleBarChart.java b/src/main/java/org/darisadesigns/polyglotlina/PGoogleBarChart.java index 739405d2..7a84d070 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/PGoogleBarChart.java +++ b/src/main/java/org/darisadesigns/polyglotlina/PGoogleBarChart.java @@ -36,7 +36,7 @@ public String getLeftYAxisLabel() { } /** - * @param leftYAxisLabel the leftYAxisLabel to set + * @param _leftYAxisLabel the leftYAxisLabel to set */ public void setLeftYAxisLabel(String _leftYAxisLabel) { this.leftYAxisLabel = _leftYAxisLabel; @@ -50,7 +50,7 @@ public String getRightYAxisLabel() { } /** - * @param rightYAxisLabel the rightYAxisLabel to set + * @param _rightYAxisLabel the rightYAxisLabel to set */ public void setRightYAxisLabel(String _rightYAxisLabel) { this.rightYAxisLabel = _rightYAxisLabel; @@ -75,7 +75,7 @@ public PGoogleBarChart(String _caption) { * subsequent set should have 1 label and n - 1 values. It will not display * otherwise. * - * @param labels + * @param _labels * @param values */ @Override @@ -166,14 +166,14 @@ public String getDisplayHTML() { } /** - * @param labels the labels to set + * @param _labels the labels to set */ public void setLabels(String[] _labels) { this.labels = _labels; } /** - * @param conFontName the conFontName to set + * @param _conFontName the conFontName to set */ public void setConFontName(String _conFontName) { this.conFontName = _conFontName; diff --git a/src/main/java/org/darisadesigns/polyglotlina/PLanguageStats.java b/src/main/java/org/darisadesigns/polyglotlina/PLanguageStats.java index e0b98596..746efadb 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/PLanguageStats.java +++ b/src/main/java/org/darisadesigns/polyglotlina/PLanguageStats.java @@ -90,7 +90,7 @@ private static String buildWordReport(DictCore core, ScrProgressMenu progress) { Map phonemeCount = new HashMap<>(); Map charCount = new HashMap<>(); Map phonemeCombo2 = new HashMap<>(); - ConWord wordList[] = core.getWordCollection().getWordNodes(); + ConWord[] wordList = core.getWordCollection().getWordNodes(); String allChars = core.getPropertiesManager().getAlphaPlainText(); String alphabet = core.getPropertiesManager().getAlphaPlainText(); diff --git a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrExcelImport.java b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrExcelImport.java index 002701b2..511509b9 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrExcelImport.java +++ b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrExcelImport.java @@ -35,7 +35,6 @@ import org.apache.commons.csv.CSVFormat; import org.darisadesigns.polyglotlina.CustomControls.PRadioButton; import org.darisadesigns.polyglotlina.ImportFileHelper.DuplicateOption; -import org.darisadesigns.polyglotlina.PGTUtil; /** * @@ -426,7 +425,7 @@ public static ScrExcelImport run(DictCore _core, ScrMainMenu _parent) { private void browseFile() { JFileChooser chooser = new JFileChooser(); - chooser.setCurrentDirectory(new File(".")); + chooser.setCurrentDirectory(core.getWorkingDirectory()); FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel/CSV Documents", "xls", "xlsx", "xlsm", "csv", "txt", "tsv"); chooser.setFileFilter(filter); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { diff --git a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrFontImportDialog.form b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrFontImportDialog.form new file mode 100644 index 00000000..b1979e1c --- /dev/null +++ b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrFontImportDialog.form @@ -0,0 +1,175 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrFontImportDialog.java b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrFontImportDialog.java new file mode 100644 index 00000000..02914706 --- /dev/null +++ b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrFontImportDialog.java @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2020, Draque Thompson, draquemail@gmail.com + * All rights reserved. + * + * Licensed under: MIT License + * See LICENSE.TXT included with this code to read the full license agreement. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package org.darisadesigns.polyglotlina.Screens; + +import java.awt.Font; +import java.awt.FontFormatException; +import java.io.IOException; +import javax.swing.JFileChooser; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.text.PlainDocument; +import org.darisadesigns.polyglotlina.CustomControls.InfoBox; +import org.darisadesigns.polyglotlina.CustomControls.PButton; +import org.darisadesigns.polyglotlina.CustomControls.PDialog; +import org.darisadesigns.polyglotlina.CustomControls.PLabel; +import org.darisadesigns.polyglotlina.CustomControls.PTextField; +import org.darisadesigns.polyglotlina.CustomControls.PTextFieldFilter; +import org.darisadesigns.polyglotlina.DictCore; +import org.darisadesigns.polyglotlina.IOHandler; +import org.darisadesigns.polyglotlina.PFontHandler; + +/** + * + * @author draque + */ +public class ScrFontImportDialog extends PDialog { + + /** + * Creates new form ScrFontImportDialog + * + * @param _core + */ + public ScrFontImportDialog(DictCore _core) { + super(_core); + this.setModal(true); + initComponents(); + + txtFontSize.setText(Double.toString(core.getPropertiesManager().getFontSize())); + ((PlainDocument) txtFontSize.getDocument()) + .setDocumentFilter(new PTextFieldFilter()); + txtFontSize.getDocument().addDocumentListener(new DocumentListener() { + public void insertUpdate(DocumentEvent e) { + updateDisplayFont(); + } + + public void removeUpdate(DocumentEvent e) { + updateDisplayFont(); + } + + public void changedUpdate(DocumentEvent e) { + updateDisplayFont(); + } + }); + + txtFontLocation.getDocument().addDocumentListener(new DocumentListener() { + public void insertUpdate(DocumentEvent e) { + updateDisplayFont(); + } + + public void removeUpdate(DocumentEvent e) { + updateDisplayFont(); + } + + public void changedUpdate(DocumentEvent e) { + updateDisplayFont(); + } + }); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + btnOk = new PButton(); + btnCancel = new PButton(); + jPanel1 = new javax.swing.JPanel(); + txtFontLocation = new PTextField(core, true, "-- Font File --"); + btnSelectFOnt = new PButton(); + jLabel1 = new PLabel("Font Size", core.getOptionsManager().getMenuFontSize()); + txtFontSize = new PTextField(core, true, ""); + txtDemoText = new PTextField(core, false, ""); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Select Font to Import"); + + btnOk.setText("OK"); + btnOk.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnOkActionPerformed(evt); + } + }); + + btnCancel.setText("Cancel"); + btnCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnCancelActionPerformed(evt); + } + }); + + jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); + + txtFontLocation.setEditable(false); + + btnSelectFOnt.setText("Select Font"); + btnSelectFOnt.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnSelectFOntActionPerformed(evt); + } + }); + + jLabel1.setText("Font Size"); + + txtDemoText.setHorizontalAlignment(javax.swing.JTextField.CENTER); + txtDemoText.setText("Demo Text"); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(txtFontLocation) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnSelectFOnt)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(txtFontSize, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE)))) + .addComponent(txtDemoText)) + .addContainerGap()) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(txtFontLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(btnSelectFOnt)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(txtFontSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(txtDemoText, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE) + .addContainerGap()) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(343, Short.MAX_VALUE) + .addComponent(btnCancel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnOk) + .addContainerGap()) + .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(btnOk) + .addComponent(btnCancel)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed + String fileName = txtFontLocation.getText(); + + try { + core.getPropertiesManager().setFontFromFile(fileName); + core.getPropertiesManager().setFontSize(Double.valueOf(txtFontSize.getText())); + core.getRootWindow().selectFirstAvailableButton(); + dispose(); + } catch (IOException e) { + InfoBox.error("IO Error", "Unable to open " + fileName + " due to: " + e.getLocalizedMessage(), core.getRootWindow()); + } catch (FontFormatException e) { + IOHandler.writeErrorLog(e); + InfoBox.error("Font Format Error", "Unable to read " + fileName + " due to: " + + e.getLocalizedMessage(), this); + } + }//GEN-LAST:event_btnOkActionPerformed + + private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed + this.dispose(); + }//GEN-LAST:event_btnCancelActionPerformed + + private void btnSelectFOntActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectFOntActionPerformed + JFileChooser chooser = new JFileChooser(); + FileNameExtensionFilter filter = new FileNameExtensionFilter("Font Files", "ttf", "otf", "ttc", "dfont"); + + chooser.setDialogTitle("Select Font File"); + chooser.setFileFilter(filter); + chooser.setCurrentDirectory(core.getWorkingDirectory()); + chooser.setApproveButtonText("Open"); + + if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { + txtFontLocation.setText(chooser.getSelectedFile().getAbsolutePath()); + } + }//GEN-LAST:event_btnSelectFOntActionPerformed + + private void updateDisplayFont() { + if (!txtFontLocation.getText().isBlank()) { + try { + Font newFont = PFontHandler.getFontFromFile(txtFontLocation.getText()); + txtDemoText.setFont(newFont.deriveFont(Float.parseFloat(txtFontSize.getText()))); + } catch (FontFormatException | IOException e) { + InfoBox.error("Font Load Error", "Unable to load font: " + e.getLocalizedMessage(), this); + } + } + } + + @Override + public void updateAllValues(DictCore _core) { + // nothing to update + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnCancel; + private javax.swing.JButton btnOk; + private javax.swing.JButton btnSelectFOnt; + private javax.swing.JLabel jLabel1; + private javax.swing.JPanel jPanel1; + private javax.swing.JTextField txtDemoText; + private javax.swing.JTextField txtFontLocation; + private javax.swing.JTextField txtFontSize; + // End of variables declaration//GEN-END:variables +} diff --git a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrLogoDetails.java b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrLogoDetails.java index a7083a21..af48f4c9 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrLogoDetails.java +++ b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrLogoDetails.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019, Draque Thompson, draquemail@gmail.com + * Copyright (c) 2014-2020, Draque Thompson, draquemail@gmail.com * All rights reserved. * * Licensed under: MIT Licence @@ -51,7 +51,6 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.concurrent.CountDownLatch; import javafx.application.Platform; @@ -666,7 +665,7 @@ private void populateRelatedWords() { LogoNode curNode = (LogoNode) lstLogos.getSelectedValue(); if (curNode == null) { - lstRelWords.setModel(new DefaultListModel()); + lstRelWords.setModel(new DefaultListModel<>()); return; } @@ -785,7 +784,7 @@ private void populateLogographs() { /** * Populates logographs based on iterator * - * @param it iterator of all logographs to populate + * @param logoNodes all logographs to populate */ private void populateLogographs(LogoNode[] logoNodes) { DefaultListModel logoModel = new DefaultListModel<>(); @@ -824,9 +823,9 @@ private void populateLogoProps(int index) { txtName.setText(""); txtNotes.setText(""); txtStrokes.setText(""); - lstRadicals.setModel(new DefaultListModel()); + lstRadicals.setModel(new DefaultListModel<>()); tblReadings.setModel(new DefaultTableModel(new Object[]{"Readings"}, 0)); - lstRelWords.setModel(new DefaultListModel()); + lstRelWords.setModel(new DefaultListModel<>()); chkIsRad.setSelected(false); lblLogo.setIcon(new ImageIcon(new LogoNode().getLogoGraph().getScaledInstance( lblLogo.getWidth(), lblLogo.getHeight(), Image.SCALE_SMOOTH))); @@ -902,7 +901,7 @@ private void openImage() { "BMP", "bmp", "jpeg", "wbmp", "gif", "GIF", "png", "JPG", "jpg", "WBMP", "JPEG", "PNG"); chooser.setFileFilter(filter); String fileName; - chooser.setCurrentDirectory(new File(".")); + chooser.setCurrentDirectory(core.getWorkingDirectory()); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { fileName = chooser.getSelectedFile().getAbsolutePath(); diff --git a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrMainMenu.java b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrMainMenu.java index ff586da0..aba2916e 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrMainMenu.java +++ b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrMainMenu.java @@ -34,7 +34,6 @@ import java.awt.Cursor; import java.awt.Desktop; import java.awt.Dimension; -import java.awt.FontFormatException; import java.awt.Frame; import java.awt.Graphics; import java.awt.GraphicsEnvironment; @@ -107,8 +106,11 @@ public final class ScrMainMenu extends PFrame { /** * Creates new form ScrMainMenu * + * Note: Single time setup per app run requires handing self to other objects + * * @param _core DictCore menus run on */ + @SuppressWarnings("LeakingThisInConstructor") public ScrMainMenu(DictCore _core) { super(_core); @@ -725,7 +727,7 @@ public void exportFont(boolean exportCharis) { chooser.setDialogTitle("Export Font"); chooser.setFileFilter(filter); - chooser.setCurrentDirectory(new File(".")); + chooser.setCurrentDirectory(core.getWorkingDirectory()); chooser.setApproveButtonText("Save"); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { @@ -1968,41 +1970,7 @@ public void showOptions() { } private void mnuImportFontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuImportFontActionPerformed - JFileChooser chooser = new JFileChooser(); - String fileName; - FileNameExtensionFilter filter = new FileNameExtensionFilter("Font Files", "ttf", "otf", "ttc", "dfont"); - - chooser.setDialogTitle("Import Font"); - chooser.setFileFilter(filter); - chooser.setCurrentDirectory(new File(".")); - chooser.setApproveButtonText("Open"); - - if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - fileName = chooser.getSelectedFile().getAbsolutePath(); - } else { - return; - } - - Double fontSize = InfoBox.doubleInputDialog("Font Size", - "Enter a numeric value for font size.", - "Please provide a numeric value (default 12.0) for font size.", - this); - - if (fontSize == null) { - return; - } - - try { - core.getPropertiesManager().setFontFromFile(fileName); - core.getPropertiesManager().setFontSize(fontSize.intValue()); - this.selectFirstAvailableButton(); - } catch (IOException e) { - InfoBox.error("IO Error", "Unable to open " + fileName + " due to: " + e.getLocalizedMessage(), this); - } catch (FontFormatException e) { - IOHandler.writeErrorLog(e); - InfoBox.error("Font Format Error", "Unable to read " + fileName + " due to: " - + e.getLocalizedMessage(), this); - } + new ScrFontImportDialog(core).setVisible(true); }//GEN-LAST:event_mnuImportFontActionPerformed private void btnQuizActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuizActionPerformed diff --git a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrOptions.java b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrOptions.java index 7a22130f..49055f86 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrOptions.java +++ b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrOptions.java @@ -107,7 +107,7 @@ public boolean testWarnClose() { private void setOptions() { ((PlainDocument) txtTextFontSize.getDocument()) - .setDocumentFilter(new PTextFieldFilter(core.getRootWindow())); + .setDocumentFilter(new PTextFieldFilter()); chkResize.setSelected(core.getOptionsManager().isAnimateWindows()); chkNightMode.setSelected(core.getOptionsManager().isNightMode()); diff --git a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrPrintToPDF.java b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrPrintToPDF.java index f737d9ec..3bef6d41 100644 --- a/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrPrintToPDF.java +++ b/src/main/java/org/darisadesigns/polyglotlina/Screens/ScrPrintToPDF.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019, Draque Thompson, draquemail@gmail.com + * Copyright (c) 2016-2020, Draque Thompson, draquemail@gmail.com * All rights reserved. * * Licensed under: MIT Licence @@ -311,7 +311,7 @@ private void btnSelectSavePathActionPerformed(java.awt.event.ActionEvent evt) {/ FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Documents", "pdf"); chooser.setFileFilter(filter); chooser.setApproveButtonText("Save"); - chooser.setCurrentDirectory(new File(".")); + chooser.setCurrentDirectory(core.getWorkingDirectory()); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String fileName = chooser.getSelectedFile().getAbsolutePath(); @@ -333,7 +333,7 @@ private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS } if (new File(txtSavePath.getText()).exists() - && InfoBox.actionConfirmation("Overwrite Confirmation", "File already exists. Overwrite?", this)) { + && !InfoBox.actionConfirmation("Overwrite Confirmation", "File already exists. Overwrite?", this)) { return; } @@ -381,7 +381,7 @@ private void btnSelectImagePathActionPerformed(java.awt.event.ActionEvent evt) { "BMP", "bmp", "jpeg", "wbmp", "gif", "GIF", "png", "JPG", "jpg", "WBMP", "JPEG", "PNG"); chooser.setFileFilter(filter); String fileName; - chooser.setCurrentDirectory(new File(".")); + chooser.setCurrentDirectory(core.getWorkingDirectory()); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { fileName = chooser.getSelectedFile().getAbsolutePath();