📄 calendaroption.java
字号:
/*--------------------------------------------------------------------------*
| Copyright (C) 2006 Christopher Kohlhaas |
| |
| This program 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. A copy of the license has been included with |
| these distribution in the COPYING file, if not go to www.fsf.org |
| |
| As a special exception, you are granted the permissions to link this |
| program with every library, which license fulfills the Open Source |
| Definition as published by the Open Source Initiative (OSI). |
*--------------------------------------------------------------------------*/
package org.rapla.gui.internal;
import java.awt.Component;
import java.util.Calendar;
import java.util.Locale;
import javax.swing.BoxLayout;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.rapla.components.calendar.RaplaNumber;
import org.rapla.components.calendar.RaplaTime;
import org.rapla.components.calendarview.WeekdayMapper;
import org.rapla.components.layout.TableLayout;
import org.rapla.entities.configuration.Preferences;
import org.rapla.entities.configuration.RaplaConfiguration;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaException;
import org.rapla.gui.CalendarOptions;
import org.rapla.gui.CalendarOptionsImpl;
import org.rapla.gui.OptionPanel;
import org.rapla.gui.RaplaGUIComponent;
public class CalendarOption extends RaplaGUIComponent implements OptionPanel {
JPanel panel = new JPanel();
JCheckBox showExceptionsField = new JCheckBox();
JComboBox colorBlocks = new JComboBox( new String[] {CalendarOptionsImpl.COLOR_RESOURCES, CalendarOptionsImpl.COLOR_EVENTS});
RaplaNumber rowsPerHourField = new RaplaNumber(new Double(1),new Double(1),new Double(12), false);
Preferences preferences;
CalendarOptions options;
RaplaTime worktimeStart;
RaplaTime worktimeEnd;
JPanel excludeDaysPanel = new JPanel();
JCheckBox[] box = new JCheckBox[7];
WeekdayMapper mapper;
public CalendarOption(RaplaContext sm) throws RaplaException {
super( sm);
mapper = new WeekdayMapper(getLocale());
worktimeStart = createRaplaTime();
worktimeStart.setRowsPerHour( 1 );
worktimeEnd = createRaplaTime();
worktimeEnd.setRowsPerHour( 1 );
double pre = TableLayout.PREFERRED;
double fill = TableLayout.FILL;
panel.setLayout( new TableLayout(new double[][] {{pre, 5, pre}, {pre,5,pre,5,pre,5,pre,5,pre,5, pre,fill}}));
showExceptionsField.setText("");
panel.add( new JLabel(getString("rows_per_hour")),"0,0" );
panel.add( rowsPerHourField,"2,0");
panel.add( new JLabel(getString("start_time")),"0,2" );
panel.add( worktimeStart, "2,2");
panel.add( new JLabel(getString("end_time")),"0,4" );
panel.add( worktimeEnd,"2,4");
panel.add( new JLabel(getString("color")),"0,6" );
panel.add( colorBlocks,"2,6");
colorBlocks.setRenderer( new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
public Component getListCellRendererComponent(JList list,Object value, int index, boolean isSelected, boolean cellHasFocus) {
if ( value != null) {
value = getString( (String) value );
}
return super.getListCellRendererComponent(list,value, index,isSelected,cellHasFocus);
}
});
panel.add( new JLabel(getString("display_exceptions")),"0,8");
panel.add( showExceptionsField,"2,8");
panel.add( new JLabel(getString("exclude_days")),"0,10,l,t");
panel.add( excludeDaysPanel,"2,10");
excludeDaysPanel.setLayout( new BoxLayout( excludeDaysPanel,BoxLayout.Y_AXIS));
for ( int i=0;i<box.length;i++) {
int weekday = mapper.dayForIndex( i);
box[i] = new JCheckBox(mapper.getName(weekday));
excludeDaysPanel.add( box[i]);
}
}
public JComponent getComponent() {
return panel;
}
public String getName(Locale locale) {
return getString("calendar");
}
public void setPreferences( Preferences preferences) {
this.preferences = preferences;
}
public void show() throws RaplaException {
RaplaConfiguration config = (RaplaConfiguration)preferences.getEntry( CalendarOptionsImpl.CALENDAR_OPTIONS);
if ( config != null) {
options = new CalendarOptionsImpl( config.getConfig());
} else {
options = getCalendarOptions();
}
colorBlocks.setSelectedItem( options.isEventColoring() ? CalendarOptionsImpl.COLOR_EVENTS : CalendarOptionsImpl.COLOR_RESOURCES );
showExceptionsField.setSelected( options.isExceptionsVisible());
rowsPerHourField.setNumber( new Long(options.getRowsPerHour()));
Calendar calendar = getRaplaLocale().createCalendar();
calendar.set( Calendar.HOUR_OF_DAY, options.getWorktimeStart());
calendar.set( Calendar.MINUTE, 0);
worktimeStart.setTime( calendar.getTime() );
calendar.set( Calendar.HOUR_OF_DAY, options.getWorktimeEnd());
worktimeEnd.setTime( calendar.getTime() );
for ( int i=0;i<box.length;i++) {
int weekday = mapper.dayForIndex( i);
box[i].setSelected( options.getExcludeDays().contains( new Integer( weekday)));
}
}
public void commit() {
DefaultConfiguration calendarOptions = new DefaultConfiguration("calendar-options");
DefaultConfiguration worktime = new DefaultConfiguration(CalendarOptionsImpl.WORKTIME);
DefaultConfiguration excludeDays = new DefaultConfiguration(CalendarOptionsImpl.EXCLUDE_DAYS);
DefaultConfiguration rowsPerHour = new DefaultConfiguration(CalendarOptionsImpl.ROWS_PER_HOUR);
DefaultConfiguration colorBlocks = new DefaultConfiguration(CalendarOptionsImpl.COLOR_BLOCKS);
DefaultConfiguration exceptionsVisible = new DefaultConfiguration(CalendarOptionsImpl.EXCEPTIONS_VISIBLE);
String colorValue = (String) this.colorBlocks.getSelectedItem();
if ( colorValue != null )
{
colorBlocks.setValue( colorValue );
}
Calendar calendar = getRaplaLocale().createCalendar();
calendar.setTime( worktimeStart.getTime());
int worktimeStart = calendar.get(Calendar.HOUR_OF_DAY);
calendar.setTime( worktimeEnd.getTime());
int worktimeEnd = calendar.get(Calendar.HOUR_OF_DAY);
worktime.setValue( worktimeStart + "-" + worktimeEnd );
exceptionsVisible.setValue( showExceptionsField.isSelected() );
rowsPerHour.setValue( rowsPerHourField.getNumber().intValue());
StringBuffer days = new StringBuffer();
for ( int i=0;i<box.length;i++) {
if (box[i].isSelected()) {
if ( days.length() > 0)
days.append(",");
days.append( mapper.dayForIndex( i ));
}
}
excludeDays.setValue( days.toString());
calendarOptions.addChild( worktime);
calendarOptions.addChild( colorBlocks );
calendarOptions.addChild( excludeDays);
calendarOptions.addChild( rowsPerHour);
calendarOptions.addChild( exceptionsVisible);
preferences.putEntry( CalendarOptionsImpl.CALENDAR_OPTIONS,new RaplaConfiguration( calendarOptions));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -