summaryrefslogtreecommitdiff
path: root/jeu-test/Lemmini/0.84/src/GUI/GainDialog.java
blob: b2598ebdba90431d155a35fbacff27da07aa252f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package GUI;

import java.awt.Point;
import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;

import Game.GameController;
import Game.Music;

/*
 * Copyright 2009 Volker Oth
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Dialog for volume/gain control.
 * @author Volker Oth
 */
public class GainDialog extends JDialog {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JSlider jSliderMusic = null;

	private JLabel jLabelMusicGain = null;

	private JLabel jLabelSoundGain = null;

	private JSlider jSliderSound = null;

	private JButton jButtonOK = null;

	private JButton jButtonCancel = null;


	/**
	 * Constructor for modal dialog in parent frame.
	 * @param frame parent frame
	 * @param modal create modal dialog?
	 */
	public GainDialog(final JFrame frame, final boolean modal) {
		super(frame, modal);
		initialize();

		//
		Point p = frame.getLocation();
		this.setLocation(p.x+frame.getWidth()/2-getWidth()/2, p.y+frame.getHeight()/2-getHeight()/2);
		jSliderSound.setValue((int)(100*GameController.sound.getGain()));
		jSliderMusic.setValue((int)(100*Music.getGain()));
	}

	/**
	 * Automatically generated init.
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setTitle("Volume Controls");
		this.setContentPane(getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 *
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabelSoundGain = new JLabel();
			jLabelSoundGain.setBounds(new Rectangle(15, 75, 101, 14));
			jLabelSoundGain.setText("Sound Volume");
			jLabelMusicGain = new JLabel();
			jLabelMusicGain.setText("Music Volume");
			jLabelMusicGain.setBounds(new Rectangle(15, 15, 106, 14));
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJSliderMusic(), null);
			jContentPane.add(jLabelMusicGain, null);
			jContentPane.add(jLabelSoundGain, null);
			jContentPane.add(getJSliderSound(), null);
			jContentPane.add(getJButtonOK(), null);
			jContentPane.add(getJButtonCancel(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jSliderMusic
	 *
	 * @return javax.swing.JSlider
	 */
	private JSlider getJSliderMusic() {
		if (jSliderMusic == null) {
			jSliderMusic = new JSlider();
			jSliderMusic.setBounds(new Rectangle(15, 30, 256, 25));
			jSliderMusic.setMaximum(100);
			jSliderMusic.setMinimum(0);
			jSliderMusic.setMajorTickSpacing(10);
			jSliderMusic.setPaintTicks(true);
			jSliderMusic.setValue(100);
		}
		return jSliderMusic;
	}

	/**
	 * This method initializes jSliderSound
	 *
	 * @return javax.swing.JSlider
	 */
	private JSlider getJSliderSound() {
		if (jSliderSound == null) {
			jSliderSound = new JSlider();
			jSliderSound.setBounds(new Rectangle(15, 90, 256, 25));
			jSliderSound.setMaximum(100);
			jSliderSound.setMinimum(0);
			jSliderSound.setPaintTicks(true);
			jSliderSound.setValue(100);
			jSliderSound.setMajorTickSpacing(10);
		}
		return jSliderSound;
	}

	/**
	 * This method initializes jButtonOK
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getJButtonOK() {
		if (jButtonOK == null) {
			jButtonOK = new JButton();
			jButtonOK.setBounds(new Rectangle(210, 135, 66, 25));
			jButtonOK.setText(" Ok ");
			jButtonOK.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Music.setGain(jSliderMusic.getValue()/100.0);
					GameController.sound.setGain(jSliderSound.getValue()/100.0);
					dispose();
				}
			});
		}
		return jButtonOK;
	}

	/**
	 * This method initializes jButtonCancel
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getJButtonCancel() {
		if (jButtonCancel == null) {
			jButtonCancel = new JButton();
			jButtonCancel.setBounds(new Rectangle(14, 136, 77, 23));
			jButtonCancel.setText("Cancel");
			jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
				}
			});
		}
		return jButtonCancel;
	}
}