diff --git a/src/net/apocalypselabs/symat/CodeEditor.java b/src/net/apocalypselabs/symat/CodeEditor.java index 1d42b1e..af756ee 100644 --- a/src/net/apocalypselabs/symat/CodeEditor.java +++ b/src/net/apocalypselabs/symat/CodeEditor.java @@ -52,8 +52,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; @@ -175,17 +173,10 @@ public class CodeEditor extends javax.swing.JInternalFrame { } private void loadTheme() { - if (PrefStorage.getSetting("theme").equals("dark")) { - outputBox.setBackground(new Color(41, 49, 52)); - outputBox.setForeground(Color.WHITE); - setBackground(Color.DARK_GRAY); - setEditorTheme("dark"); - } else { - outputBox.setBackground(Color.WHITE); - outputBox.setForeground(Color.BLACK); - setBackground(Color.LIGHT_GRAY); - setEditorTheme("default"); - } + outputBox.setBackground(net.apocalypselabs.symat.Theme.boxColor()); + outputBox.setForeground(net.apocalypselabs.symat.Theme.textColor()); + setBackground(net.apocalypselabs.symat.Theme.windowColor()); + setEditorTheme(net.apocalypselabs.symat.Theme.editorTheme()); } /** @@ -799,7 +790,7 @@ public class CodeEditor extends javax.swing.JInternalFrame { }//GEN-LAST:event_shareMenuActionPerformed private void shareAsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shareAsMenuActionPerformed - String id = JOptionPane.showInternalInputDialog(this, + String id = JOptionPane.showInternalInputDialog(this, "Enter the pad ID to share to. " + "If the pad exists, it will be overwritten.", "Share", @@ -826,7 +817,7 @@ public class CodeEditor extends javax.swing.JInternalFrame { JOptionPane.ERROR_MESSAGE); } } - + /** * Open a sample code file with the given name.

* Uses the current language. diff --git a/src/net/apocalypselabs/symat/Display.java b/src/net/apocalypselabs/symat/Display.java index 1c38be7..7310940 100644 --- a/src/net/apocalypselabs/symat/Display.java +++ b/src/net/apocalypselabs/symat/Display.java @@ -56,6 +56,7 @@ public class Display extends javax.swing.JInternalFrame { */ public Display() { initComponents(); + setBackground(Theme.windowColor()); } /** @@ -176,9 +177,9 @@ public class Display extends javax.swing.JInternalFrame { private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBtnActionPerformed if (themeDark.isSelected()) { - PrefStorage.saveSetting("theme", "dark"); + Theme.setTheme("dark"); } else { - PrefStorage.saveSetting("theme", "light"); + Theme.setTheme("light"); } if (showRecent.isSelected()) { PrefStorage.saveSetting("showrecent", ""); diff --git a/src/net/apocalypselabs/symat/Interpreter.java b/src/net/apocalypselabs/symat/Interpreter.java index 2cdeefa..ebd93e1 100644 --- a/src/net/apocalypselabs/symat/Interpreter.java +++ b/src/net/apocalypselabs/symat/Interpreter.java @@ -313,19 +313,11 @@ public class Interpreter extends javax.swing.JInternalFrame { }//GEN-LAST:event_runBtnActionPerformed private void loadTheme() { - if (PrefStorage.getSetting("theme").equals("dark")) { - mainBox.setBackground(new Color(41, 49, 52)); - mainBox.setForeground(Color.WHITE); - inputBox.setBackground(new Color(41, 49, 52)); - inputBox.setForeground(Color.WHITE); - setBackground(Color.DARK_GRAY); - } else { - mainBox.setBackground(Color.WHITE); - mainBox.setForeground(Color.BLACK); - inputBox.setBackground(Color.WHITE); - inputBox.setForeground(Color.BLACK); - setBackground(Color.LIGHT_GRAY); - } + mainBox.setBackground(Theme.boxColor()); + mainBox.setForeground(Theme.textColor()); + inputBox.setBackground(Theme.boxColor()); + inputBox.setForeground(Theme.textColor()); + setBackground(Theme.windowColor()); } private void inputBoxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_inputBoxKeyTyped diff --git a/src/net/apocalypselabs/symat/MainGUI.java b/src/net/apocalypselabs/symat/MainGUI.java index 6d2241b..099e956 100644 --- a/src/net/apocalypselabs/symat/MainGUI.java +++ b/src/net/apocalypselabs/symat/MainGUI.java @@ -257,15 +257,9 @@ public class MainGUI extends javax.swing.JFrame { public static void updateDisplay() { mainPane.paintImmediately(0, 0, mainPane.getWidth(), mainPane.getHeight()); - if (PrefStorage.getSetting("theme").equals("dark")) { - tabs.setBackground(new Color(41, 49, 52)); - recentFileList.setForeground(Color.white); - recentFileList.setBackground(new Color(41, 49, 52)); - } else { - tabs.setBackground(new Color(240, 240, 240)); - recentFileList.setForeground(Color.black); - recentFileList.setBackground(Color.white); - } + tabs.setBackground(Theme.tabColor()); + recentFileList.setForeground(Theme.textColor()); + recentFileList.setBackground(Theme.boxColor()); if (!PrefStorage.getSetting("showrecent", "").equals("")) { recentItemsPanel.setVisible(false); } else { diff --git a/src/net/apocalypselabs/symat/Notepad.form b/src/net/apocalypselabs/symat/Notepad.form index aea084b..b5853ce 100644 --- a/src/net/apocalypselabs/symat/Notepad.form +++ b/src/net/apocalypselabs/symat/Notepad.form @@ -20,17 +20,6 @@ - - - - - - - - - - - @@ -45,7 +34,6 @@ - @@ -89,6 +77,11 @@ + + + + + diff --git a/src/net/apocalypselabs/symat/Notepad.java b/src/net/apocalypselabs/symat/Notepad.java index f2ded17..616efde 100644 --- a/src/net/apocalypselabs/symat/Notepad.java +++ b/src/net/apocalypselabs/symat/Notepad.java @@ -61,9 +61,14 @@ public class Notepad extends javax.swing.JInternalFrame { */ public Notepad() { initComponents(); + updateTheme(); textBox.setText(PrefStorage.getSetting("notepad")); } + private void updateTheme() { + + } + /** * 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 @@ -78,7 +83,6 @@ public class Notepad extends javax.swing.JInternalFrame { jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); eraseBtn = new javax.swing.JMenuItem(); - saveBtn = new javax.swing.JMenuItem(); setClosable(true); setIconifiable(true); @@ -89,6 +93,7 @@ public class Notepad extends javax.swing.JInternalFrame { jScrollPane4.setFont(Font.getFont(Font.MONOSPACED)); + textBox.setBackground(new java.awt.Color(255, 255, 204)); textBox.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { textBoxKeyTyped(evt); @@ -107,15 +112,6 @@ public class Notepad extends javax.swing.JInternalFrame { }); jMenu1.add(eraseBtn); - saveBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK)); - saveBtn.setText("Save"); - saveBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - saveBtnActionPerformed(evt); - } - }); - jMenu1.add(saveBtn); - jMenuBar1.add(jMenu1); setJMenuBar(jMenuBar1); @@ -138,26 +134,23 @@ public class Notepad extends javax.swing.JInternalFrame { int ans = JOptionPane.showInternalConfirmDialog(this, "Erase notepad contents?", "Are you sure?", JOptionPane.YES_NO_OPTION); if (ans == JOptionPane.YES_OPTION) { textBox.setText(""); - setTitle("Notepad *"); + save(); } }//GEN-LAST:event_eraseBtnActionPerformed - private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBtnActionPerformed - PrefStorage.saveSetting("notepad", textBox.getText()); - setTitle("Notepad"); - }//GEN-LAST:event_saveBtnActionPerformed - private void textBoxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textBoxKeyTyped - setTitle("Notepad *"); + save(); }//GEN-LAST:event_textBoxKeyTyped + private void save() { + PrefStorage.saveSetting("notepad", textBox.getText()); + } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JMenuItem eraseBtn; private javax.swing.JMenu jMenu1; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JScrollPane jScrollPane4; - private javax.swing.JMenuItem saveBtn; private javax.swing.JEditorPane textBox; // End of variables declaration//GEN-END:variables } diff --git a/src/net/apocalypselabs/symat/Pads.form b/src/net/apocalypselabs/symat/Pads.form index d583de6..fdb7fa2 100644 --- a/src/net/apocalypselabs/symat/Pads.form +++ b/src/net/apocalypselabs/symat/Pads.form @@ -17,6 +17,9 @@ + + + diff --git a/src/net/apocalypselabs/symat/Pads.java b/src/net/apocalypselabs/symat/Pads.java index 503535c..d81b64f 100644 --- a/src/net/apocalypselabs/symat/Pads.java +++ b/src/net/apocalypselabs/symat/Pads.java @@ -45,6 +45,7 @@ */ package net.apocalypselabs.symat; +import java.awt.Color; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -66,9 +67,18 @@ public class Pads extends javax.swing.JInternalFrame { */ public Pads() { initComponents(); + updateTheme(); padPane.setListData(getPads()); } + private void updateTheme() { + padPane.setBackground(Theme.boxColor()); + padPane.setForeground(Theme.textColor()); + previewPane.setBackground(Theme.boxColor()); + previewPane.setForeground(Theme.textColor()); + setBackground(Theme.windowColor()); + } + /** * Add the given pad ID to the local pad list. * @@ -283,6 +293,11 @@ public class Pads extends javax.swing.JInternalFrame { setTitle("Collaboration"); setMinimumSize(new java.awt.Dimension(450, 280)); setPreferredSize(new java.awt.Dimension(450, 280)); + addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseEntered(java.awt.event.MouseEvent evt) { + formMouseEntered(evt); + } + }); padPane.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); padPane.addListSelectionListener(new javax.swing.event.ListSelectionListener() { @@ -494,6 +509,10 @@ public class Pads extends javax.swing.JInternalFrame { JOptionPane.PLAIN_MESSAGE); }//GEN-LAST:event_shareBtnActionPerformed + private void formMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseEntered + updateTheme(); + }//GEN-LAST:event_formMouseEntered + private String getSelectedPad() { return padPane.getSelectedValue().toString(); } diff --git a/src/net/apocalypselabs/symat/Theme.java b/src/net/apocalypselabs/symat/Theme.java new file mode 100644 index 0000000..c543fcf --- /dev/null +++ b/src/net/apocalypselabs/symat/Theme.java @@ -0,0 +1,136 @@ +/* + * CODE LICENSE ===================== + * Copyright (c) 2015, Apocalypse Laboratories + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * 4. You adhere to the Media License detailed below. If you do not, this license + * is automatically revoked and you must purge all copies of the software you + * possess, in source or binary form. + * + * 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. + * + * MEDIA LICENSE ==================== + * All images and other graphical files (the "graphics") included with this + * software are copyright (c) 2015 Apocalypse Laboratories. You may not distribute + * the graphics or any program, source code repository, or other digital storage + * media containing them without written permission from Apocalypse Laboratories. + * This ban on distribution only applies to publicly available systems. + * A password-protected network file share, USB drive, or other storage scheme that + * cannot be easily accessed by the public is generally allowed. If in doubt, + * contact Apocalypse Laboratories. If Apocalypse Laboratories allows or denies + * you permission, that decision is considered final and binding. + */ +package net.apocalypselabs.symat; + +import java.awt.Color; + +/** + * Handles theme colors and giving them out. + * + * @author Skylar + */ +public class Theme { + + // Theme colors. + private static final Color WHITE = Color.WHITE; + private static final Color BLACK = Color.BLACK; + private static final Color DBACK = new Color(41, 49, 52); + private static final Color LBACK = new Color(240,240,240); + private static final Color DGRAY = Color.DARK_GRAY; + private static final Color LGRAY = Color.LIGHT_GRAY; + + /** + * Light theme. + */ + public static final int THEME_LIGHT = 0; + /** + * Dark theme. + */ + public static final int THEME_DARK = 1; + + /** + * The current theme. + */ + public static int currentTheme = (PrefStorage.getSetting("theme") + .equals("dark") ? 1 : 0); + + /** + * Set the theme for the application. + * + * @param theme the theme id number. + */ + public static void setTheme(int theme) { + switch (theme) { + case THEME_DARK: + PrefStorage.saveSetting("theme", "dark"); + break; + case THEME_LIGHT: + default: + PrefStorage.saveSetting("theme", "light"); + } + currentTheme = theme; + } + + /** + * Set the theme for the application. + * + * @param theme The theme name, either "light" or "dark". + */ + public static void setTheme(String theme) { + switch (theme) { + case "dark": + setTheme(THEME_DARK); + break; + case "light": + default: + setTheme(THEME_LIGHT); + } + } + + public static String getTheme() { + return (currentTheme == THEME_LIGHT) ? "light" : "dark"; + } + + public static Color textColor() { + return (currentTheme == THEME_LIGHT) ? BLACK : WHITE; + } + + public static Color boxColor() { + return (currentTheme == THEME_LIGHT) ? WHITE : DBACK; + } + + public static Color windowColor() { + return (currentTheme == THEME_LIGHT) ? LGRAY : DGRAY; + } + + public static Color tabColor() { + return (currentTheme == THEME_LIGHT) ? LBACK : DBACK; + } + + public static String editorTheme() { + return (currentTheme == THEME_LIGHT) ? "default" : "dark"; + } +}