OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.map.ui;
15
 
16
import org.openconcerto.map.model.Ville;
17
import org.openconcerto.ui.component.ComboLockedMode;
18
import org.openconcerto.ui.component.ITextComboCache;
25 ilm 19
import org.openconcerto.ui.component.combo.ISearchableTextCombo;
20
import org.openconcerto.utils.model.DefaultIListModel;
17 ilm 21
 
22
import java.awt.Dimension;
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.Insets;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28
import java.beans.PropertyChangeEvent;
29
import java.beans.PropertyChangeListener;
30
import java.util.Hashtable;
31
 
32
import javax.swing.ButtonGroup;
33
import javax.swing.ImageIcon;
34
import javax.swing.JLabel;
35
import javax.swing.JPanel;
36
import javax.swing.JSlider;
37
import javax.swing.JToggleButton;
38
import javax.swing.event.ChangeEvent;
39
import javax.swing.event.ChangeListener;
40
 
41
public class StatusPanel extends JPanel implements VilleRendererListener, ZoomListener {
42
 
43
    /**
44
     *
45
     */
46
    private static final long serialVersionUID = 4859531406653415107L;
47
    private final JLabel label = new JLabel("Status");
48
    private VilleRendererPanel v;
49
    private Ville currentVille = null;
50
    private JToggleButton radio1 = null;
51
    private JToggleButton radio2 = null;
52
    private final JSlider slider;
53
 
54
    public StatusPanel(final VilleRendererPanel villeRendererPanel, boolean viewOnly) {
55
        this.v = villeRendererPanel;
56
 
57
        this.setLayout(new GridBagLayout());
58
        // this.add(label);
59
        GridBagConstraints c = new GridBagConstraints();
60
        c.insets = new Insets(2, 0, 2, 0);
61
        c.gridx = 0;
62
        c.gridy = 0;
63
        c.weightx = 0;
64
        c.fill = GridBagConstraints.HORIZONTAL;
65
 
66
        c.insets = new Insets(2, 2, 2, 2);
25 ilm 67
        //
17 ilm 68
        if (!viewOnly) {
69
            c.gridx++;
70
            this.radio1 = new JToggleButton(new ImageIcon(StatusPanel.class.getResource("move.png")));
71
            this.radio1.setMargin(new Insets(2, 4, 2, 4));
72
            this.radio1.setSelected(true);
73
            this.add(this.radio1, c);
74
            this.radio2 = new JToggleButton(new ImageIcon(StatusPanel.class.getResource("draw.png")));
75
            c.gridx++;
76
            this.radio2.setMargin(new Insets(2, 4, 2, 4));
77
            this.add(this.radio2, c);
78
            ButtonGroup g = new ButtonGroup();
79
            g.add(this.radio2);
80
            g.add(this.radio1);
81
 
82
        }
83
        /* final JButton button = new JButton("Centrer"); */
25 ilm 84
        ISearchableTextCombo txt = new ISearchableTextCombo(ComboLockedMode.ITEMS_LOCKED, 1, 40);
17 ilm 85
        txt.addValueListener(new PropertyChangeListener() {
86
 
87
            public void propertyChange(PropertyChangeEvent evt) {
88
                final String trim = evt.getNewValue().toString().trim();
89
                StatusPanel.this.currentVille = Ville.getVilleFromVilleEtCode(trim);
90
                if (StatusPanel.this.currentVille != null) {
91
                    System.out.println("CurrentVille:" + StatusPanel.this.currentVille + " from:" + trim);
92
                    // button.setEnabled(currentVille != null);
93
                    StatusPanel.this.v.setAlwayVisible(StatusPanel.this.currentVille);
94
                    StatusPanel.this.v.setHighlight(StatusPanel.this.currentVille);
95
                    StatusPanel.this.v.centerScreenXYLambert(StatusPanel.this.currentVille.getXLambert(), StatusPanel.this.currentVille.getYLambert());
96
                }
97
            }
98
 
99
        });
100
        txt.setMinimumSearch(0);
101
        txt.setMaximumResult(200);
102
 
25 ilm 103
        txt.initCache(new DefaultIListModel<String>(new ITextComboCacheVille().getCache()));
17 ilm 104
        c.weightx = 1;
105
        c.gridx++;
106
        this.add(txt, c);
107
 
108
        c.weightx = 0;
109
        c.gridx++;
110
        this.slider = new JSlider(0, villeRendererPanel.getMaxZoomIndex(), 1);
111
 
112
        this.slider.setMajorTickSpacing(1);
113
        Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
114
        labelTable.put(new Integer(0), new JLabel("Zoom Minimum"));
115
        labelTable.put(new Integer(villeRendererPanel.getMaxZoomIndex()), new JLabel("Maximum"));
116
        this.slider.setLabelTable(labelTable);
117
        this.slider.setPaintLabels(true);
118
        // set min size since by default it is about 5*5
119
        // at the end so that labels are used
120
        final Dimension preferredSize = this.slider.getPreferredSize();
121
        this.slider.setMinimumSize(new Dimension((int) (preferredSize.width * 0.8), preferredSize.height));
122
 
123
        this.slider.addChangeListener(new ChangeListener() {
124
            public void stateChanged(ChangeEvent e) {
125
                StatusPanel.this.v.setZoomIndex(StatusPanel.this.slider.getValue());
126
            }
127
        });
128
        this.v.addZoomListener(this);
129
 
130
        this.add(this.slider, c);
131
        if (!viewOnly) { // Radio Listeners
132
            this.radio1.addActionListener(new ActionListener() {
133
 
134
                public void actionPerformed(ActionEvent e) {
135
                    StatusPanel.this.v.setMode(VilleRendererPanel.MODE_MOVE);
136
 
137
                }
138
            });
139
            this.radio2.addActionListener(new ActionListener() {
140
                public void actionPerformed(ActionEvent e) {
141
                    StatusPanel.this.v.setMode(VilleRendererPanel.MODE_DRAW);
142
                }
143
            });
144
 
145
            villeRendererPanel.addModeListener(new ModeListener() {
146
 
147
                public void modeChanged() {
148
                    if (StatusPanel.this.v.getMode() == VilleRendererPanel.MODE_MOVE)
149
                        StatusPanel.this.radio1.setSelected(true);
150
                    else
151
                        StatusPanel.this.radio2.setSelected(true);
152
                }
153
            });
154
 
155
        }
156
 
157
    }
158
 
159
    public void selectionChanged(VilleRendererPanel src) {
160
        this.label.setText(src.getStatus());
161
 
162
    }
163
 
164
    @Override
165
    public void zoomChanged(int newZoom) {
166
        if (newZoom != this.slider.getValue()) {
167
            this.slider.setValue(newZoom);
168
        }
169
 
170
    }
171
}