OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 177 → Rev 178

/trunk/jOpenCalendar/src/org/jopencalendar/ui/CalendarWithToolBar.java
35,6 → 35,8
private final DatePicker picker;
private String title;
final JScrollPane contentPane = new JScrollPane();
private int week;
private int year;
 
public CalendarWithToolBar(JCalendarItemProvider manager) {
this(manager, false);
42,13 → 44,13
 
public CalendarWithToolBar(JCalendarItemProvider manager, boolean showPrintButton) {
this.weekView = new WeekView(manager);
Calendar currentDate = Calendar.getInstance();
this.year = currentDate.get(Calendar.YEAR);
this.week = currentDate.get(Calendar.WEEK_OF_YEAR);
 
JPanel toolbar = new JPanel();
toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
 
Calendar cal = Calendar.getInstance();
int week = cal.get(Calendar.WEEK_OF_YEAR);
int year = cal.get(Calendar.YEAR);
JButton bPrevious = new JButton(new ImageIcon(this.getClass().getResource("left.png")));
JButton bNext = new JButton(new ImageIcon(this.getClass().getResource("right.png")));
configureButton(bPrevious);
59,8 → 61,7
 
@Override
public void actionPerformed(ActionEvent e) {
addWeek(1);
 
nextWeek();
}
});
bPrevious.addActionListener(new ActionListener() {
67,20 → 68,19
 
@Override
public void actionPerformed(ActionEvent e) {
addWeek(-1);
 
previousWeek();
}
});
 
toolbar.add(new JLabel("Semaine"));
spinWeek = new JSpinner(new SpinnerNumberModel(week, 1, 53, 1));
toolbar.add(spinWeek);
this.spinWeek = new JSpinner(new SpinnerNumberModel(this.week, 1, 53, 1));
toolbar.add(this.spinWeek);
toolbar.add(new JLabel(" de "));
spinYear = new JSpinner(new SpinnerNumberModel(year, 1000, year + 20, 1));
toolbar.add(spinYear);
this.spinYear = new JSpinner(new SpinnerNumberModel(this.year, 1000, this.year + 20, 1));
toolbar.add(this.spinYear);
//
this.picker = new DatePicker(false);
toolbar.add(picker);
toolbar.add(this.picker);
//
 
final JSlider zoomSlider = createZoomSlider(this.weekView);
124,59 → 124,59
c.fill = GridBagConstraints.BOTH;
c.weighty = 1;
 
contentPane.setBorder(BorderFactory.createEmptyBorder());
contentPane.setOpaque(false);
contentPane.setColumnHeaderView(new WeekViewHeader(weekView));
contentPane.setViewportView(weekView);
contentPane.getViewport().setBackground(Color.WHITE);
final MouseWheelListener[] l = contentPane.getMouseWheelListeners();
this.contentPane.setBorder(BorderFactory.createEmptyBorder());
this.contentPane.setOpaque(false);
this.contentPane.setColumnHeaderView(new WeekViewHeader(this.weekView));
this.contentPane.setViewportView(this.weekView);
this.contentPane.getViewport().setBackground(Color.WHITE);
final MouseWheelListener[] l = this.contentPane.getMouseWheelListeners();
for (int i = 0; i < l.length; i++) {
MouseWheelListener string = l[i];
contentPane.removeMouseWheelListener(string);
this.contentPane.removeMouseWheelListener(string);
}
contentPane.addMouseWheelListener(new MouseWheelListener() {
this.contentPane.addMouseWheelListener(new MouseWheelListener() {
 
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
weekView.mouseWheelMoved(e, l);
CalendarWithToolBar.this.weekView.mouseWheelMoved(e, l);
}
});
 
this.add(contentPane, c);
this.add(this.contentPane, c);
final int value = 300;
contentPane.getVerticalScrollBar().setValue(value);
weekView.loadWeek(week, year, false);
this.contentPane.getVerticalScrollBar().setValue(value);
this.weekView.loadWeek(this.week, this.year, false);
final ChangeListener listener = new ChangeListener() {
 
@Override
public void stateChanged(ChangeEvent e) {
Calendar c = getCurrentDate();
picker.setDate(c.getTime());
weekView.loadWeek(getWeek(), getYear(), false);
setDate(((Number) CalendarWithToolBar.this.spinWeek.getValue()).intValue(), CalendarWithToolBar.this.year);
 
}
};
spinWeek.addChangeListener(listener);
spinYear.addChangeListener(listener);
picker.addPropertyChangeListener("value", new PropertyChangeListener() {
this.spinWeek.addChangeListener(listener);
 
final ChangeListener listenerYear = new ChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getNewValue() != null) {
final Date d = (Date) evt.getNewValue();
public void stateChanged(ChangeEvent e) {
setDate(CalendarWithToolBar.this.week, ((Number) CalendarWithToolBar.this.spinYear.getValue()).intValue());
}
};
 
this.spinYear.addChangeListener(listenerYear);
 
this.picker.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
 
final Date d = CalendarWithToolBar.this.picker.getDate();
final Calendar c = Calendar.getInstance();
c.setTime(d);
final int y = c.get(Calendar.YEAR);
final int w = c.get(Calendar.WEEK_OF_YEAR);
spinWeek.removeChangeListener(listener);
spinYear.removeChangeListener(listener);
spinYear.setValue(y);
spinWeek.setValue(w);
spinWeek.addChangeListener(listener);
spinYear.addChangeListener(listener);
weekView.loadWeek(getWeek(), getYear(), false);
setDate(w, y);
}
 
}
});
 
}
201,21 → 201,27
return zoomSlider;
}
 
