1 //
2 // Neuros Database Manipulator
3 // Copyright (C) 2003 Neuros Database Manipulator
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 // For information about Neuros Database Manipulator and its authors,
20 // please contact the Neuros Database Manipulator Web Site at
21 // http://neurosdbm.sourceforge.net
22 //
23 //
24
25 package net.sourceforge.neurosdbm;
26
27
28 import java.awt.Frame;
29 import java.awt.GridBagLayout;
30 import java.awt.GridBagConstraints;
31 import java.awt.Insets;
32 import java.awt.GridLayout;
33 import java.awt.Dimension;
34 import java.awt.event.ActionListener;
35 import java.awt.event.ActionEvent;
36 import javax.swing.JLabel;
37 import javax.swing.JPanel;
38 import javax.swing.JDialog;
39 import javax.swing.JButton;
40 import javax.swing.JRadioButton;
41 import javax.swing.JTextField;
42 import javax.swing.JCheckBox;
43 import javax.swing.ButtonGroup;
44 import javax.swing.border.TitledBorder;
45
46 class MusicPathDialog extends JDialog implements ActionListener {
47
48 private JButton changeButton;
49 private JButton cancelButton;
50
51 private JRadioButton noneRadioButton;
52 private static final String noneRadioButtonPath = "music";
53 private JRadioButton artistRadioButton;
54 private static final String artistRadioButtonPath = "music/%a";
55 private JRadioButton artistAlbumRadioButton;
56 private static final String artistAlbumRadioButtonPath = "music/%a/%b";
57 private JRadioButton genreArtistRadioButton;
58 private static final String genreArtistRadioButtonPath = "music/%g/%a";
59 private JRadioButton customPathRadioButton;
60 private ButtonGroup pathGroup;
61
62 private final JTextField pathText = new JTextField();
63
64 MusicPathDialog(Frame owner, String title) {
65 super(owner, title, true);
66
67 GridBagLayout gridbag = new GridBagLayout();
68 GridBagConstraints constraints = new GridBagConstraints();
69 constraints.insets = new Insets(5, 5, 5, 5);
70
71 getContentPane().setLayout(gridbag);
72
73 Symbols symbols = NeurosProperties.getSymbols();
74 String path = symbols.getPath();
75
76 final JLabel pathLabel = new JLabel( "Music path:", JLabel.RIGHT);
77 constraints.gridwidth = 1;
78 constraints.fill = GridBagConstraints.HORIZONTAL;
79 constraints.weightx = 1;
80 gridbag.setConstraints(pathLabel, constraints);
81 getContentPane().add(pathLabel);
82
83 constraints.gridwidth = GridBagConstraints.REMAINDER;
84 constraints.fill = GridBagConstraints.HORIZONTAL;
85 gridbag.setConstraints(pathText, constraints);
86 getContentPane().add(pathText);
87
88 JPanel selectionPanel = new JPanel();
89 selectionPanel.setLayout(new GridLayout(0, 1));
90 noneRadioButton = new JRadioButton("None");
91 noneRadioButton.addActionListener(this);
92 selectionPanel.add(noneRadioButton);
93
94 artistRadioButton = new JRadioButton("Artist");
95 artistRadioButton.addActionListener(this);
96 selectionPanel.add(artistRadioButton);
97
98 artistAlbumRadioButton = new JRadioButton("Artist/Album");
99 artistAlbumRadioButton.addActionListener(this);
100 selectionPanel.add(artistAlbumRadioButton);
101
102 genreArtistRadioButton = new JRadioButton("Genre/Artist");
103 genreArtistRadioButton.addActionListener(this);
104 selectionPanel.add(genreArtistRadioButton);
105
106 customPathRadioButton = new JRadioButton("Custom Path");
107 customPathRadioButton.addActionListener(this);
108 selectionPanel.add(customPathRadioButton);
109
110 TitledBorder selectionBorder = new TitledBorder("Path Selection");
111 selectionPanel.setBorder(selectionBorder);
112 constraints.fill = GridBagConstraints.BOTH;
113 constraints.gridwidth = 2;
114 gridbag.setConstraints(selectionPanel, constraints);
115 getContentPane().add(selectionPanel);
116
117 pathGroup = new ButtonGroup();
118 pathGroup.add(noneRadioButton);
119 pathGroup.add(artistRadioButton);
120 pathGroup.add(artistAlbumRadioButton);
121 pathGroup.add(genreArtistRadioButton);
122 pathGroup.add(customPathRadioButton);
123
124 // Determine which button to set
125 if (path == null) {
126 path = artistAlbumRadioButtonPath;
127 }
128 customPathRadioButton.setSelected(true);
129 if (path == noneRadioButtonPath) {
130 noneRadioButton.setSelected(true);
131 pathText.setEnabled(false);
132 }
133 if (path == artistAlbumRadioButtonPath) {
134 artistAlbumRadioButton.setSelected(true);
135 pathText.setEnabled(false);
136 }
137
138 pathText.setText(path);
139
140 JPanel helpPanel = new JPanel();
141 helpPanel.setLayout(new GridLayout(0, 1, 3, 5));
142 helpPanel.add(new JLabel("%a, artist"));
143 helpPanel.add(new JLabel("%b, album"));
144 helpPanel.add(new JLabel("%m, track"));
145 helpPanel.add(new JLabel("%t, track (padded)"));
146 helpPanel.add(new JLabel("%n, name"));
147 helpPanel.add(new JLabel("%e, extension"));
148 helpPanel.add(new JLabel("%%, percent"));
149 helpPanel.add(new JLabel("Add a * (i.e. %*a) to encode chars."));
150 TitledBorder helpBorder = new TitledBorder("Path Symbols");
151 helpPanel.setBorder(helpBorder);
152 constraints.fill = GridBagConstraints.BOTH;
153 constraints.gridwidth = GridBagConstraints.REMAINDER;
154 gridbag.setConstraints(helpPanel, constraints);
155 getContentPane().add(helpPanel);
156
157 JPanel buttonPanel = new JPanel();
158 buttonPanel.setLayout(new GridLayout(1, 0, 10, 0));
159 changeButton = new JButton("Change");
160 changeButton.addActionListener(this);
161 buttonPanel.add(changeButton);
162
163 cancelButton = new JButton("Cancel");
164 cancelButton.addActionListener(this);
165 buttonPanel.add(cancelButton);
166
167 constraints.gridwidth = GridBagConstraints.REMAINDER;
168 constraints.weightx = 1;
169 gridbag.setConstraints(buttonPanel, constraints);
170 getContentPane().add(buttonPanel);
171
172 pack();
173 }
174
175
176 public void actionPerformed(ActionEvent e) {
177 if (e.getSource().equals(changeButton)) {
178 Symbols symbols = NeurosProperties.getSymbols();
179 symbols.setPath(pathText.getText());
180 NeurosProperties.setSymbols(symbols);
181 dispose();
182 }
183 if (e.getSource().equals(cancelButton)) {
184 dispose();
185 }
186
187 if (e.getSource().equals(noneRadioButton)) {
188 pathText.setText(noneRadioButtonPath);
189 pathText.setEnabled(false);
190 }
191 if (e.getSource().equals(artistRadioButton)) {
192 pathText.setText(artistRadioButtonPath);
193 pathText.setEnabled(false);
194 }
195 if (e.getSource().equals(artistAlbumRadioButton)) {
196 pathText.setText(artistAlbumRadioButtonPath);
197 pathText.setEnabled(false);
198 }
199 if (e.getSource().equals(genreArtistRadioButton)) {
200 pathText.setText(genreArtistRadioButtonPath);
201 pathText.setEnabled(false);
202 }
203 if (e.getSource().equals(customPathRadioButton)) {
204 pathText.setEnabled(true);
205 }
206 }
207 }