calendaroptionsimpl.java

来自「Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI」· Java 代码 · 共 124 行

JAVA
124
字号
/*--------------------------------------------------------------------------*
 | 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;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

import org.apache.avalon.framework.configuration.Configuration;
import org.rapla.framework.RaplaException;

/** <strong>WARNING!!</strong> This class should not be public to the outside. Please use the interface */
public class CalendarOptionsImpl implements CalendarOptions {
    public final static String CALENDAR_OPTIONS="org.rapla.calendarview";

    public static final String WORKTIME = "worktime";
    public static final String EXCLUDE_DAYS = "exclude-days";
    public static final String ROWS_PER_HOUR = "rows-per-hour";
    public final static String EXCEPTIONS_VISIBLE="exceptions-visible";
    public final static String COMPACT_COLUMNS="compact-columns";
    public final static String COLOR_BLOCKS="color";

    public final static String COLOR_RESOURCES="resources";
    public final static String COLOR_EVENTS="reservations";

    public final int MAX_INTERVALLS = 10000;

    Set excludeDays = new HashSet();

    int maxtime = -1;
    int mintime = -1;
    int rowsPerHour = 4;
    boolean exceptionsVisible;
    boolean compactColumns = false;
    Configuration config;
    String colorField;

    public CalendarOptionsImpl(Configuration config ) throws RaplaException {
        this.config = config;
        Configuration worktime = config.getChild( WORKTIME );
        StringTokenizer tokenizer = new StringTokenizer( worktime.getValue("8-18"), "-" );
        try {
            if ( tokenizer.hasMoreTokens() )
                mintime = new Integer( tokenizer.nextToken().toLowerCase().trim()).intValue( );
            if ( tokenizer.hasMoreTokens() )
                maxtime = new Integer( tokenizer.nextToken().toLowerCase().trim()).intValue( );
        } catch ( NumberFormatException e ) {
            throw new RaplaException( "Invalid time in " + worktime.getLocation( )
                                             + ". only numbers are allowed e.g. 8-18!");
        }
        if ( mintime == -1 || maxtime == -1 /*|| mintime >= maxtime*/ )
            throw new RaplaException("Invalid intervall in "
                                             + worktime.getLocation()
                                             + ". Use the following format 8-16 !");

        Configuration exclude = config.getChild( EXCLUDE_DAYS );
        tokenizer = new StringTokenizer( exclude.getValue(""), "," );
        while ( tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken().toLowerCase().trim();
            try {
                excludeDays.add( new Integer(token) );
            } catch ( NumberFormatException e ) {
                throw new RaplaException("Invalid day in "
                                                 + exclude.getLocation()
                                                 + ". only numbers are allowed!");
            }
        } // end of while ()

        rowsPerHour = config.getChild( ROWS_PER_HOUR ).getValueAsInteger( 4 );
        exceptionsVisible = config.getChild(EXCEPTIONS_VISIBLE).getValueAsBoolean(false);

        colorField = config.getChild( COLOR_BLOCKS ).getValue( COLOR_RESOURCES );
    }

    public Configuration getConfig() {
        return config;
    }

    public int getWorktimeStart() {
        return mintime;
    }

    public int getRowsPerHour() {
        return rowsPerHour;
    }

    public int getWorktimeEnd() {
        return maxtime;
    }

    public Set getExcludeDays() {
        return excludeDays;
    }

    public boolean isExceptionsVisible() {
        return exceptionsVisible;
    }

    public boolean isCompactColumns() {
    	return compactColumns;
    }

    public boolean isResourceColoring() {
        return colorField.equals( COLOR_RESOURCES );
    }

    public boolean isEventColoring() {
        return colorField.equals( COLOR_EVENTS );
    }


}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?