protected void addWeek(int i) {
Calendar c = getCurrentDate();
c.add(Calendar.DAY_OF_YEAR, i * 7);
final int year = c.get(Calendar.YEAR);
final int week = c.get(Calendar.WEEK_OF_YEAR);
spinYear.setValue(year);
spinWeek.setValue(week);
protected void nextWeek() {
if (getWeek() >= 52) {
setDate(1, this.year + 1);
} else {
setDate(this.week + 1, this.year);
}
}
 
protected void previousWeek() {
if (getWeek() == 1) {
setDate(52, this.year - 1);
} else {
setDate(this.week - 1, this.year);
}
}
 
public Calendar getCurrentDate() {
Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR, getYear());
c.set(Calendar.WEEK_OF_YEAR, getWeek());
c.set(Calendar.YEAR, this.year);
c.set(Calendar.WEEK_OF_YEAR, this.week);
return c;
}
 
224,9 → 230,37
}
 
public final void setCurrentDate(final Date d) {
this.picker.setDate(d);
Calendar c = Calendar.getInstance();
c.clear();
c.setTime(d);
this.setDate(c.get(Calendar.WEEK_OF_YEAR), c.get(Calendar.YEAR));
 
}
 
private void setDate(int week, int year) {
if (this.week != week || this.year != year) {
int oldWeek = this.week;
int oldYear = this.year;
this.week = week;
this.year = year;
if (this.week != oldWeek) {
this.spinWeek.setValue(week);
}
if (this.year != oldYear) {
this.spinYear.setValue(year);
}
 
Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR, this.year);
c.set(Calendar.WEEK_OF_YEAR, this.week);
this.picker.setDate(c.getTime());
 
CalendarWithToolBar.this.weekView.loadWeek(getWeek(), getYear(), false);
 
}
}
 
private void configureButton(JButton b) {
b.setOpaque(false);
b.setBorderPainted(false);
236,19 → 270,19
}
 
public void reload() {
weekView.reload();
this.weekView.reload();
}
 
public int getWeek() {
return ((Number) spinWeek.getValue()).intValue();
return this.week;
}
 
public int getYear() {
return ((Number) spinYear.getValue()).intValue();
return this.year;
}
 
public WeekView getWeekView() {
return weekView;
return this.weekView;
}
 
public void setTitle(String title) {
256,10 → 290,10
}
 
public void scrollTo(int hour) {
contentPane.getVerticalScrollBar().setValue(hour * weekView.getRowHeight());
this.contentPane.getVerticalScrollBar().setValue(hour * this.weekView.getRowHeight());
}
 
public JScrollPane getContentPane() {
return contentPane;
return this.contentPane;
}
}