View Javadoc

1   /*
2    * Copyright (C) 2010 Unreal Visualizer Authors
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package nl.tudelft.goal.ut2004.visualizer.gui.dialogs;
18  
19  import java.awt.Color;
20  import java.awt.FlowLayout;
21  import java.awt.Frame;
22  import java.awt.event.ActionEvent;
23  import java.awt.event.ActionListener;
24  
25  import javax.swing.JButton;
26  import javax.swing.JColorChooser;
27  import javax.swing.JDialog;
28  
29  import nl.tudelft.goal.ut2004.visualizer.timeline.map.FlagRenderer;
30  import nl.tudelft.goal.ut2004.visualizer.timeline.map.MapRenderer;
31  import nl.tudelft.goal.ut2004.visualizer.timeline.map.PlayerRenderer;
32  import nl.tudelft.goal.ut2004.visualizer.timeline.map.WaypointRenderer;
33  import nl.tudelft.goal.ut2004.visualizer.util.WindowPersistenceHelper;
34  
35  /**
36   * Dialog to connect to the server.
37   * 
38   * @author M.P. Korstanje
39   * 
40   */
41  public class SettingsDialog extends JDialog {
42  
43  	/**
44  	 * Helper class to persist this window.
45  	 */
46  	private WindowPersistenceHelper persistenceHelper;
47  
48  	public SettingsDialog(Frame parent) {
49  		super(parent, false);
50  
51  		setTitle("Visualizer Settings");
52  
53  		this.setSize(200, 200);
54  		// Setup persistence
55  		persistenceHelper = new WindowPersistenceHelper(this);
56  		persistenceHelper.load();
57  
58  		this.setLayout(new FlowLayout());
59  
60  		JButton selectHighColor = new JButton("Change Map High Color");
61  		selectHighColor.addActionListener(new ActionListener() {
62  
63  			@Override
64  			public void actionPerformed(ActionEvent e) {
65  				Color current = MapRenderer.getHighColor();
66  				Color selected = JColorChooser.showDialog(SettingsDialog.this, "Pick a color", current);
67  				MapRenderer.setHighColor(selected);
68  			}
69  		});
70  		add(selectHighColor);
71  
72  		JButton selectLowColor = new JButton("Change Map Low Color");
73  		selectLowColor.addActionListener(new ActionListener() {
74  
75  			@Override
76  			public void actionPerformed(ActionEvent e) {
77  				Color current = MapRenderer.getLowColor();
78  				Color selected = JColorChooser.showDialog(SettingsDialog.this, "Pick a color", current);
79  				if (selected == null)
80  					return;
81  				MapRenderer.setLowColor(selected);
82  			}
83  		});
84  		add(selectLowColor);
85  
86  		JButton selectNavpointColor = new JButton("Change Navpoint Color");
87  		selectNavpointColor.addActionListener(new ActionListener() {
88  
89  			@Override
90  			public void actionPerformed(ActionEvent e) {
91  				Color current = WaypointRenderer.getColor();
92  				Color selected = JColorChooser.showDialog(SettingsDialog.this, "Pick a color", current);
93  				if (selected == null)
94  					return;
95  				WaypointRenderer.setColor(selected);
96  			}
97  		});
98  		add(selectNavpointColor);
99  
100 		JButton selectRedTeamColor = new JButton("Change Red Team Color");
101 		selectRedTeamColor.addActionListener(new ActionListener() {
102 
103 			@Override
104 			public void actionPerformed(ActionEvent e) {
105 
106 				{
107 					Color current = FlagRenderer.getRedFlagColor();
108 					Color selected = JColorChooser.showDialog(SettingsDialog.this, "Pick a color", current);
109 					if (selected == null)
110 						return;
111 					
112 					
113 					FlagRenderer.setRedFlagColor(selected);
114 					PlayerRenderer.setRedTeamColor(selected);
115 				}
116 
117 			}
118 		});
119 		add(selectRedTeamColor);
120 
121 		JButton selectBlueTeamColor = new JButton("Change Blue Team Color");
122 		selectBlueTeamColor.addActionListener(new ActionListener() {
123 
124 			@Override
125 			public void actionPerformed(ActionEvent e) {
126 
127 				{
128 					Color current = FlagRenderer.getBlueFlagColor();
129 					Color selected = JColorChooser.showDialog(SettingsDialog.this, "Pick a color", current);
130 					if (selected == null)
131 						return;
132 					FlagRenderer.setBlueFlagColor(selected);
133 					PlayerRenderer.setBlueTeamColor(selected);
134 
135 				}
136 			}
137 		});
138 		add(selectBlueTeamColor);
139 	}
140 
141 }