/*
* (c) Copyright 2009 Tim Jenkins
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* ITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package com.screenrunner.ui;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.ListCellRenderer;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.MatteBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.screenrunner.ui.Display;
import com.screenrunner.ScreenRunner;
import com.screenrunner.data.I18n;
import com.screenrunner.data.Displayable;
import com.screenrunner.data.ImageSlide;
import com.screenrunner.data.Playlist;
import com.screenrunner.data.PlaylistPage;
import com.screenrunner.data.ScripturePassage;
import com.screenrunner.data.Song;
import com.screenrunner.data.Style;
public class MainWindow {
public JFrame rootFrame;
public JPanel contentPanel;
public JRadioButtonMenuItem modeSongEditorCommand;
public JRadioButtonMenuItem modePlaylistEditorCommand;
public JRadioButtonMenuItem modePresentationCommand;
public JToggleButton songEditorModeButton;
public JToggleButton playlistEditorModeButton;
public JToggleButton presentationModeButton;
public JMenu songMenu;
public JMenu playlistMenu;
public JMenu presentationMenu;
public JCheckBox songEditorShowAdvancedCheckbox;
public JPanel songEditorAdvanced1;
public JPanel songEditorAdvanced2;
public JPanel songEditorAdvanced3;
public JTextField songEditorTitleField;
public JTextField songEditorAuthorField;
public JTextField songEditorCopyrightField;
public JTextField songEditorCcliField;
public JTextField songEditorPresentationField;
public JTextField songEditorHymnField;
public JTextArea songEditorLyricsArea;
public JComboBox songEditorCapoCombo;
public JTextField songEditorKeyField;
public JTextField songEditorAkaField;
public JComboBox songEditorTimeSigCombo;
public JComboBox songEditorTempoCombo;
public JTextField songEditorKeyLineField;
public JComboBox songEditorUserSelectorCombo;
public JTextArea songEditorUser1Area;
public JTextArea songEditorUser2Area;
public JTextArea songEditorUser3Area;
public String songEditorCurrentSong;
public JButton songEditorThemesButton;
public JPanel songEditorUserAreas;
private Vector<String> songEditorThemeList;
private boolean songEditorIsModified = false;
public JButton songEditorSaveButton;
public JButton songEditorSaveAsButton;
public JButton songEditorInsertButton;
public JButton songEditorRevertButton;
public JButton playlistEditorSaveButton;
public JButton playlistEditorSaveAsButton;
public JButton playlistEditorInsertButton;
public JButton playlistEditorMoveUpButton;
public JButton playlistEditorMoveDownButton;
public JButton playlistEditorRemoveButton;
public JTextField playlistEditorTitleField;
public JList playlistEditorItemList;
public JMenuItem playlistEditorSaveCommand;
public JMenuItem playlistEditorSaveAsCommand;
public JMenuItem playlistEditorMoveUpCommand;
public JMenuItem playlistEditorModeDownCommand;
public JMenuItem playlistEditorRemoveCommand;
public JMenuItem playlistEditorInsertSongCommand;
public JMenuItem playlistEditorInsertScriptureCommand;
public JMenuItem playlistEditorInsertCustomCommand;
public JMenuItem playlistEditorInsertMediaCommand;
public JMenuItem playlistEditorInsertStyleCommand;
private boolean playlistEditorIsModified = false;
public JRadioButtonMenuItem presentDisplayOffCommand;
public JRadioButtonMenuItem presentDisplayNormalCommand;
public JRadioButtonMenuItem presentDisplayBackgroundCommand;
public JRadioButtonMenuItem presentDisplayBlackCommand;
public JRadioButtonMenuItem presentDisplayLogoCommand;
public JToggleButton presentDisplayLockCommand;
public JToggleButton presentDisplayOffButton;
public JToggleButton presentDisplayNormalButton;
public JToggleButton presentDisplayBackgroundButton;
public JToggleButton presentDisplayBlackButton;
public JToggleButton presentDisplayLogoButton;
public JToggleButton presentDisplayLockButton;
public JPanel presentationPreviewPanel;
public JComboBox presentScreenModeCombo;
public JList presentationSlideList;
private boolean ignoreChanges = false;
public MainWindow() {
ignoreChanges = true;
}
public void initWindow() {
songEditorTitleField.getDocument().addDocumentListener(songEditorText);
songEditorAuthorField.getDocument().addDocumentListener(songEditorText);
songEditorCopyrightField.getDocument().addDocumentListener(songEditorText);
songEditorCcliField.getDocument().addDocumentListener(songEditorText);
songEditorPresentationField.getDocument().addDocumentListener(songEditorText);
songEditorHymnField.getDocument().addDocumentListener(songEditorText);
songEditorLyricsArea.getDocument().addDocumentListener(songEditorText);
songEditorKeyField.getDocument().addDocumentListener(songEditorText);
songEditorAkaField.getDocument().addDocumentListener(songEditorText);
songEditorKeyLineField.getDocument().addDocumentListener(songEditorText);
songEditorUser1Area.getDocument().addDocumentListener(songEditorText);
songEditorUser2Area.getDocument().addDocumentListener(songEditorText);
songEditorUser3Area.getDocument().addDocumentListener(songEditorText);
songEditorCapoCombo.setModel(new DefaultComboBoxModel(I18n.getAll("song/capos/capo")));
songEditorTimeSigCombo.setModel(new DefaultComboBoxModel(I18n.getAll("song/timesigs/sig")));
songEditorTempoCombo.setModel(new DefaultComboBoxModel(I18n.getAll("song/tempos/tempo")));
songEditorCapoCombo.setPreferredSize(new Dimension(songEditorCapoCombo.getPreferredSize().width + 10, songEditorCapoCombo.getPreferredSize().height));
songEditorCapoCombo.setMinimumSize(songEditorCapoCombo.getPreferredSize());
songEditorTimeSigCombo.setPreferredSize(new Dimension(songEditorTimeSigCombo.getPreferredSize().width + 10, songEditorTimeSigCombo.getPreferredSize().height));
songEditorTimeSigCombo.setMinimumSize(songEditorTimeSigCombo.getPreferredSize());
songEditorTempoCombo.setPreferredSize(new Dimension(songEditorTempoCombo.getPreferredSize().width + 10, songEditorTempoCombo.getPreferredSize().height));
songEditorTempoCombo.setMinimumSize(songEditorTempoCombo.getPreferredSize());
playlistEditorTitleField.getDocument().addDocumentListener(playlistEditorText);
playlistEditorItemList.setModel(ScreenRunner.playlist.getItemsModel());
playlistEditorItemList.setCellRenderer(playlistCellRenderer);
presentationSlideList.setModel(ScreenRunner.playlist.getPagesModel());
presentationSlideList.setCellRenderer(pageCellRenderer);
presentationPreviewPanel.setLayout(new BorderLayout());
presentScreenModeCombo.setModel(new DefaultComboBoxModel(new String[] {"Single", "Preview Dual", "Dual"}));
presentScreenModeCombo.setSelectedIndex(Display.getWindowMode());
presentScreenModeCombo.setActionCommand("screenmode");
presentScreenModeCombo.addActionListener(presentationDispMode);
ignoreChanges = false;
}
public ActionListener modeActions = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
boolean songEditor = false, playlistEditor = false, presentation = false;
String cmd = e.getActionCommand();
if(cmd.equalsIgnoreCase("modesongeditor")) {
songEditor = true;
}
else if(cmd.equalsIgnoreCase("modeplaylisteditor")) {
playlistEditor = true;
}
else if(cmd.equalsIgnoreCase("modepresentation")) {
presentation = true;
}
else {
System.out.println("FIXME: Unhandled action: '" + cmd + "'");
return;
}
modeSongEditorCommand.setSelected(songEditor);
modePlaylistEditorCommand.setSelected(playlistEditor);
modePresentationCommand.setSelected(presentation);
songEditorModeButton.setSelected(songEditor);
playlistEditorModeButton.setSelected(playlistEditor);
presentationModeButton.setSelected(presentation);
songMenu.setVisible(songEditor);
playlistMenu.setVisible(playlistEditor);
presentationMenu.setVisible(presentation);
CardLayout l = (CardLayout)contentPanel.getLayout();
l.show(contentPanel, cmd);
if(presentation) {
presentationRefreshDisplay();
}
}
};
public ActionListener actions = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.equals("exit")) {
rootFrame.setVisible(false);
System.exit(0);
}
if(cmd.equals("prefs")) {
showPrefsDialog();
}
else {
System.out.println("FIXME: Unhandled action: '" + cmd + "'");
}
}
};
private void showPrefsDialog() {
PreferencesDialog dlg = new PreferencesDialog();
dlg.showDialog();
}
public ActionListener songEditorActions = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.equals("showadvanced")) {
boolean visible = songEditorShowAdvancedCheckbox.isSelected();
songEditorAdvanced1.setVisible(visible);
songEditorAdvanced2.setVisible(visible);
songEditorAdvanced3.setVisible(visible);
}
else if(cmd.equals("open")) {
if(!songEditorCheckModified()) return;
songEditorOpen();
}
else if(cmd.equals("new")) {
if(!songEditorCheckModified()) return;
songEditorNew();
}
else if(cmd.equals("saveas")) {
songEditorSaveAs();
}
else if(cmd.equals("save")) {
songEditorSave();
}
else if(cmd.equals("revert")) {
if(MessageBox.showDialog("Are you sure you want to revert to the last saved version?", "Confirm", "No", "Yes", null, MessageBox.ICON_QUESTION) == MessageBox.RESULT_BUTTON1) return;
loadSong();
}
else if(cmd.equals("insert")) {
songEditorInsert();
}
else if(cmd.equals("insertsection")) {
songEditorInsertSection();
}
else if(cmd.equals("insertmultiverse")) {
songEditorInsertVerses();
}
else if(cmd.equals("insertchordslyrics")) {
songEditorInsertChords();
}
else if(cmd.equals("insertpagebreak")) {
songEditorInsertPageBreak();
}
else if(cmd.equals("insertcomment")) {
songEditorInsertComment();
}
else if(cmd.equalsIgnoreCase("selectthemes")) {
showThemeSelector();
}
else if(cmd.equals("capo")) {
if(!ignoreChanges) {
setSongEditorModified(true);
}
}
else if(cmd.equals("tempo")) {
if(!ignoreChanges) {
setSongEditorModified(true);
}
}
else if(cmd.equals("timesig")) {
if(!ignoreChanges) {
setSongEditorModified(true);
}
}
else if(cmd.equalsIgnoreCase("userselectorchanged")) {
if(songEditorUserAreas == null || songEditorUserSelectorCombo == null) return;
CardLayout l = (CardLayout)songEditorUserAreas.getLayout();
String card = songEditorUserSelectorCombo.getSelectedItem().toString();
//System.out.println("selecting card: " + card);
l.show(songEditorUserAreas, card);
}
else {
System.out.println("FIXME: Unhandled action: '" + cmd + "'");
}
}
};
public DocumentListener songEditorText = new DocumentListener() {
@Override
public void changedUpdate(DocumentEvent e) {
setSongEditorModified(true);
}
@Override
public void insertUpdate(DocumentEvent e) {
setSongEditorModified(true);
}
@Override
public void removeUpdate(DocumentEvent e) {
setSongEditorModified(true);
}
};
private void songEditorInsert() {
showPopup(songEditorInsertButton, new Point(songEditorInsertButton.getWidth(), 0), songEditorActions, new String[] { "Section (Chorus, Verse, ...)", "Multiple Verses", "Chords / Lyrics", "Page Break", "Comment" }, new String[] { "insertsection", "insertmultiverse", "insertchordslyrics", "insertpagebreak", "insertcomment" });
}
private int songEditorCountVerses() {
BufferedReader lines = new BufferedReader(new StringReader(songEditorLyricsArea.getText()));
String line;
int count = 0;
try {
while((line = lines.readLine()) != null) {
if(line.startsWith("[V") || line.startsWith("[v")) {
count++;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return count;
}
private void songEditorInsertSection() {
try {
int section = OptionBox.showDialog("Type of section:", new String[] { "Verse", "Chorus", "Pre-Chorus", "Bridge", "Tag" }, "Insert Section", OptionBox.ICON_QUESTION);
String sname = "";
switch(section) {
case 0:
sname = "[V" + Integer.toString(songEditorCountVerses() + 1) + "]\n";
break;
case 1:
sname = "[C]\n";
break;
case 2:
sname = "[P]\n";
break;
case 3:
sname = "[B]\n";
break;
case 4:
sname = "[T]\n";
break;
default:
return;
}
int cpos = songEditorLyricsArea.getCaretPosition();
int lsta = songEditorLyricsArea.getLineStartOffset(songEditorLyricsArea.getLineOfOffset(cpos));
int lend = songEditorLyricsArea.getLineEndOffset(songEditorLyricsArea.getLineOfOffset(cpos));
if(lend > lsta) {
if(lend == songEditorLyricsArea.getText().length())
songEditorLyricsArea.getDocument().insertString(lend, "\n", null);
songEditorLyricsArea.getDocument().insertString(lend + 1, sname, null);
songEditorLyricsArea.setCaretPosition(lend + 1 + sname.length());
} else {
songEditorLyricsArea.getDocument().insertString(lsta, sname, null);
songEditorLyricsArea.setCaretPosition(lsta + sname.length());
}
songEditorLyricsArea.requestFocus();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
private void songEditorInsertVerses() {
try {
int count = 0;
String inp = "3";
while(count < 1 || count > 9) {
inp = InputBox.showDialog("Number of verses to insert (must be 1 - 9):", "Insert Verses", InputBox.ICON_QUESTION, inp);
if(inp == null) return;
try {
count = Integer.parseInt(inp);
} catch (NumberFormatException ex) {
continue;
}
}
String section = "[V]\n.\n";
for(int i = 1; i <= count; i++) {
section += Integer.toString(i) + "\n";
}
int cpos = songEditorLyricsArea.getCaretPosition();
int lpos = songEditorLyricsArea.getLineEndOffset(songEditorLyricsArea.getLineOfOffset(cpos));
if(lpos == songEditorLyricsArea.getText().length())
songEditorLyricsArea.getDocument().insertString(lpos, "\n", null);
songEditorLyricsArea.getDocument().insertString(lpos + 1, section, null);
songEditorLyricsArea.setCaretPosition(lpos + 1 + section.length());
songEditorLyricsArea.requestFocus();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
private void songEditorInsertChords() {
try {
int count = 0;
String inp = "4";
while(count <= 0) {
inp = InputBox.showDialog("Number of rows to insert (must be >= 1):", "Insert Verses", InputBox.ICON_QUESTION, inp);
if(inp == null) return;
try {
count = Integer.parseInt(inp);
} catch (NumberFormatException ex) {
continue;
}
}
String section = "";
for(int i = 0; i < count; i++) {
section += ".\n \n";
}
int cpos = songEditorLyricsArea.getCaretPosition();
int lsta = songEditorLyricsArea.getLineStartOffset(songEditorLyricsArea.getLineOfOffset(cpos));
int lend = songEditorLyricsArea.getLineEndOffset(songEditorLyricsArea.getLineOfOffset(cpos));
if(lend > lsta) {
if(lend == songEditorLyricsArea.getText().length())
songEditorLyricsArea.getDocument().insertString(lend, "\n", null);
songEditorLyricsArea.getDocument().insertString(lend + 1, section, null);
songEditorLyricsArea.setCaretPosition(lend + 1 + section.length());
} else {
songEditorLyricsArea.getDocument().insertString(lsta, section, null);
songEditorLyricsArea.setCaretPosition(lsta + section.length());
}songEditorLyricsArea.requestFocus();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
private void songEditorInsertPageBreak() {
try {
int cpos = songEditorLyricsArea.getCaretPosition();
int lpos = songEditorLyricsArea.getLineStartOffset(songEditorLyricsArea.getLineOfOffset(cpos));
songEditorLyricsArea.getDocument().insertString(lpos, "---\n", null);
songEditorLyricsArea.setCaretPosition(lpos + 3);
songEditorLyricsArea.requestFocus();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
private void songEditorInsertComment() {
try {
int cpos = songEditorLyricsArea.getCaretPosition();
int lpos = songEditorLyricsArea.getLineStartOffset(songEditorLyricsArea.getLineOfOffset(cpos));
songEditorLyricsArea.getDocument().insertString(lpos, ";\n", null);
songEditorLyricsArea.setCaretPosition(lpos + 1);
songEditorLyricsArea.requestFocus();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
public void showThemeSelector() {
ThemePicker dlg = new ThemePicker(I18n.getAll("song/themes/theme"));
dlg.setCheckedItems(songEditorThemeList);
if(dlg.showDialog() != ThemePicker.RESULT_OK) return;
songEditorThemeList = dlg.getCheckedItems();
setSongEditorModified(true);
}
public boolean songEditorCheckModified() {
if(songEditorIsModified) {
String message = I18n.get("ui/dialogs/songunsaved/message", songEditorCurrentSong);
String title = I18n.get("ui/dialogs/songunsaved/title");
int result = MessageBox.showDialog(message, title, I18n.get("ui/dialogs/generic/save"), I18n.get("ui/dialogs/generic/cancel"), I18n.get("ui/dialogs/generic/dontsave"), MessageBox.ICON_QUESTION);
if(result == MessageBox.RESULT_BUTTON1) {
songEditorSave();
}
else if(result == MessageBox.RESULT_BUTTON2) {
return false;
}
}
return true;
}
public void songEditorSave() {
Song s = ScreenRunner.songs.get(songEditorCurrentSong);
songEditorDataToSong(s);
s.saveAs(songEditorCurrentSong);
setSongEditorModified(false);
loadSong();
}
public void songEditorSaveAs() {
String newName = InputBox.showDialog("Enter a name for the song:", "Save As", InputBox.ICON_NONE, songEditorCurrentSong);
if(newName == null || newName.length() == 0) return;
Song s = Song.createNew(songEditorTitleField.getText());
songEditorCurrentSong = newName;
songEditorDataToSong(s);
s.saveAs(songEditorCurrentSong);
ScreenRunner.songs.set(songEditorCurrentSong, s);
setSongEditorModified(false);
loadSong();
}
private void songEditorDataToSong(Song s) {
s.setTitle(songEditorTitleField.getText());
s.setAuthor(songEditorAuthorField.getText());
s.setCopyright(songEditorCopyrightField.getText());
s.setCCLINumber(songEditorCcliField.getText());
s.setPresentationOrder(songEditorPresentationField.getText());
s.setHymnNumber(songEditorHymnField.getText());
s.setLyrics(songEditorLyricsArea.getText());
s.setCapo(songEditorCapoCombo.getSelectedItem().toString());
s.setKey(songEditorKeyField.getText());
s.setAKA(songEditorAkaField.getText());
s.setTimeSignature(songEditorTimeSigCombo.getSelectedItem().toString());
s.setTempo(songEditorTempoCombo.getSelectedItem().toString());
s.setKeyLine(songEditorKeyLineField.getText());
s.setUser1(songEditorUser1Area.getText());
s.setUser2(songEditorUser2Area.getText());
s.setUser3(songEditorUser3Area.getText());
String themes = "";
for(int i = 0; i < songEditorThemeList.size(); i++) {
themes += (themes.length() == 0 ? "" : "; ") + songEditorThemeList.get(i);
}
s.setThemes(themes);
ScreenRunner.songs.reindex(s, songEditorCurrentSong);
}
public void songEditorNew() {
String name = InputBox.showDialog("Enter a name for the song:", "New Song", InputBox.ICON_QUESTION, "untitled song");
if(name == null) return;
while(name.length() == 0) {
name = InputBox.showDialog("Enter a name for the song:", "New Song", InputBox.ICON_QUESTION, name);
}
Song s = Song.createNew(name);
s.saveAs(name);
ScreenRunner.songs.set(name, s);
songEditorCurrentSong = name;
loadSong();
}
public void setSongEditorEnabled(boolean enabled) {
if(songEditorTitleField != null) songEditorTitleField.setEnabled(enabled);
if(songEditorAuthorField != null) songEditorAuthorField.setEnabled(enabled);
if(songEditorCopyrightField != null) songEditorCopyrightField.setEnabled(enabled);
if(songEditorCcliField != null) songEditorCcliField.setEnabled(enabled);
if(songEditorPresentationField != null) songEditorPresentationField.setEnabled(enabled);
if(songEditorHymnField != null) songEditorHymnField.setEnabled(enabled);
if(songEditorLyricsArea != null) songEditorLyricsArea.setEnabled(enabled);
if(songEditorCapoCombo != null) songEditorCapoCombo.setEnabled(enabled);
if(songEditorKeyField != null) songEditorKeyField.setEnabled(enabled);
if(songEditorAkaField != null) songEditorAkaField.setEnabled(enabled);
if(songEditorTimeSigCombo != null) songEditorTimeSigCombo.setEnabled(enabled);
if(songEditorTempoCombo != null) songEditorTempoCombo.setEnabled(enabled);
if(songEditorKeyLineField != null) songEditorKeyLineField.setEnabled(enabled);
if(songEditorUserSelectorCombo != null) songEditorUserSelectorCombo.setEnabled(enabled);
if(songEditorUser1Area != null) songEditorUser1Area.setEnabled(enabled);
if(songEditorUser2Area != null) songEditorUser2Area.setEnabled(enabled);
if(songEditorUser3Area != null) songEditorUser3Area.setEnabled(enabled);
if(songEditorThemesButton != null) songEditorThemesButton.setEnabled(enabled);
if(songEditorInsertButton != null) songEditorInsertButton.setEnabled(enabled);
if(songEditorSaveButton != null) songEditorSaveButton.setEnabled(enabled && songEditorIsModified);
if(songEditorSaveAsButton != null) songEditorSaveAsButton.setEnabled(enabled && songEditorIsModified);
if(songEditorRevertButton != null) songEditorRevertButton.setEnabled(enabled && songEditorIsModified);
}
public void setSongEditorModified(boolean value) {
if(ignoreChanges) return;
songEditorIsModified = value;
if(songEditorSaveButton != null) songEditorSaveButton.setEnabled(value);
if(songEditorSaveAsButton != null) songEditorSaveAsButton.setEnabled(value);
if(songEditorRevertButton != null) songEditorRevertButton.setEnabled(value);
}
public void songEditorOpen() {
SongPicker p = new SongPicker();
int result = p.showDialog();
if(result == SongPicker.RESULT_OK) {
songEditorCurrentSong = p.getSelectedSong();
loadSong();
}
}
public void loadSong() {
Song s = ScreenRunner.songs.get(songEditorCurrentSong);
if(s != null) {
ignoreChanges = true;
songEditorTitleField.setText(s.getTitle());
songEditorAuthorField.setText(s.getAuthor());
songEditorCopyrightField.setText(s.getCopyright());
songEditorCcliField.setText(s.getCCLINumber());
songEditorPresentationField.setText(s.getPresentationOrder());
songEditorHymnField.setText(s.getHymnNumber());
songEditorLyricsArea.setText(s.getLyrics());
songEditorCapoCombo.setSelectedItem(s.getCapo());
songEditorKeyField.setText(s.getKey());
songEditorAkaField.setText(s.getAKA());
songEditorTimeSigCombo.setSelectedItem(s.getTimeSignature());
songEditorTempoCombo.setSelectedItem(s.getTempo());
songEditorKeyLineField.setText(s.getKeyLine());
songEditorUser1Area.setText(s.getUser1());
songEditorUser1Area.setText(s.getUser2());
songEditorUser1Area.setText(s.getUser3());
songEditorUserSelectorCombo.setSelectedItem("User 1");
songEditorThemeList = new Vector<String>();
String[] themes = s.getThemes();
for(int i = 0; i < themes.length; i++) {
songEditorThemeList.add(themes[i]);
}
ignoreChanges = false;
setSongEditorModified(false);
setSongEditorEnabled(true);
}
}
public ActionListener playlistEditorActions = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.equals("new")) {
playlistEditorNewPlaylist();
}
else if(cmd.equals("open")) {
playlistEditorOpenPlaylist();
}
else if(cmd.equals("save")) {
playlistEditorSavePlaylist();
}
else if(cmd.equals("saveas")) {
playlistEditorSavePlaylistAs();
}
else if(cmd.equals("insert")) {
playlistEditorInsertItem();
}
else if(cmd.equals("insertsong")) {
playlistEditorInsertSong();
}
else if(cmd.equals("insertmedia")) {
playlistEditorInsertMedia();
}
else if(cmd.equals("insertscripture")) {
playlistEditorInsertScripture();
}
else if(cmd.equals("remove")) {
playlistEditorRemoveItem();
}
else if(cmd.equals("moveup")) {
playlistEditorMoveUp();
}
else if(cmd.equals("movedown")) {
playlistEditorMoveDown();
}
else {
System.out.println("FIXME: Unhandled action: '" + cmd + "'");
}
}
};
public DocumentListener playlistEditorText = new DocumentListener() {
@Override
public void changedUpdate(DocumentEvent e) {
playlistEditorUIToList(ScreenRunner.playlist);
setPlaylistEditorModified(true);
}
@Override
public void insertUpdate(DocumentEvent e) {
playlistEditorUIToList(ScreenRunner.playlist);
setPlaylistEditorModified(true);
}
@Override
public void removeUpdate(DocumentEvent e) {
playlistEditorUIToList(ScreenRunner.playlist);
setPlaylistEditorModified(true);
}
};
private void playlistEditorMoveUp() {
int idx1 = playlistEditorItemList.getSelectedIndex();
if(idx1 <= 0) return;
int idx2 = idx1 - 1;
ScreenRunner.playlist.swapItems(idx1, idx2);
setPlaylistEditorModified(true);
playlistEditorItemList.setSelectedIndex(idx2);
}
private void playlistEditorMoveDown() {
int idx1 = playlistEditorItemList.getSelectedIndex();
if(idx1 < 0 || idx1 >= (ScreenRunner.playlist.size() - 1)) return;
int idx2 = idx1 + 1;
ScreenRunner.playlist.swapItems(idx1, idx2);
setPlaylistEditorModified(true);
playlistEditorItemList.setSelectedIndex(idx2);
}
private void playlistEditorInsertItem() {
showPopup(playlistEditorInsertButton, new Point(playlistEditorInsertButton.getWidth(), 0), playlistEditorActions, new String[] { "Song", "Scripture", "Image" }, new String[] { "insertsong", "insertscripture", "insertmedia"});
}
private void playlistEditorInsertScripture() {
ScripturePicker dlg = new ScripturePicker(false);
if(dlg.showDialog() != ScripturePicker.RESULT_OK) return;
ScripturePassage p = dlg.getSelectedPassage();
ScreenRunner.playlist.add(p);
setPlaylistEditorModified(true);
}
private void playlistEditorInsertMedia() {
String path = System.getProperty("user.home");
if(ScreenRunner.playlist.getFilename() != null && ScreenRunner.playlist.getFilename().trim().length() > 0) {
path = new File(ScreenRunner.playlist.getFilename()).getParentFile().getAbsolutePath();
}
MediaPicker dlg = new MediaPicker(false, true, false, path);
if(dlg.showDialog() != MediaPicker.RESULT_OK) return;
String[] paths = dlg.getSelectedPaths();
String s = "";
for(int i = 0; i < paths.length; i++) {
s += (i == 0 ? "" : File.pathSeparator) + paths[i];
}
ImageSlide is = new ImageSlide();
is.setUserData(s);
ScreenRunner.playlist.add(is);
}
private void showPopup(Component source, Point offset, ActionListener listener, String[] labels, String[] commands) {
JPopupMenu pm = new JPopupMenu();
for(int i = 0; i < labels.length; i++) {
JMenuItem mi = new JMenuItem(labels[i]);
if(i < commands.length) mi.setActionCommand(commands[i]);
mi.addActionListener(listener);
pm.add(mi);
}
pm.show(source, offset.x, offset.y);
}
private void playlistEditorInsertSong() {
while(true) {
SongPicker dlg = new SongPicker();
int rv = dlg.showDialog();
if(rv == SongPicker.RESULT_CANCEL) break;
String id = dlg.getSelectedSong();
Song s = ScreenRunner.songs.get(id);
if(s == null) {
I18n.err("sys/playlist/songnotfound", id);
continue;
}
ScreenRunner.playlist.add(s.cloneObject());
setPlaylistEditorModified(true);
}
}
private void setPlaylistEditorModified(boolean value) {
if(ignoreChanges) return;
playlistEditorIsModified = value;
if(playlistEditorSaveButton != null) playlistEditorSaveButton.setEnabled(value);
if(playlistEditorSaveCommand != null) playlistEditorSaveCommand.setEnabled(value);
if(playlistEditorSaveAsCommand != null) playlistEditorSaveAsCommand.setEnabled(value);
}
public void setPlaylistEditorEnabled(boolean enabled) {
playlistEditorSaveButton.setEnabled(enabled && playlistEditorIsModified);
playlistEditorSaveAsButton.setEnabled(enabled);
playlistEditorInsertButton.setEnabled(enabled);
playlistEditorMoveUpButton.setEnabled(enabled && (playlistEditorItemList.getSelectedIndex() > 0));
playlistEditorMoveDownButton.setEnabled(enabled && (playlistEditorItemList.getSelectedIndex() > -1 && playlistEditorItemList.getSelectedIndex() < (playlistEditorItemList.getModel().getSize() - 1)));
playlistEditorRemoveButton.setEnabled(enabled && (playlistEditorItemList.getSelectedIndex() > -1));
playlistEditorTitleField.setEnabled(enabled);
playlistEditorItemList.setEnabled(enabled);
playlistEditorSaveCommand.setEnabled(enabled && playlistEditorIsModified);
playlistEditorSaveAsCommand.setEnabled(enabled);
playlistEditorMoveUpCommand.setEnabled(enabled && (playlistEditorItemList.getSelectedIndex() > 0));
playlistEditorModeDownCommand.setEnabled(enabled && (playlistEditorItemList.getSelectedIndex() > -1 && playlistEditorItemList.getSelectedIndex() < (playlistEditorItemList.getModel().getSize() - 1)));
playlistEditorRemoveCommand.setEnabled(enabled && (playlistEditorItemList.getSelectedIndex() > -1));
playlistEditorInsertSongCommand.setEnabled(enabled);
playlistEditorInsertScriptureCommand.setEnabled(enabled);
playlistEditorInsertCustomCommand.setEnabled(enabled);
playlistEditorInsertMediaCommand.setEnabled(enabled);
playlistEditorInsertStyleCommand.setEnabled(enabled);
}
public boolean playlistEditorCheckModified() {
if(playlistEditorIsModified) {
String pls = ScreenRunner.playlist.getTitle();
if(pls == null || pls.length() == 0)
pls = "(untitled playlist)";
String message = I18n.get("ui/dialogs/playlistunsaved/message", pls);
String title = I18n.get("ui/dialogs/playlistunsaved/title");
int result = MessageBox.showDialog(message, title, I18n.get("ui/dialogs/generic/save"), I18n.get("ui/dialogs/generic/cancel"), I18n.get("ui/dialogs/generic/dontsave"), MessageBox.ICON_QUESTION);
if(result == MessageBox.RESULT_BUTTON1) {
playlistEditorSavePlaylist();
}
else if(result == MessageBox.RESULT_BUTTON2) {
return false;
}
}
return true;
}
private void playlistEditorUpdateListButtons() {
playlistEditorMoveUpButton.setEnabled((playlistEditorItemList.getSelectedIndex() > 0));
playlistEditorMoveDownButton.setEnabled((playlistEditorItemList.getSelectedIndex() > -1 && playlistEditorItemList.getSelectedIndex() < (playlistEditorItemList.getModel().getSize() - 1)));
playlistEditorRemoveButton.setEnabled((playlistEditorItemList.getSelectedIndex() > -1));
playlistEditorMoveUpCommand.setEnabled((playlistEditorItemList.getSelectedIndex() > 0));
playlistEditorModeDownCommand.setEnabled((playlistEditorItemList.getSelectedIndex() > -1 && playlistEditorItemList.getSelectedIndex() < (playlistEditorItemList.getModel().getSize() - 1)));
playlistEditorRemoveCommand.setEnabled((playlistEditorItemList.getSelectedIndex() > -1));
}
public void playlistEditorListToUI(Playlist list) {
ignoreChanges = true;
playlistEditorTitleField.setText(list.getTitle());
ignoreChanges = false;
}
public void playlistEditorUIToList(Playlist list) {
list.setTitle(playlistEditorTitleField.getText());
}
public void playlistEditorNewPlaylist() {
if(!playlistEditorCheckModified()) return;
ScreenRunner.playlist.newPlaylist();
playlistEditorListToUI(ScreenRunner.playlist);
setPlaylistEditorModified(false);
setPlaylistEditorEnabled(true);
}
public void playlistEditorOpenPlaylist() {
if(!playlistEditorCheckModified()) return;
JFileChooser jfc = new JFileChooser();
if(ScreenRunner.playlist.getFilename() != null) {
jfc.setCurrentDirectory(new File(ScreenRunner.playlist.getFilename()).getParentFile());
}
FileNameExtensionFilter filter = new FileNameExtensionFilter("ScreenRunner Playlists", "srplaylist");
jfc.setFileFilter(filter);
int rv = jfc.showOpenDialog(rootFrame);
if(rv != JFileChooser.APPROVE_OPTION) return;
ScreenRunner.playlist.loadFrom(jfc.getSelectedFile().getAbsolutePath());
playlistEditorListToUI(ScreenRunner.playlist);
setPlaylistEditorModified(false);
setPlaylistEditorEnabled(true);
}
public void playlistEditorSavePlaylist() {
String filename = ScreenRunner.playlist.getFilename();
if(filename == null) {
playlistEditorSavePlaylistAs();
return;
}
ScreenRunner.playlist.saveListAs(ScreenRunner.playlist.getFilename());
setPlaylistEditorModified(false);
}
public void playlistEditorSavePlaylistAs() {
JFileChooser jfc = new JFileChooser();
if(ScreenRunner.playlist.getFilename() != null) {
jfc.setSelectedFile(new File(ScreenRunner.playlist.getFilename()));
}
FileNameExtensionFilter filter = new FileNameExtensionFilter("ScreenRunner Playlists", "srplaylist");
jfc.setFileFilter(filter);
int rv = jfc.showSaveDialog(rootFrame);
if(rv != JFileChooser.APPROVE_OPTION) return;
ScreenRunner.playlist.setFilename(jfc.getSelectedFile().getAbsolutePath());
playlistEditorSavePlaylist();
}
public void playlistEditorRemoveItem() {
int idx = playlistEditorItemList.getSelectedIndex();
if(idx == -1) return;
ScreenRunner.playlist.remove(idx);
setPlaylistEditorModified(true);
}
public ListSelectionListener playlistSelection = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
playlistEditorUpdateListButtons();
}
};
private ListCellRenderer playlistCellRenderer = new ListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
UIDefaults uid = UIManager.getLookAndFeel().getDefaults();
Color itemBg = (isSelected ? uid.getColor("List.selectionBackground") : new Color(0, 0, 0, 0));
Color itemFg = (isSelected ? uid.getColor("List.selectionForeground") : uid.getColor("List.foreground"));
Color selHilite = (isSelected ? uid.getColor("List.focusSelectedCellHighlightBorder") : uid.getColor("List.focusCellHighlightBorder"));
Displayable v = (Displayable)value;
int count = v.getPageCount();
JLabel typeLbl = new JLabel();
typeLbl.setText(v.getTypeLabel());
Dimension sz = typeLbl.getPreferredSize();
Dimension prefsz = new Dimension(130, sz.height);
typeLbl.setPreferredSize(prefsz);
JLabel pageLbl = new JLabel(Integer.toString(count - 1));
prefsz.width = 100;
pageLbl.setPreferredSize(prefsz);
JPanel c = new JPanel();
c.setLayout(new GridBagLayout());
c.setBorder(new MatteBorder(1, 0, 1, 0, (cellHasFocus ? selHilite : itemBg)));
c.setForeground(itemFg);
c.setBackground(itemBg);
if(!isSelected) {
c.setOpaque(false);
}
typeLbl.setForeground(itemFg);
pageLbl.setForeground(itemFg);
JLabel txtLbl = new JLabel(v.getTitle());
txtLbl.setForeground(itemFg);
c.add(typeLbl, new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 20, 1, 20), 0, 0));
c.add(pageLbl, new GridBagConstraints(1, 0, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 20, 1, 20), 0, 0));
c.add(txtLbl, new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 20, 1, 20), 0, 0));
return c;
}
};
private ListCellRenderer pageCellRenderer = new ListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
PlaylistPage v = (PlaylistPage)value;
String pgname = v.getItem().getPageName(v.getPage());
boolean isBlank = (pgname != null && pgname.equals("<blank>"));
UIDefaults uid = UIManager.getLookAndFeel().getDefaults();
Color itemBg = (isSelected ? uid.getColor("List.selectionBackground") : uid.getColor("List.background"));
Color itemFg = (isSelected ? uid.getColor("List.selectionForeground") : uid.getColor("List.foreground"));
Color selHilite = (isSelected ? uid.getColor("List.focusSelectedCellHighlightBorder") : uid.getColor("List.focusCellHighlightBorder"));
if(isBlank) selHilite = Color.black;
JLabel typeLbl = new JLabel();
typeLbl.setText(v.getItem().getSlideLabel());
if(isBlank) typeLbl.setText("");
Dimension sz = typeLbl.getPreferredSize();
if(isBlank) sz = new JLabel("FooBar").getPreferredSize();
Dimension prefsz = new Dimension(250, sz.height);
typeLbl.setPreferredSize(prefsz);
typeLbl.setMinimumSize(prefsz);
typeLbl.setForeground(itemFg);
JLabel pageLbl = new JLabel((isBlank ? "" : pgname));
prefsz = new Dimension(50, sz.height);
pageLbl.setPreferredSize(prefsz);
JPanel c = new JPanel();
c.setLayout(new GridBagLayout());
c.setBorder(new MatteBorder(1, 0, 1, 0, ((cellHasFocus || isBlank) ? selHilite : itemBg)));
c.setBackground(itemBg);
pageLbl.setForeground(itemFg);
JLabel txtLbl = new JLabel((isBlank ? "" : v.getItem().getPageText(v.getPage()).replace("\n", " | ")));
txtLbl.setForeground(itemFg);
c.add(typeLbl, new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(1, 10, 1, 10), 0, 0));
c.add(pageLbl, new GridBagConstraints(1, 0, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(1, 10, 1, 10), 0, 0));
c.add(txtLbl, new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(1, 10, 1, 10), 0, 0));
return c;
}
};
public ActionListener presentationActions = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.equals("customscripture")) {
presentationCustomScripture();
}
else if(cmd.equals("custommedia")) {
presentationCustomMedia();
}
else {
System.out.println("FIXME: Unhandled action: '" + cmd + "'");
}
}
};
public ActionListener presentationDispMode = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.equals("dispoff")) {
presentationDispOff();
}
else if(cmd.equals("dispnormal")) {
presentationDispNormal();
}
else if(cmd.equals("dispbackground")) {
presentationDispBackground();
}
else if(cmd.equals("dispblack")) {
presentationDispBlack();
}
else if(cmd.equals("displogo")) {
presentationDispLogo();
}
else if(cmd.equals("displock")) {
presentationDispToggleLock();
}
else if(cmd.equals("screenmode")) {
presentationChangeScreenMode();
}
else {
System.out.println("FIXME: Unhandled action: '" + cmd + "'");
}
presentationSyncDisplayButtons();
}
};
public ListSelectionListener presentationListListener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if(e.getValueIsAdjusting()) return;
presentationShowSelectedItem();
}
};
private void presentationChangeScreenMode() {
int index = presentScreenModeCombo.getSelectedIndex();
if(index == -1) return;
Display.setWindowMode(index);
Display.positionWindow();
}
private void presentationShowSelectedItem() {
PlaylistPage page = (PlaylistPage)presentationSlideList.getSelectedValue();
if(page == null) return;
Display.getDisplay().prepareNextBackground(ScreenRunner.currentStyle, page.getItem().getStyleType());
Display.getDisplay().prepareNextSlide(page.getItem(), page.getPage(), ScreenRunner.currentStyle);
Display.getDisplay().applyChanges();
}
private void presentationCustomScripture() {
ScripturePicker dlg = new ScripturePicker(true);
dlg.showDialog();
presentationShowSelectedItem();
}
private void presentationCustomMedia() {
MediaPicker dlg = new MediaPicker(true, true, false, System.getProperty("user.home"));
dlg.showDialog();
presentationShowSelectedItem();
}
private void presentationSyncDisplayButtons() {
presentDisplayOffButton.setSelected(Display.getDisplay().getDisplayMode() == Display.DISPMODE_OFF);
presentDisplayNormalButton.setSelected(Display.getDisplay().getDisplayMode() == Display.DISPMODE_NORMAL);
presentDisplayBackgroundButton.setSelected(Display.getDisplay().getDisplayMode() == Display.DISPMODE_BACKGROUND);
presentDisplayBlackButton.setSelected(Display.getDisplay().getDisplayMode() == Display.DISPMODE_BLACK);
presentDisplayLogoButton.setSelected(Display.getDisplay().getDisplayMode() == Display.DISPMODE_LOGO);
presentDisplayLockButton.setSelected(Display.getDisplay().isDisplayLocked());
presentDisplayOffCommand.setSelected(Display.getDisplay().getDisplayMode() == Display.DISPMODE_OFF);
presentDisplayNormalCommand.setSelected(Display.getDisplay().getDisplayMode() == Display.DISPMODE_NORMAL);
presentDisplayBackgroundCommand.setSelected(Display.getDisplay().getDisplayMode() == Display.DISPMODE_BACKGROUND);
presentDisplayBlackCommand.setSelected(Display.getDisplay().getDisplayMode() == Display.DISPMODE_BLACK);
presentDisplayLogoCommand.setSelected(Display.getDisplay().getDisplayMode() == Display.DISPMODE_LOGO);
if(presentDisplayLockCommand != null) presentDisplayLockCommand.setSelected(Display.getDisplay().isDisplayLocked());
}
public void presentationDispOff() {
if(Display.getDisplay().getDisplayMode() == Display.DISPMODE_OFF) return;
Display.getDisplayWindow().setVisible(false);
Display.getDisplay().setDisplayMode(Display.DISPMODE_OFF);
presentationRefreshDisplay();
}
public void presentationDispNormal() {
if(Display.getDisplay().getDisplayMode() == Display.DISPMODE_NORMAL) return;
presentationShowDisplay();
Display.getDisplay().setDisplayMode(Display.DISPMODE_NORMAL);
presentationRefreshDisplay();
}
public void presentationDispBackground() {
if(Display.getDisplay().getDisplayMode() == Display.DISPMODE_BACKGROUND) return;
presentationShowDisplay();
Display.getDisplay().setDisplayMode(Display.DISPMODE_BACKGROUND);
presentationRefreshDisplay();
}
public void presentationDispBlack() {
if(Display.getDisplay().getDisplayMode() == Display.DISPMODE_BLACK) return;
presentationShowDisplay();
Display.getDisplay().setDisplayMode(Display.DISPMODE_BLACK);
presentationRefreshDisplay();
}
public void presentationDispLogo() {
if(Display.getDisplay().getDisplayMode() == Display.DISPMODE_LOGO) return;
presentationShowDisplay();
Display.getDisplay().setDisplayMode(Display.DISPMODE_LOGO);
presentationRefreshDisplay();
}
private void presentationShowDisplay() {
if(!Display.getDisplayWindow().isVisible()) {
Display.positionWindow();
Display.getDisplayWindow().setVisible(true);
}
}
public void presentationDispToggleLock() {
Display.getDisplay().setDisplayLocked(!Display.getDisplay().isDisplayLocked());
}
private void presentationRefreshDisplay() {
Display disp = Display.getDisplay();
Style style = ScreenRunner.currentStyle;
PlaylistPage page = new PlaylistPage(null, -1);
int idx = presentationSlideList.getSelectedIndex();
if(idx > -1) {
page = (PlaylistPage)ScreenRunner.playlist.getPagesModel().getElementAt(idx);
if(page == null) {
disp.prepareNextBackground(style, "default");
disp.prepareNextSlide(null, 0, style);
} else {
disp.prepareNextBackground(style, page.getItem().getStyleType());
disp.prepareNextSlide(page.getItem(), page.getPage(), style);
}
} else {
disp.prepareNextBackground(style, "default");
disp.prepareNextSlide(null, 0, style);
}
disp.applyChanges();
}
public ComponentListener component = new ComponentListener() {
@Override
public void componentHidden(ComponentEvent e) { }
@Override
public void componentMoved(ComponentEvent e) { }
@Override
public void componentResized(ComponentEvent e) {
try {
ScreenRunner.config.setProperty("window-width", Integer.toString(rootFrame.getWidth()));
ScreenRunner.config.setProperty("window-height", Integer.toString(rootFrame.getHeight()));
} catch (NullPointerException ex) {
// componentResized was probably called before rootFrame was initialized. (multithreading?)
}
}
@Override
public void componentShown(ComponentEvent e) { }
};
public WindowListener window = new WindowListener() {
@Override
public void windowActivated(WindowEvent e) { }
@Override
public void windowClosed(WindowEvent e) {
System.exit(0);
}
@Override
public void windowClosing(WindowEvent e) {
if(songEditorCheckModified() && playlistEditorCheckModified()) {
ScreenRunner.saveConfig();
rootFrame.dispose();
}
}
@Override
public void windowDeactivated(WindowEvent e) { }
@Override
public void windowDeiconified(WindowEvent e) { }
@Override
public void windowIconified(WindowEvent e) { }
@Override
public void windowOpened(WindowEvent e) { }
};
}