aboutsummaryrefslogtreecommitdiff
path: root/JBriscola/all_versions/0.3/0.3.1/src/OptionFrame.java
blob: d89745bb0e355537d7fba9314126a86fd7418895 (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
/*
Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org>

This file is part of JBriscola.

    JBriscola is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    JBriscola is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with JBriscola; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

import java.util.Formatter;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class OptionFrame extends JFrame {
	
	public static Main main = new Main();
	public static Formatter formatter;
	public static JButton ok, annulla, scegliColore;
	public static JLabel lingua, sfondo;
	public static JComboBox selezionaLingua;
	public static JCheckBox suono, tastiRapidi;
	public static JPanel[] pannello = new JPanel[6];
	
	public OptionFrame() {
		
		super( "JBriscola - " + main.stringaModificaOpzioni );
		
		ok = new JButton( "OK" );
		ok.addActionListener( new ActionListener() {
			
			/* Quando le modifiche vengono confermate premendo ok, viene scritto
			 * il file di configurazione (o aggiornato) se possibile, e modificate
			 * le impostazioni attuali. */
			public void actionPerformed( ActionEvent e ) {
				
				try {
					formatter = new Formatter( "JBriscolaConfig.txt" );
				} catch ( Exception ex ) {
					JOptionPane.showMessageDialog( OptionFrame.this, main.stringaImpossibileConfigurare + ex, "JBriscola - " + main.version, JOptionPane.ERROR_MESSAGE );
				}
				
				String lang;
				
				switch ( selezionaLingua.getSelectedIndex() ) {
					case 0:
						lang = "it";
						break;
					case 1:
						lang = "la";
						break;
					case 2:
						lang = "bl";
						break;
					case 3:
						lang = "bv";
						break;
					case 4:
						lang = "en";
						break;
					default:
						lang = "it";
						break;
				}
				
				String suonosiono, tastisiono;
				
				if ( suono.isSelected() )
					suonosiono = "suono=si";
				else
					suonosiono = "suono=no";
				if ( tastiRapidi.isSelected() )
					tastisiono = "tasti=si";
				else
					tastisiono = "tasti=no";
					
				formatter.format( lang );
				formatter.format( "\n" );
				formatter.format( suonosiono );
				formatter.format( "\n" );
				formatter.format( tastisiono );
				formatter.format( "\n" );
				formatter.format( main.color.getRed() + " " + main.color.getGreen() + " " + main.color.getBlue() );
				formatter.close();
				
				main.settaOpzioni();
				
				OptionFrame.this.dispose();
			}
		});
		
		annulla = new JButton( main.stringaAnnulla );
		annulla.addActionListener( new ActionListener() {
			/* Se l'utente annulla viene chiusa la finestra senza fare nulla. */
			public void actionPerformed( ActionEvent e ) {
				OptionFrame.this.dispose();
			}
		});
		
		scegliColore = new JButton( " " );
		scegliColore.setBackground( main.color );
		scegliColore.addActionListener( new ActionListener() {
			/* Permette di scegliere il colore dello sfondo. */
			public void actionPerformed( ActionEvent e ) {
				Color colore = JColorChooser.showDialog( OptionFrame.this, "JBriscola " + main.version, main.color );
				if ( colore != null )
					main.color = colore;
				OptionFrame.scegliColore.setBackground( main.color );
			}
		} );
		
		/* Vengono impostati e disegnati i vari componenti. */
		lingua = new JLabel( main.stringaLingua );
		sfondo = new JLabel( main.stringaSfondo );
		String[] lingueDaSelezionare = { main.stringaIt, main.stringaLa, main.stringaBL, main.stringaBV, main.stringaEN };
		selezionaLingua = new JComboBox( lingueDaSelezionare );
		int linguaPreselezionata = 0;
		
		if ( main.lang.equals( "it" ) )
			linguaPreselezionata = 0;
		else if ( main.lang.equals( "la" ) )
			linguaPreselezionata = 1;
		else if ( main.lang.equals( "bl" ) )
			linguaPreselezionata = 2;
		else if ( main.lang.equals( "bv" ) )
			linguaPreselezionata = 3;
		else if ( main.lang.equals( "en" ) )
			linguaPreselezionata = 4;
		
		selezionaLingua.setSelectedIndex( linguaPreselezionata );
		suono = new JCheckBox( main.stringaSuono );
		suono.setSelected( main.sound );
		tastiRapidi = new JCheckBox( main.stringaTasti );
		tastiRapidi.setSelected( main.keys );

		pannello[0] = new JPanel( new GridLayout( 4, 1 ) );
		pannello[1] = new JPanel( new FlowLayout() );
		pannello[2] = new JPanel( new FlowLayout() );
		pannello[3] = new JPanel( new FlowLayout() );
		pannello[4] = new JPanel( new FlowLayout() );
		pannello[5] = new JPanel( new FlowLayout() );
		pannello[5].add( ok );
		pannello[5].add( annulla );
		pannello[4].add( sfondo );
		pannello[4].add( scegliColore );
		pannello[3].add( tastiRapidi );
		pannello[2].add( suono );
		pannello[1].add( lingua );
		pannello[1].add( selezionaLingua );
		pannello[0].add( pannello[1] );
		pannello[0].add( pannello[2] );
		pannello[0].add( pannello[3] );
		pannello[0].add( pannello[4] );
		add( pannello[0], BorderLayout.CENTER );
		add( pannello[5], BorderLayout.SOUTH );
	}
}

Generated with cgit - Back to sebastiano.tronto.net