mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
IJPL-156799 Refactor: replace every \t with 2 spaces
GitOrigin-RevId: 0ac6d51b9150a3c9af10c41f5ba86712bd1cc3c8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e972b6d37b
commit
d17bbf4da5
@@ -20,161 +20,161 @@ import com.michaelbaranov.microba.common.MicrobaComponent;
|
||||
*/
|
||||
public class Microba {
|
||||
|
||||
private static UIChangeListener changeListener = new UIChangeListener();
|
||||
private static UIChangeListener changeListener = new UIChangeListener();
|
||||
|
||||
/**
|
||||
* Initializes the library: installs L&F properties, sets up a L&F change
|
||||
* listener.
|
||||
* <p>
|
||||
* No need to call this method explicitly for desktop applications. You
|
||||
* should only call it in {@link Applet#init()}. This will handle browser
|
||||
* refresh button correctly.
|
||||
*
|
||||
*/
|
||||
public static synchronized void init() {
|
||||
setLookAndFeelProperties(UIManager.getLookAndFeel());
|
||||
/**
|
||||
* Initializes the library: installs L&F properties, sets up a L&F change
|
||||
* listener.
|
||||
* <p>
|
||||
* No need to call this method explicitly for desktop applications. You
|
||||
* should only call it in {@link Applet#init()}. This will handle browser
|
||||
* refresh button correctly.
|
||||
*
|
||||
*/
|
||||
public static synchronized void init() {
|
||||
setLookAndFeelProperties(UIManager.getLookAndFeel());
|
||||
|
||||
UIManager.removePropertyChangeListener(changeListener);
|
||||
UIManager.addPropertyChangeListener(changeListener);
|
||||
}
|
||||
UIManager.removePropertyChangeListener(changeListener);
|
||||
UIManager.addPropertyChangeListener(changeListener);
|
||||
}
|
||||
|
||||
private static synchronized void setLookAndFeelProperties(
|
||||
LookAndFeel lookAndFeel) {
|
||||
if (lookAndFeel == null)
|
||||
return;
|
||||
private static synchronized void setLookAndFeelProperties(
|
||||
LookAndFeel lookAndFeel) {
|
||||
if (lookAndFeel == null)
|
||||
return;
|
||||
|
||||
String packagePrefix = "com.michaelbaranov.microba.";
|
||||
String packagePrefix = "com.michaelbaranov.microba.";
|
||||
|
||||
// all L&F
|
||||
UIManager.put("microba.CalendarPaneUI", packagePrefix
|
||||
+ "calendar.ui.basic.BasicCalendarPaneUI");
|
||||
UIManager.put("microba.DatePickerUI", packagePrefix
|
||||
+ "calendar.ui.basic.BasicDatePickerUI");
|
||||
UIManager.put("microba.GradientUI", packagePrefix
|
||||
+ "gradient.ui.basic.BasicGradientUI");
|
||||
UIManager.put("microba.GradientEditorUI", packagePrefix
|
||||
+ "gradienteditor.ui.basic.BasicGradientEditorUI");
|
||||
UIManager.put("microba.MarkerBarUI", packagePrefix
|
||||
+ "marker.ui.basic.BasicMarkerBarUI");
|
||||
// all L&F
|
||||
UIManager.put("microba.CalendarPaneUI", packagePrefix
|
||||
+ "calendar.ui.basic.BasicCalendarPaneUI");
|
||||
UIManager.put("microba.DatePickerUI", packagePrefix
|
||||
+ "calendar.ui.basic.BasicDatePickerUI");
|
||||
UIManager.put("microba.GradientUI", packagePrefix
|
||||
+ "gradient.ui.basic.BasicGradientUI");
|
||||
UIManager.put("microba.GradientEditorUI", packagePrefix
|
||||
+ "gradienteditor.ui.basic.BasicGradientEditorUI");
|
||||
UIManager.put("microba.MarkerBarUI", packagePrefix
|
||||
+ "marker.ui.basic.BasicMarkerBarUI");
|
||||
|
||||
// particular L&F
|
||||
if (lookAndFeel.getID().equals("Windows")) {
|
||||
UIManager.put("microba.MarkerBarUI", packagePrefix
|
||||
+ "marker.ui.windows.WindowsMarkerBarUI");
|
||||
} else if (lookAndFeel.getID().equals("Metal")) {
|
||||
UIManager.put("microba.MarkerBarUI", packagePrefix
|
||||
+ "marker.ui.metal.MetalMarkerBarUI");
|
||||
} else if (lookAndFeel.getID().equals("Motif")) {
|
||||
UIManager.put("microba.MarkerBarUI", packagePrefix
|
||||
+ "marker.ui.motif.MotifMarkerBarUI");
|
||||
}
|
||||
// particular L&F
|
||||
if (lookAndFeel.getID().equals("Windows")) {
|
||||
UIManager.put("microba.MarkerBarUI", packagePrefix
|
||||
+ "marker.ui.windows.WindowsMarkerBarUI");
|
||||
} else if (lookAndFeel.getID().equals("Metal")) {
|
||||
UIManager.put("microba.MarkerBarUI", packagePrefix
|
||||
+ "marker.ui.metal.MetalMarkerBarUI");
|
||||
} else if (lookAndFeel.getID().equals("Motif")) {
|
||||
UIManager.put("microba.MarkerBarUI", packagePrefix
|
||||
+ "marker.ui.motif.MotifMarkerBarUI");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static final class UIChangeListener implements
|
||||
PropertyChangeListener {
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
if ("lookAndFeel".equals(event.getPropertyName())) {
|
||||
setLookAndFeelProperties((LookAndFeel) event.getNewValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final class UIChangeListener implements
|
||||
PropertyChangeListener {
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
if ("lookAndFeel".equals(event.getPropertyName())) {
|
||||
setLookAndFeelProperties((LookAndFeel) event.getNewValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map lookAndFeelToOverride = new HashMap();
|
||||
private static Map lookAndFeelToOverride = new HashMap();
|
||||
|
||||
/**
|
||||
* Sets per-Lokk&Feel map of color overrides.
|
||||
*
|
||||
*
|
||||
* @param lookAndFeel
|
||||
* look&feel ID
|
||||
* @param overrides
|
||||
* keys in the map are {@link String} constants, valuse are of
|
||||
* type {@link Color} or of type {@link String} (in this case,
|
||||
* {@link Color} values are obtained via
|
||||
* {@link UIManager#getColor(Object)}). May be <code>null</code>.
|
||||
*/
|
||||
public static void setColorOverrideMap(String lookAndFeel, Map overrides) {
|
||||
lookAndFeelToOverride.put(lookAndFeel, overrides);
|
||||
// TODO: refresh ui delegates
|
||||
}
|
||||
/**
|
||||
* Sets per-Lokk&Feel map of color overrides.
|
||||
*
|
||||
*
|
||||
* @param lookAndFeel
|
||||
* look&feel ID
|
||||
* @param overrides
|
||||
* keys in the map are {@link String} constants, valuse are of
|
||||
* type {@link Color} or of type {@link String} (in this case,
|
||||
* {@link Color} values are obtained via
|
||||
* {@link UIManager#getColor(Object)}). May be <code>null</code>.
|
||||
*/
|
||||
public static void setColorOverrideMap(String lookAndFeel, Map overrides) {
|
||||
lookAndFeelToOverride.put(lookAndFeel, overrides);
|
||||
// TODO: refresh ui delegates
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns overriden color for given component in current Look&Feel. The
|
||||
* algorithms is:
|
||||
* <ul>
|
||||
* <li>If the component overrides the constant (per-instance override),
|
||||
* then it is returned.
|
||||
* <li>If the library overrides the constant (per-Look&Feel override), then
|
||||
* it is returned.
|
||||
* <li>Else <code>null</code> is returned.
|
||||
* </ul>
|
||||
* This method is actually intended to be used by UI delegates of the
|
||||
* library.
|
||||
*
|
||||
* @param colorConstant
|
||||
* color constant
|
||||
* @param component
|
||||
* component of the library
|
||||
* @return overriden color or <code>null</code> if not overriden
|
||||
*/
|
||||
public static synchronized Color getOverridenColor(String colorConstant,
|
||||
MicrobaComponent component) {
|
||||
/**
|
||||
* Returns overriden color for given component in current Look&Feel. The
|
||||
* algorithms is:
|
||||
* <ul>
|
||||
* <li>If the component overrides the constant (per-instance override),
|
||||
* then it is returned.
|
||||
* <li>If the library overrides the constant (per-Look&Feel override), then
|
||||
* it is returned.
|
||||
* <li>Else <code>null</code> is returned.
|
||||
* </ul>
|
||||
* This method is actually intended to be used by UI delegates of the
|
||||
* library.
|
||||
*
|
||||
* @param colorConstant
|
||||
* color constant
|
||||
* @param component
|
||||
* component of the library
|
||||
* @return overriden color or <code>null</code> if not overriden
|
||||
*/
|
||||
public static synchronized Color getOverridenColor(String colorConstant,
|
||||
MicrobaComponent component) {
|
||||
|
||||
Map componentOverrideMap = component.getColorOverrideMap();
|
||||
if (componentOverrideMap != null) {
|
||||
if (componentOverrideMap.containsKey(colorConstant)) {
|
||||
Object val = componentOverrideMap.get(colorConstant);
|
||||
if (val instanceof Color)
|
||||
return (Color) val;
|
||||
else
|
||||
return UIManager.getColor(val);
|
||||
}
|
||||
}
|
||||
Map componentOverrideMap = component.getColorOverrideMap();
|
||||
if (componentOverrideMap != null) {
|
||||
if (componentOverrideMap.containsKey(colorConstant)) {
|
||||
Object val = componentOverrideMap.get(colorConstant);
|
||||
if (val instanceof Color)
|
||||
return (Color) val;
|
||||
else
|
||||
return UIManager.getColor(val);
|
||||
}
|
||||
}
|
||||
|
||||
String currentLookAndFeel = UIManager.getLookAndFeel().getID();
|
||||
Map overrides = (Map) lookAndFeelToOverride.get(currentLookAndFeel);
|
||||
if (overrides != null) {
|
||||
if (overrides.containsKey(colorConstant)) {
|
||||
Object val = overrides.get(colorConstant);
|
||||
if (val instanceof Color)
|
||||
return (Color) val;
|
||||
else
|
||||
return UIManager.getColor(val);
|
||||
String currentLookAndFeel = UIManager.getLookAndFeel().getID();
|
||||
Map overrides = (Map) lookAndFeelToOverride.get(currentLookAndFeel);
|
||||
if (overrides != null) {
|
||||
if (overrides.containsKey(colorConstant)) {
|
||||
Object val = overrides.get(colorConstant);
|
||||
if (val instanceof Color)
|
||||
return (Color) val;
|
||||
else
|
||||
return UIManager.getColor(val);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns overriden color for given component in current Look&Feel or a
|
||||
* default value. The algorithms is:
|
||||
* <ul>
|
||||
* <li>If the component overrides the constant (per-instance override),
|
||||
* then it is returned.
|
||||
* <li>If the library overrides the constant (per-Look&Feel override), then
|
||||
* it is returned.
|
||||
* <li>Else defaultColor is returned.
|
||||
* </ul>
|
||||
* This method is actually intended to be used by UI delegates of the
|
||||
* library.
|
||||
*
|
||||
* @param colorConstant
|
||||
* color constant
|
||||
* @param component
|
||||
* component of the library
|
||||
* @param defaultColor
|
||||
* @return overriden color or defaultColor if not overriden
|
||||
*/
|
||||
public static synchronized Color getOverridenColor(String colorConstant,
|
||||
MicrobaComponent component, Color defaultColor) {
|
||||
Color overriden = getOverridenColor(colorConstant, component);
|
||||
if (overriden != null)
|
||||
return overriden;
|
||||
else
|
||||
return defaultColor;
|
||||
}
|
||||
/**
|
||||
* Returns overriden color for given component in current Look&Feel or a
|
||||
* default value. The algorithms is:
|
||||
* <ul>
|
||||
* <li>If the component overrides the constant (per-instance override),
|
||||
* then it is returned.
|
||||
* <li>If the library overrides the constant (per-Look&Feel override), then
|
||||
* it is returned.
|
||||
* <li>Else defaultColor is returned.
|
||||
* </ul>
|
||||
* This method is actually intended to be used by UI delegates of the
|
||||
* library.
|
||||
*
|
||||
* @param colorConstant
|
||||
* color constant
|
||||
* @param component
|
||||
* component of the library
|
||||
* @param defaultColor
|
||||
* @return overriden color or defaultColor if not overriden
|
||||
*/
|
||||
public static synchronized Color getOverridenColor(String colorConstant,
|
||||
MicrobaComponent component, Color defaultColor) {
|
||||
Color overriden = getOverridenColor(colorConstant, component);
|
||||
if (overriden != null)
|
||||
return overriden;
|
||||
else
|
||||
return defaultColor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,45 +2,45 @@ package com.michaelbaranov.microba.calendar;
|
||||
|
||||
public interface CalendarColors {
|
||||
|
||||
// *** Header
|
||||
// *** Header
|
||||
|
||||
public static final String COLOR_CALENDAR_HEADER_FOREGROUND_ENABLED = "calendar.header.foreground.enabled";
|
||||
public static final String COLOR_CALENDAR_HEADER_FOREGROUND_ENABLED = "calendar.header.foreground.enabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_HEADER_FOREGROUND_DISABLED = "calendar.header.foreground.disabled";
|
||||
public static final String COLOR_CALENDAR_HEADER_FOREGROUND_DISABLED = "calendar.header.foreground.disabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_HEADER_BACKGROUND_ENABLED = "calendar.header.background.enabled";
|
||||
public static final String COLOR_CALENDAR_HEADER_BACKGROUND_ENABLED = "calendar.header.background.enabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_HEADER_BACKGROUND_DISABLED = "calendar.header.background.disabled";
|
||||
public static final String COLOR_CALENDAR_HEADER_BACKGROUND_DISABLED = "calendar.header.background.disabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_HEADER_FOREGROUND_WEEKEND_ENABLED = "calendar.header.foreground.weekend.enabled";
|
||||
public static final String COLOR_CALENDAR_HEADER_FOREGROUND_WEEKEND_ENABLED = "calendar.header.foreground.weekend.enabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_HEADER_FOREGROUND_WEEKEND_DISABLED = "calendar.header.foreground.weekend.disabled";
|
||||
public static final String COLOR_CALENDAR_HEADER_FOREGROUND_WEEKEND_DISABLED = "calendar.header.foreground.weekend.disabled";
|
||||
|
||||
// *** Dates grid
|
||||
public static final String COLOR_CALENDAR_GRID_FOCUS = "calendar.grid.focus";
|
||||
// *** Dates grid
|
||||
public static final String COLOR_CALENDAR_GRID_FOCUS = "calendar.grid.focus";
|
||||
|
||||
public static final String COLOR_CALENDAR_GRID_RESTRICTED = "calendar.grid.banned";
|
||||
public static final String COLOR_CALENDAR_GRID_RESTRICTED = "calendar.grid.banned";
|
||||
|
||||
//
|
||||
public static final String COLOR_CALENDAR_GRID_BACKGROUND_ENABLED = "calendar.grid.background.enabled";
|
||||
//
|
||||
public static final String COLOR_CALENDAR_GRID_BACKGROUND_ENABLED = "calendar.grid.background.enabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_GRID_BACKGROUND_DISABLED = "calendar.grid.background.disabled";
|
||||
public static final String COLOR_CALENDAR_GRID_BACKGROUND_DISABLED = "calendar.grid.background.disabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_GRID_FOREGROUND_ENABLED = "calendar.grid.foreground.enabled";
|
||||
public static final String COLOR_CALENDAR_GRID_FOREGROUND_ENABLED = "calendar.grid.foreground.enabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_GRID_FOREGROUND_DISABLED = "calendar.grid.foreground.disabled";
|
||||
public static final String COLOR_CALENDAR_GRID_FOREGROUND_DISABLED = "calendar.grid.foreground.disabled";
|
||||
|
||||
//
|
||||
public static final String COLOR_CALENDAR_GRID_SELECTION_BACKGROUND_ENABLED = "calendar.grid.selection.background.enabled";
|
||||
//
|
||||
public static final String COLOR_CALENDAR_GRID_SELECTION_BACKGROUND_ENABLED = "calendar.grid.selection.background.enabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_GRID_SELECTION_BACKGROUND_DISABLED = "calendar.grid.selection.background.disabled";
|
||||
public static final String COLOR_CALENDAR_GRID_SELECTION_BACKGROUND_DISABLED = "calendar.grid.selection.background.disabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_GRID_WEEKEND_FOREGROUND_ENABLED = "calendar.grid.weekend.foreground.enabled";
|
||||
public static final String COLOR_CALENDAR_GRID_WEEKEND_FOREGROUND_ENABLED = "calendar.grid.weekend.foreground.enabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_GRID_WEEKEND_FOREGROUND_DISABLED = "calendar.grid.weekend.foreground.disabled";
|
||||
public static final String COLOR_CALENDAR_GRID_WEEKEND_FOREGROUND_DISABLED = "calendar.grid.weekend.foreground.disabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_GRID_HOLIDAY_FOREGROUND_ENABLED = "calendar.grid.holiday.foreground.enabled";
|
||||
public static final String COLOR_CALENDAR_GRID_HOLIDAY_FOREGROUND_ENABLED = "calendar.grid.holiday.foreground.enabled";
|
||||
|
||||
public static final String COLOR_CALENDAR_GRID_HOLIDAY_FOREGROUND_DISABLED = "calendar.grid.holiday.foreground.disabled";
|
||||
public static final String COLOR_CALENDAR_GRID_HOLIDAY_FOREGROUND_DISABLED = "calendar.grid.holiday.foreground.disabled";
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,25 +11,25 @@ import java.util.Locale;
|
||||
*/
|
||||
public interface CalendarResources {
|
||||
|
||||
/**
|
||||
* A key for "today" word
|
||||
*/
|
||||
public static final String KEY_TODAY = "key.today";
|
||||
/**
|
||||
* A key for "today" word
|
||||
*/
|
||||
public static final String KEY_TODAY = "key.today";
|
||||
|
||||
/**
|
||||
* A key for "none" word
|
||||
*/
|
||||
public static final String KEY_NONE = "key.none";
|
||||
/**
|
||||
* A key for "none" word
|
||||
*/
|
||||
public static final String KEY_NONE = "key.none";
|
||||
|
||||
/**
|
||||
* This method is used to query tring resources for {@link CalendarPane} and
|
||||
* {@link DatePicker} classes. Should not return <code>null</code>.
|
||||
*
|
||||
* @param key
|
||||
* one of the keys defined by {@link CalendarResources}
|
||||
* @param locale
|
||||
* a {@link Locale}
|
||||
* @return localized string resource for a given key
|
||||
*/
|
||||
public String getResource(String key, Locale locale);
|
||||
/**
|
||||
* This method is used to query tring resources for {@link CalendarPane} and
|
||||
* {@link DatePicker} classes. Should not return <code>null</code>.
|
||||
*
|
||||
* @param key
|
||||
* one of the keys defined by {@link CalendarResources}
|
||||
* @param locale
|
||||
* a {@link Locale}
|
||||
* @return localized string resource for a given key
|
||||
*/
|
||||
public String getResource(String key, Locale locale);
|
||||
}
|
||||
|
||||
@@ -19,372 +19,372 @@ import com.michaelbaranov.microba.calendar.ui.DatePickerUI;
|
||||
*/
|
||||
public class DatePicker extends CalendarPane {
|
||||
|
||||
/**
|
||||
* The name of a "dateFormat" property.
|
||||
*/
|
||||
public static final String PROPERTY_NAME_DATE_FORMAT = "dateFormat";
|
||||
/**
|
||||
* The name of a "dateFormat" property.
|
||||
*/
|
||||
public static final String PROPERTY_NAME_DATE_FORMAT = "dateFormat";
|
||||
|
||||
/**
|
||||
* The name of a "fieldEditable" property.
|
||||
*/
|
||||
public static final String PROPERTY_NAME_FIELD_EDITABLE = "fieldEditable";
|
||||
/**
|
||||
* The name of a "fieldEditable" property.
|
||||
*/
|
||||
public static final String PROPERTY_NAME_FIELD_EDITABLE = "fieldEditable";
|
||||
|
||||
/**
|
||||
* The name of a "keepTime" property.
|
||||
*/
|
||||
public static final String PROPERTY_NAME_KEEP_TIME = "keepTime";
|
||||
/**
|
||||
* The name of a "keepTime" property.
|
||||
*/
|
||||
public static final String PROPERTY_NAME_KEEP_TIME = "keepTime";
|
||||
|
||||
/**
|
||||
* The name of a "pickerStyle" property.
|
||||
*/
|
||||
public static final String PROPERTY_NAME_PICKER_STYLE = "pickerStyle";
|
||||
/**
|
||||
* The name of a "pickerStyle" property.
|
||||
*/
|
||||
public static final String PROPERTY_NAME_PICKER_STYLE = "pickerStyle";
|
||||
|
||||
/**
|
||||
* The name of a "popupFocusable" property.
|
||||
*/
|
||||
public static final String PROPERTY_NAME_DROPDOWN_FOCUSABLE = "dropdownFocusable";
|
||||
/**
|
||||
* The name of a "popupFocusable" property.
|
||||
*/
|
||||
public static final String PROPERTY_NAME_DROPDOWN_FOCUSABLE = "dropdownFocusable";
|
||||
|
||||
/**
|
||||
* A constant for the "pickerStyle" property.
|
||||
*/
|
||||
public static final int PICKER_STYLE_FIELD_AND_BUTTON = 0x110;
|
||||
/**
|
||||
* A constant for the "pickerStyle" property.
|
||||
*/
|
||||
public static final int PICKER_STYLE_FIELD_AND_BUTTON = 0x110;
|
||||
|
||||
/**
|
||||
* A constant for the "pickerStyle" property.
|
||||
*/
|
||||
public static final int PICKER_STYLE_BUTTON = 0x120;
|
||||
/**
|
||||
* A constant for the "pickerStyle" property.
|
||||
*/
|
||||
public static final int PICKER_STYLE_BUTTON = 0x120;
|
||||
|
||||
private static final String uiClassID = "microba.DatePickerUI";
|
||||
private static final String uiClassID = "microba.DatePickerUI";
|
||||
|
||||
private DateFormat dateFormat;
|
||||
private DateFormat dateFormat;
|
||||
|
||||
private boolean fieldEditable;
|
||||
private boolean fieldEditable;
|
||||
|
||||
private boolean keepTime;
|
||||
private boolean keepTime;
|
||||
|
||||
private int pickerStyle;
|
||||
private int pickerStyle;
|
||||
|
||||
private boolean dropdownFocusable;
|
||||
private boolean dropdownFocusable;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker() {
|
||||
this(new Date(), DateFormat.MEDIUM, Locale.getDefault(), TimeZone
|
||||
.getDefault());
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker() {
|
||||
this(new Date(), DateFormat.MEDIUM, Locale.getDefault(), TimeZone
|
||||
.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate) {
|
||||
this(initialDate, DateFormat.MEDIUM, Locale.getDefault(), TimeZone
|
||||
.getDefault());
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate) {
|
||||
this(initialDate, DateFormat.MEDIUM, Locale.getDefault(), TimeZone
|
||||
.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, int dateStyle) {
|
||||
this(initialDate, dateStyle, Locale.getDefault(), TimeZone.getDefault());
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, int dateStyle) {
|
||||
this(initialDate, dateStyle, Locale.getDefault(), TimeZone.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, DateFormat dateFormat) {
|
||||
this(initialDate, dateFormat, Locale.getDefault(), TimeZone
|
||||
.getDefault());
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, DateFormat dateFormat) {
|
||||
this(initialDate, dateFormat, Locale.getDefault(), TimeZone
|
||||
.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, int dateStyle, Locale locale) {
|
||||
this(initialDate, dateStyle, locale, TimeZone.getDefault());
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, int dateStyle, Locale locale) {
|
||||
this(initialDate, dateStyle, locale, TimeZone.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, DateFormat dateFormat, Locale locale) {
|
||||
this(initialDate, dateFormat, locale, TimeZone.getDefault());
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, DateFormat dateFormat, Locale locale) {
|
||||
this(initialDate, dateFormat, locale, TimeZone.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, int dateStyle, Locale locale,
|
||||
TimeZone zone) {
|
||||
super(initialDate, CalendarPane.STYLE_CLASSIC, locale, zone);
|
||||
checkDateStyle(dateStyle);
|
||||
this.dateFormat = dateFormatFromStyle(dateStyle);
|
||||
this.fieldEditable = true;
|
||||
this.keepTime = true;
|
||||
this.pickerStyle = PICKER_STYLE_FIELD_AND_BUTTON;
|
||||
this.setStripTime(false);
|
||||
this.dropdownFocusable = true;
|
||||
updateUI();
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, int dateStyle, Locale locale,
|
||||
TimeZone zone) {
|
||||
super(initialDate, CalendarPane.STYLE_CLASSIC, locale, zone);
|
||||
checkDateStyle(dateStyle);
|
||||
this.dateFormat = dateFormatFromStyle(dateStyle);
|
||||
this.fieldEditable = true;
|
||||
this.keepTime = true;
|
||||
this.pickerStyle = PICKER_STYLE_FIELD_AND_BUTTON;
|
||||
this.setStripTime(false);
|
||||
this.dropdownFocusable = true;
|
||||
updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, DateFormat dateFormat, Locale locale,
|
||||
TimeZone zone) {
|
||||
super(initialDate, CalendarPane.STYLE_CLASSIC, locale, zone);
|
||||
checkDateFormat(dateFormat);
|
||||
this.dateFormat = dateFormat;
|
||||
this.fieldEditable = true;
|
||||
this.keepTime = true;
|
||||
this.pickerStyle = PICKER_STYLE_FIELD_AND_BUTTON;
|
||||
this.setStripTime(false);
|
||||
this.dropdownFocusable = true;
|
||||
updateUI();
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DatePicker(Date initialDate, DateFormat dateFormat, Locale locale,
|
||||
TimeZone zone) {
|
||||
super(initialDate, CalendarPane.STYLE_CLASSIC, locale, zone);
|
||||
checkDateFormat(dateFormat);
|
||||
this.dateFormat = dateFormat;
|
||||
this.fieldEditable = true;
|
||||
this.keepTime = true;
|
||||
this.pickerStyle = PICKER_STYLE_FIELD_AND_BUTTON;
|
||||
this.setStripTime(false);
|
||||
this.dropdownFocusable = true;
|
||||
updateUI();
|
||||
}
|
||||
|
||||
public String getUIClassID() {
|
||||
return uiClassID;
|
||||
}
|
||||
public String getUIClassID() {
|
||||
return uiClassID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date format.
|
||||
* <p>
|
||||
*
|
||||
* @return current date format
|
||||
* @see #setDateFormat(DateFormat)
|
||||
*/
|
||||
public DateFormat getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
/**
|
||||
* Returns the date format.
|
||||
* <p>
|
||||
*
|
||||
* @return current date format
|
||||
* @see #setDateFormat(DateFormat)
|
||||
*/
|
||||
public DateFormat getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the date format constant defined by {@link DateFormat} and updates
|
||||
* the control to reflect new date style.
|
||||
* <p>
|
||||
*
|
||||
* @param dateFormat
|
||||
* the date format constant to set
|
||||
* @see #getDateFormat()
|
||||
* @see DateFormat
|
||||
*/
|
||||
public void setDateFormat(DateFormat dateFormat) {
|
||||
checkDateFormat(dateFormat);
|
||||
Object oldValue = this.dateFormat;
|
||||
this.dateFormat = dateFormat;
|
||||
firePropertyChange(PROPERTY_NAME_DATE_FORMAT, oldValue, dateFormat);
|
||||
}
|
||||
/**
|
||||
* Sets the date format constant defined by {@link DateFormat} and updates
|
||||
* the control to reflect new date style.
|
||||
* <p>
|
||||
*
|
||||
* @param dateFormat
|
||||
* the date format constant to set
|
||||
* @see #getDateFormat()
|
||||
* @see DateFormat
|
||||
*/
|
||||
public void setDateFormat(DateFormat dateFormat) {
|
||||
checkDateFormat(dateFormat);
|
||||
Object oldValue = this.dateFormat;
|
||||
this.dateFormat = dateFormat;
|
||||
firePropertyChange(PROPERTY_NAME_DATE_FORMAT, oldValue, dateFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the edit field of the control editable by the user?
|
||||
* <p>
|
||||
* If not editable, the user can not type in the date and can only use
|
||||
* calendar drop-down to select dates.
|
||||
*
|
||||
* @return <code>true</code> if the edit field is editable,
|
||||
* <code>false</code> otherwise
|
||||
*
|
||||
* @see #setFieldEditable(boolean)
|
||||
*/
|
||||
public boolean isFieldEditable() {
|
||||
return fieldEditable;
|
||||
}
|
||||
/**
|
||||
* Is the edit field of the control editable by the user?
|
||||
* <p>
|
||||
* If not editable, the user can not type in the date and can only use
|
||||
* calendar drop-down to select dates.
|
||||
*
|
||||
* @return <code>true</code> if the edit field is editable,
|
||||
* <code>false</code> otherwise
|
||||
*
|
||||
* @see #setFieldEditable(boolean)
|
||||
*/
|
||||
public boolean isFieldEditable() {
|
||||
return fieldEditable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables editing of the edit field by the user.
|
||||
* <p>
|
||||
* If not editable, the user can not type in the date and can only use
|
||||
* calendar drop-down to select dates.
|
||||
*
|
||||
* @param fieldEditable
|
||||
* the editable value to set
|
||||
*
|
||||
* @see #isFieldEditable()
|
||||
*/
|
||||
public void setFieldEditable(boolean fieldEditable) {
|
||||
boolean old = this.fieldEditable;
|
||||
this.fieldEditable = fieldEditable;
|
||||
firePropertyChange(PROPERTY_NAME_FIELD_EDITABLE, old, fieldEditable);
|
||||
}
|
||||
/**
|
||||
* Enables or disables editing of the edit field by the user.
|
||||
* <p>
|
||||
* If not editable, the user can not type in the date and can only use
|
||||
* calendar drop-down to select dates.
|
||||
*
|
||||
* @param fieldEditable
|
||||
* the editable value to set
|
||||
*
|
||||
* @see #isFieldEditable()
|
||||
*/
|
||||
public void setFieldEditable(boolean fieldEditable) {
|
||||
boolean old = this.fieldEditable;
|
||||
this.fieldEditable = fieldEditable;
|
||||
firePropertyChange(PROPERTY_NAME_FIELD_EDITABLE, old, fieldEditable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the dropdown focusable?
|
||||
* <p>
|
||||
* If not focusable, the dropdown calendar will lack some keyboard input
|
||||
* capabilities.
|
||||
*
|
||||
* @return <code>true</code> if the dropdown is focusable,
|
||||
* <code>false</code> otherwise
|
||||
*
|
||||
* @see #setDropdownFocusable(boolean)
|
||||
*/
|
||||
public boolean isDropdownFocusable() {
|
||||
return dropdownFocusable;
|
||||
}
|
||||
/**
|
||||
* Is the dropdown focusable?
|
||||
* <p>
|
||||
* If not focusable, the dropdown calendar will lack some keyboard input
|
||||
* capabilities.
|
||||
*
|
||||
* @return <code>true</code> if the dropdown is focusable,
|
||||
* <code>false</code> otherwise
|
||||
*
|
||||
* @see #setDropdownFocusable(boolean)
|
||||
*/
|
||||
public boolean isDropdownFocusable() {
|
||||
return dropdownFocusable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables focusability of the dropdown calendar.
|
||||
* <p>
|
||||
* If not focusable, the dropdown calendar will lack some keyboard input
|
||||
* capabilities.
|
||||
*
|
||||
* @param popupFocusable
|
||||
* the focusable value to set
|
||||
*
|
||||
* @see #isDropdownFocusable()
|
||||
*/
|
||||
public void setDropdownFocusable(boolean popupFocusable) {
|
||||
boolean old = this.dropdownFocusable;
|
||||
this.dropdownFocusable = popupFocusable;
|
||||
firePropertyChange(PROPERTY_NAME_DROPDOWN_FOCUSABLE, old,
|
||||
popupFocusable);
|
||||
}
|
||||
/**
|
||||
* Enables or disables focusability of the dropdown calendar.
|
||||
* <p>
|
||||
* If not focusable, the dropdown calendar will lack some keyboard input
|
||||
* capabilities.
|
||||
*
|
||||
* @param popupFocusable
|
||||
* the focusable value to set
|
||||
*
|
||||
* @see #isDropdownFocusable()
|
||||
*/
|
||||
public void setDropdownFocusable(boolean popupFocusable) {
|
||||
boolean old = this.dropdownFocusable;
|
||||
this.dropdownFocusable = popupFocusable;
|
||||
firePropertyChange(PROPERTY_NAME_DROPDOWN_FOCUSABLE, old,
|
||||
popupFocusable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does UI try to preserve time components entered in the edit field?
|
||||
* <p>
|
||||
* If <code>true</code> and if the date format has some time fields
|
||||
* (hours, minutes, seconds, fraction of second), the UI tries to respect
|
||||
* the time fields' values entered by user as much as possible.
|
||||
* <p>
|
||||
* Note: to be able to receive time portion of the date, make sure
|
||||
* {@link #isStripTime()} is <code>false</code> (the dafualt).
|
||||
*
|
||||
* @return <code>true</code> if the UI respects time fields,
|
||||
* <code>false</code> otherwise
|
||||
* @see #setKeepTime(boolean)
|
||||
* @see #setStripTime(boolean)
|
||||
* @see #isStripTime()
|
||||
*
|
||||
*/
|
||||
public boolean isKeepTime() {
|
||||
return keepTime;
|
||||
}
|
||||
/**
|
||||
* Does UI try to preserve time components entered in the edit field?
|
||||
* <p>
|
||||
* If <code>true</code> and if the date format has some time fields
|
||||
* (hours, minutes, seconds, fraction of second), the UI tries to respect
|
||||
* the time fields' values entered by user as much as possible.
|
||||
* <p>
|
||||
* Note: to be able to receive time portion of the date, make sure
|
||||
* {@link #isStripTime()} is <code>false</code> (the dafualt).
|
||||
*
|
||||
* @return <code>true</code> if the UI respects time fields,
|
||||
* <code>false</code> otherwise
|
||||
* @see #setKeepTime(boolean)
|
||||
* @see #setStripTime(boolean)
|
||||
* @see #isStripTime()
|
||||
*
|
||||
*/
|
||||
public boolean isKeepTime() {
|
||||
return keepTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the UI should try to preserve time components entered in
|
||||
* the edit field.
|
||||
* <p>
|
||||
* If <code>true</code> and if the date format has some time fields
|
||||
* (hours, minutes, seconds, fraction of second), the UI tries to respect
|
||||
* the time fields' values entered by user as much as possible.
|
||||
* <p>
|
||||
* Note: to be able to receive time portion of the date, make sure
|
||||
* {@link #isStripTime()} is <code>false</code> (the dafualt).
|
||||
*
|
||||
* @param keepTime
|
||||
* <code>true</code> to make the UI respects time fields,
|
||||
* <code>false</code> otherwise
|
||||
* @see #isKeepTime()
|
||||
* @see #setStripTime(boolean)
|
||||
* @see #isStripTime()
|
||||
*/
|
||||
public void setKeepTime(boolean keepTime) {
|
||||
boolean old = this.keepTime;
|
||||
this.keepTime = keepTime;
|
||||
firePropertyChange(PROPERTY_NAME_KEEP_TIME, old, keepTime);
|
||||
}
|
||||
/**
|
||||
* Determines if the UI should try to preserve time components entered in
|
||||
* the edit field.
|
||||
* <p>
|
||||
* If <code>true</code> and if the date format has some time fields
|
||||
* (hours, minutes, seconds, fraction of second), the UI tries to respect
|
||||
* the time fields' values entered by user as much as possible.
|
||||
* <p>
|
||||
* Note: to be able to receive time portion of the date, make sure
|
||||
* {@link #isStripTime()} is <code>false</code> (the dafualt).
|
||||
*
|
||||
* @param keepTime
|
||||
* <code>true</code> to make the UI respects time fields,
|
||||
* <code>false</code> otherwise
|
||||
* @see #isKeepTime()
|
||||
* @see #setStripTime(boolean)
|
||||
* @see #isStripTime()
|
||||
*/
|
||||
public void setKeepTime(boolean keepTime) {
|
||||
boolean old = this.keepTime;
|
||||
this.keepTime = keepTime;
|
||||
firePropertyChange(PROPERTY_NAME_KEEP_TIME, old, keepTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current visual style of the picker control.
|
||||
* <p>
|
||||
* NOTE: do not confuse with {@link #getStyle()}.
|
||||
*
|
||||
* @return current visual style constant.
|
||||
*/
|
||||
public int getPickerStyle() {
|
||||
return pickerStyle;
|
||||
}
|
||||
/**
|
||||
* Returns current visual style of the picker control.
|
||||
* <p>
|
||||
* NOTE: do not confuse with {@link #getStyle()}.
|
||||
*
|
||||
* @return current visual style constant.
|
||||
*/
|
||||
public int getPickerStyle() {
|
||||
return pickerStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current visual style of the picker control.
|
||||
* <p>
|
||||
* The control is then updated to reflect the new style.
|
||||
* <p>
|
||||
* NOTE: do not confuse with {@link #getStyle()}.
|
||||
*
|
||||
* @param pickerStyle
|
||||
* the style to set
|
||||
* @see #PICKER_STYLE_BUTTON
|
||||
* @see #PICKER_STYLE_FIELD_AND_BUTTON
|
||||
*/
|
||||
public void setPickerStyle(int pickerStyle) {
|
||||
pickerStyle = checkPickerStyle(pickerStyle);
|
||||
int oldValue = this.pickerStyle;
|
||||
this.pickerStyle = pickerStyle;
|
||||
firePropertyChange(PROPERTY_NAME_PICKER_STYLE, oldValue, pickerStyle);
|
||||
}
|
||||
/**
|
||||
* Sets the current visual style of the picker control.
|
||||
* <p>
|
||||
* The control is then updated to reflect the new style.
|
||||
* <p>
|
||||
* NOTE: do not confuse with {@link #getStyle()}.
|
||||
*
|
||||
* @param pickerStyle
|
||||
* the style to set
|
||||
* @see #PICKER_STYLE_BUTTON
|
||||
* @see #PICKER_STYLE_FIELD_AND_BUTTON
|
||||
*/
|
||||
public void setPickerStyle(int pickerStyle) {
|
||||
pickerStyle = checkPickerStyle(pickerStyle);
|
||||
int oldValue = this.pickerStyle;
|
||||
this.pickerStyle = pickerStyle;
|
||||
firePropertyChange(PROPERTY_NAME_PICKER_STYLE, oldValue, pickerStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* A shortucut method to switch picker style between
|
||||
* {@link #PICKER_STYLE_FIELD_AND_BUTTON} and {@link #PICKER_STYLE_BUTTON}
|
||||
*
|
||||
* @param buttonOnly
|
||||
* <code>true</code> to set {@link #PICKER_STYLE_BUTTON},
|
||||
* <code>false</code> to set
|
||||
* {@link #PICKER_STYLE_FIELD_AND_BUTTON}
|
||||
*/
|
||||
public void showButtonOnly(boolean buttonOnly) {
|
||||
if (buttonOnly)
|
||||
setPickerStyle(PICKER_STYLE_BUTTON);
|
||||
else
|
||||
setPickerStyle(PICKER_STYLE_FIELD_AND_BUTTON);
|
||||
}
|
||||
/**
|
||||
* A shortucut method to switch picker style between
|
||||
* {@link #PICKER_STYLE_FIELD_AND_BUTTON} and {@link #PICKER_STYLE_BUTTON}
|
||||
*
|
||||
* @param buttonOnly
|
||||
* <code>true</code> to set {@link #PICKER_STYLE_BUTTON},
|
||||
* <code>false</code> to set
|
||||
* {@link #PICKER_STYLE_FIELD_AND_BUTTON}
|
||||
*/
|
||||
public void showButtonOnly(boolean buttonOnly) {
|
||||
if (buttonOnly)
|
||||
setPickerStyle(PICKER_STYLE_BUTTON);
|
||||
else
|
||||
setPickerStyle(PICKER_STYLE_FIELD_AND_BUTTON);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the calendar dropdown.
|
||||
*/
|
||||
public void showPopup() {
|
||||
((DatePickerUI) getUI()).showPopup(true);
|
||||
}
|
||||
/**
|
||||
* Displays the calendar dropdown.
|
||||
*/
|
||||
public void showPopup() {
|
||||
((DatePickerUI) getUI()).showPopup(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides the calendar dropdown without selecting a date.
|
||||
*/
|
||||
public void hidePopup() {
|
||||
((DatePickerUI) getUI()).showPopup(false);
|
||||
}
|
||||
/**
|
||||
* Hides the calendar dropdown without selecting a date.
|
||||
*/
|
||||
public void hidePopup() {
|
||||
((DatePickerUI) getUI()).showPopup(false);
|
||||
}
|
||||
|
||||
public boolean commitEdit() {
|
||||
try {
|
||||
((DatePickerUI) getUI()).commit();
|
||||
fireCommitEvent(true);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public boolean commitEdit() {
|
||||
try {
|
||||
((DatePickerUI) getUI()).commit();
|
||||
fireCommitEvent(true);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void revertEdit() {
|
||||
((DatePickerUI) getUI()).revert();
|
||||
fireCommitEvent(false);
|
||||
}
|
||||
public void revertEdit() {
|
||||
((DatePickerUI) getUI()).revert();
|
||||
fireCommitEvent(false);
|
||||
}
|
||||
|
||||
private void checkDateStyle(int style) {
|
||||
if (style != DateFormat.SHORT && style != DateFormat.MEDIUM
|
||||
&& style != DateFormat.LONG)
|
||||
throw new IllegalArgumentException("dateStyle: unrecognized style");
|
||||
}
|
||||
private void checkDateStyle(int style) {
|
||||
if (style != DateFormat.SHORT && style != DateFormat.MEDIUM
|
||||
&& style != DateFormat.LONG)
|
||||
throw new IllegalArgumentException("dateStyle: unrecognized style");
|
||||
}
|
||||
|
||||
private int checkPickerStyle(int style) {
|
||||
if (style == 0)
|
||||
style = PICKER_STYLE_FIELD_AND_BUTTON;
|
||||
if (style != PICKER_STYLE_FIELD_AND_BUTTON
|
||||
&& style != PICKER_STYLE_BUTTON)
|
||||
throw new IllegalArgumentException(PROPERTY_NAME_PICKER_STYLE
|
||||
+ ": unrecognized style");
|
||||
return style;
|
||||
}
|
||||
private int checkPickerStyle(int style) {
|
||||
if (style == 0)
|
||||
style = PICKER_STYLE_FIELD_AND_BUTTON;
|
||||
if (style != PICKER_STYLE_FIELD_AND_BUTTON
|
||||
&& style != PICKER_STYLE_BUTTON)
|
||||
throw new IllegalArgumentException(PROPERTY_NAME_PICKER_STYLE
|
||||
+ ": unrecognized style");
|
||||
return style;
|
||||
}
|
||||
|
||||
private void checkDateFormat(DateFormat dateFormat) {
|
||||
if (dateFormat == null)
|
||||
throw new IllegalArgumentException("dateFormat: null value");
|
||||
}
|
||||
private void checkDateFormat(DateFormat dateFormat) {
|
||||
if (dateFormat == null)
|
||||
throw new IllegalArgumentException("dateFormat: null value");
|
||||
}
|
||||
|
||||
private DateFormat dateFormatFromStyle(int dateStyle) {
|
||||
DateFormat df = DateFormat.getDateInstance(dateStyle, this.getLocale());
|
||||
df.setTimeZone(this.getZone());
|
||||
return df;
|
||||
}
|
||||
private DateFormat dateFormatFromStyle(int dateStyle) {
|
||||
DateFormat df = DateFormat.getDateInstance(dateStyle, this.getLocale());
|
||||
df.setTimeZone(this.getZone());
|
||||
return df;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,58 +26,58 @@ import com.michaelbaranov.microba.calendar.ui.DatePickerUI;
|
||||
*/
|
||||
public class DatePickerCellEditor extends DefaultCellEditor {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Note: you probably will want to set the property of the
|
||||
* {@link DatePicker} {@value DatePicker#PROPERTY_NAME_DROPDOWN_FOCUSABLE}
|
||||
* to <code>false</code> before using it to construct
|
||||
* {@link DatePickerCellEditor}.
|
||||
*
|
||||
* @param datePicker
|
||||
* the editor component
|
||||
*/
|
||||
public DatePickerCellEditor(final DatePicker datePicker) {
|
||||
// trick: supply a dummy JCheckBox
|
||||
super(new JCheckBox());
|
||||
// get back the dummy JCheckBox
|
||||
JCheckBox checkBox = (JCheckBox) this.editorComponent;
|
||||
// remove listeners installed by super()
|
||||
checkBox.removeActionListener(this.delegate);
|
||||
// replace editor component with own
|
||||
this.editorComponent = datePicker;
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Note: you probably will want to set the property of the
|
||||
* {@link DatePicker} {@value DatePicker#PROPERTY_NAME_DROPDOWN_FOCUSABLE}
|
||||
* to <code>false</code> before using it to construct
|
||||
* {@link DatePickerCellEditor}.
|
||||
*
|
||||
* @param datePicker
|
||||
* the editor component
|
||||
*/
|
||||
public DatePickerCellEditor(final DatePicker datePicker) {
|
||||
// trick: supply a dummy JCheckBox
|
||||
super(new JCheckBox());
|
||||
// get back the dummy JCheckBox
|
||||
JCheckBox checkBox = (JCheckBox) this.editorComponent;
|
||||
// remove listeners installed by super()
|
||||
checkBox.removeActionListener(this.delegate);
|
||||
// replace editor component with own
|
||||
this.editorComponent = datePicker;
|
||||
|
||||
// set simple look
|
||||
((DatePickerUI) datePicker.getUI()).setSimpeLook(true);
|
||||
// set simple look
|
||||
((DatePickerUI) datePicker.getUI()).setSimpeLook(true);
|
||||
|
||||
// replace delegate with own
|
||||
this.delegate = new EditorDelegate() {
|
||||
public void setValue(Object value) {
|
||||
try {
|
||||
((DatePicker) editorComponent).setDate((Date) value);
|
||||
} catch (PropertyVetoException e) {
|
||||
}
|
||||
}
|
||||
// replace delegate with own
|
||||
this.delegate = new EditorDelegate() {
|
||||
public void setValue(Object value) {
|
||||
try {
|
||||
((DatePicker) editorComponent).setDate((Date) value);
|
||||
} catch (PropertyVetoException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public Object getCellEditorValue() {
|
||||
return ((DatePicker) editorComponent).getDate();
|
||||
}
|
||||
public Object getCellEditorValue() {
|
||||
return ((DatePicker) editorComponent).getDate();
|
||||
}
|
||||
|
||||
public void cancelCellEditing() {
|
||||
((DatePicker) editorComponent).commitOrRevert();
|
||||
super.cancelCellEditing();
|
||||
}
|
||||
public void cancelCellEditing() {
|
||||
((DatePicker) editorComponent).commitOrRevert();
|
||||
super.cancelCellEditing();
|
||||
}
|
||||
|
||||
public boolean stopCellEditing() {
|
||||
((DatePicker) editorComponent).commitOrRevert();
|
||||
return super.stopCellEditing();
|
||||
}
|
||||
public boolean stopCellEditing() {
|
||||
((DatePicker) editorComponent).commitOrRevert();
|
||||
return super.stopCellEditing();
|
||||
}
|
||||
|
||||
};
|
||||
// install listeners
|
||||
datePicker.addActionListener(delegate);
|
||||
// do not set it to 1
|
||||
setClickCountToStart(2);
|
||||
}
|
||||
};
|
||||
// install listeners
|
||||
datePicker.addActionListener(delegate);
|
||||
// do not set it to 1
|
||||
setClickCountToStart(2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,30 +14,30 @@ import java.util.Properties;
|
||||
*/
|
||||
public class DefaultCalendarResources implements CalendarResources {
|
||||
|
||||
private static final String RESOURCE_FILE = "DefaultCalendarResources.properties";
|
||||
private static final String RESOURCE_FILE = "DefaultCalendarResources.properties";
|
||||
|
||||
private static final String DEFAULT_LANGUAGE = "en";
|
||||
private static final String DEFAULT_LANGUAGE = "en";
|
||||
|
||||
private Properties strings = new Properties();
|
||||
private Properties strings = new Properties();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DefaultCalendarResources() {
|
||||
try {
|
||||
strings.load(DefaultCalendarResources.class
|
||||
.getResourceAsStream(RESOURCE_FILE));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DefaultCalendarResources() {
|
||||
try {
|
||||
strings.load(DefaultCalendarResources.class
|
||||
.getResourceAsStream(RESOURCE_FILE));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getResource(String key, Locale locale) {
|
||||
String language = locale.getLanguage();
|
||||
String word = (String) strings.get(language + "." + key);
|
||||
if (word == null)
|
||||
word = (String) strings.get(DEFAULT_LANGUAGE + "." + key);
|
||||
return word;
|
||||
}
|
||||
public String getResource(String key, Locale locale) {
|
||||
String language = locale.getLanguage();
|
||||
String word = (String) strings.get(language + "." + key);
|
||||
if (word == null)
|
||||
word = (String) strings.get(DEFAULT_LANGUAGE + "." + key);
|
||||
return word;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,43 +13,43 @@ import com.michaelbaranov.microba.common.Policy;
|
||||
*
|
||||
*/
|
||||
public interface HolidayPolicy extends Policy {
|
||||
/**
|
||||
* This method is used to check if a date is a holliday. Holliday dates are
|
||||
* displayed by contols in a special way.
|
||||
*
|
||||
* @param source
|
||||
* a control calling this method
|
||||
* @param date
|
||||
* a date to check
|
||||
* @return <code>true</code> if given <code>date</code> is a holliday
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
public boolean isHolliday(Object source, Calendar date);
|
||||
/**
|
||||
* This method is used to check if a date is a holliday. Holliday dates are
|
||||
* displayed by contols in a special way.
|
||||
*
|
||||
* @param source
|
||||
* a control calling this method
|
||||
* @param date
|
||||
* a date to check
|
||||
* @return <code>true</code> if given <code>date</code> is a holliday
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
public boolean isHolliday(Object source, Calendar date);
|
||||
|
||||
/**
|
||||
* This method is used to check if a date is a weekend date. Implementation
|
||||
* should only check day of week component of the date.
|
||||
*
|
||||
* @param source
|
||||
* a control calling this method
|
||||
* @param date
|
||||
* a date to check
|
||||
* @return <code>true</code> if given <code>date</code> is weekend date
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
public boolean isWeekend(Object source, Calendar date);
|
||||
/**
|
||||
* This method is used to check if a date is a weekend date. Implementation
|
||||
* should only check day of week component of the date.
|
||||
*
|
||||
* @param source
|
||||
* a control calling this method
|
||||
* @param date
|
||||
* a date to check
|
||||
* @return <code>true</code> if given <code>date</code> is weekend date
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
public boolean isWeekend(Object source, Calendar date);
|
||||
|
||||
/**
|
||||
* This method is used to query a description for a holliday date. Note,
|
||||
* that implementation may return localized results based on the locale
|
||||
* passed with the date.
|
||||
*
|
||||
* @param source
|
||||
* a control calling this method
|
||||
* @param date
|
||||
* a holliday date to get the description for
|
||||
* @return a localized name (a description) for a holliday
|
||||
*/
|
||||
public String getHollidayName(Object source, Calendar date);
|
||||
/**
|
||||
* This method is used to query a description for a holliday date. Note,
|
||||
* that implementation may return localized results based on the locale
|
||||
* passed with the date.
|
||||
*
|
||||
* @param source
|
||||
* a control calling this method
|
||||
* @param date
|
||||
* a holliday date to get the description for
|
||||
* @return a localized name (a description) for a holliday
|
||||
*/
|
||||
public String getHollidayName(Object source, Calendar date);
|
||||
|
||||
}
|
||||
|
||||
@@ -13,28 +13,28 @@ import com.michaelbaranov.microba.common.Policy;
|
||||
*/
|
||||
public interface VetoPolicy extends Policy {
|
||||
|
||||
/**
|
||||
* This method is used to check if a date is restricted. Restricted dates
|
||||
* can not be selected by users in a control.
|
||||
*
|
||||
* @param source
|
||||
* a control calling this method
|
||||
* @param date
|
||||
* a date to check. Is never <code>null</code>
|
||||
* @return <code>true</code> if given <code>date</code> is restricted
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
public boolean isRestricted(Object source, Calendar date);
|
||||
/**
|
||||
* This method is used to check if a date is restricted. Restricted dates
|
||||
* can not be selected by users in a control.
|
||||
*
|
||||
* @param source
|
||||
* a control calling this method
|
||||
* @param date
|
||||
* a date to check. Is never <code>null</code>
|
||||
* @return <code>true</code> if given <code>date</code> is restricted
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
public boolean isRestricted(Object source, Calendar date);
|
||||
|
||||
/**
|
||||
* This method is used to check if no-date (<code>null</code> date) is
|
||||
* restricted. Restricted dates can not be selected by users in a control.
|
||||
*
|
||||
* @param source
|
||||
* a control calling this method
|
||||
* @return <code>false</code> to allow no-date, <code>true</code>
|
||||
* otherwise
|
||||
*/
|
||||
public boolean isRestrictNull(Object source);
|
||||
/**
|
||||
* This method is used to check if no-date (<code>null</code> date) is
|
||||
* restricted. Restricted dates can not be selected by users in a control.
|
||||
*
|
||||
* @param source
|
||||
* a control calling this method
|
||||
* @return <code>false</code> to allow no-date, <code>true</code>
|
||||
* otherwise
|
||||
*/
|
||||
public boolean isRestrictNull(Object source);
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import javax.swing.plaf.ComponentUI;
|
||||
|
||||
public abstract class CalendarPaneUI extends ComponentUI {
|
||||
|
||||
public abstract void commit() throws PropertyVetoException, ParseException;
|
||||
public abstract void commit() throws PropertyVetoException, ParseException;
|
||||
|
||||
public abstract void revert();
|
||||
public abstract void revert();
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.michaelbaranov.microba.calendar.ui;
|
||||
|
||||
public abstract class DatePickerUI extends CalendarPaneUI {
|
||||
|
||||
public abstract void showPopup(boolean visible);
|
||||
public abstract void showPopup(boolean visible);
|
||||
|
||||
public abstract void setSimpeLook(boolean b);
|
||||
public abstract void setSimpeLook(boolean b);
|
||||
|
||||
}
|
||||
|
||||
@@ -26,211 +26,211 @@ import com.michaelbaranov.microba.common.PolicyListener;
|
||||
|
||||
class AuxPanel extends JPanel implements PropertyChangeListener, PolicyListener {
|
||||
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
|
||||
public static final String PROPERTY_NAME_DATE = "date";
|
||||
public static final String PROPERTY_NAME_DATE = "date";
|
||||
|
||||
public static final String PROPERTY_NAME_ZONE = "zone";
|
||||
public static final String PROPERTY_NAME_ZONE = "zone";
|
||||
|
||||
public static final String PROPERTY_NAME_RESOURCES = "resources";
|
||||
public static final String PROPERTY_NAME_RESOURCES = "resources";
|
||||
|
||||
public static final String PROPERTY_NAME_VETO_MODEL = "vetoModel";
|
||||
public static final String PROPERTY_NAME_VETO_MODEL = "vetoModel";
|
||||
|
||||
private Locale locale;
|
||||
private Locale locale;
|
||||
|
||||
private TimeZone zone;
|
||||
private TimeZone zone;
|
||||
|
||||
private JButton todayButton;
|
||||
private JButton todayButton;
|
||||
|
||||
private JButton noneButton;
|
||||
private JButton noneButton;
|
||||
|
||||
private DateFormat fullDateFormat;
|
||||
private DateFormat fullDateFormat;
|
||||
|
||||
private Date currentDate;
|
||||
private Date currentDate;
|
||||
|
||||
private Set focusableComponents = new HashSet();
|
||||
private Set focusableComponents = new HashSet();
|
||||
|
||||
private VetoPolicy vetoModel;
|
||||
private VetoPolicy vetoModel;
|
||||
|
||||
private boolean showTodayBtn;
|
||||
private boolean showTodayBtn;
|
||||
|
||||
private CalendarResources resources;
|
||||
private CalendarResources resources;
|
||||
|
||||
private boolean showNoneButton;
|
||||
private boolean showNoneButton;
|
||||
|
||||
public AuxPanel(Locale locale, TimeZone zone, VetoPolicy vetoModel,
|
||||
boolean showTodayBtn, boolean showNoneButton,
|
||||
CalendarResources resources) {
|
||||
this.locale = locale;
|
||||
this.zone = zone;
|
||||
this.vetoModel = vetoModel;
|
||||
this.showTodayBtn = showTodayBtn;
|
||||
this.showNoneButton = showNoneButton;
|
||||
this.resources = resources;
|
||||
if (vetoModel != null)
|
||||
vetoModel.addVetoPolicyListener(this);
|
||||
public AuxPanel(Locale locale, TimeZone zone, VetoPolicy vetoModel,
|
||||
boolean showTodayBtn, boolean showNoneButton,
|
||||
CalendarResources resources) {
|
||||
this.locale = locale;
|
||||
this.zone = zone;
|
||||
this.vetoModel = vetoModel;
|
||||
this.showTodayBtn = showTodayBtn;
|
||||
this.showNoneButton = showNoneButton;
|
||||
this.resources = resources;
|
||||
if (vetoModel != null)
|
||||
vetoModel.addVetoPolicyListener(this);
|
||||
|
||||
setLayout(new GridBagLayout());
|
||||
setLayout(new GridBagLayout());
|
||||
|
||||
todayButton = new JButton();
|
||||
todayButton.setBorderPainted(false);
|
||||
todayButton.setContentAreaFilled(false);
|
||||
todayButton.setVisible(showTodayBtn);
|
||||
todayButton = new JButton();
|
||||
todayButton.setBorderPainted(false);
|
||||
todayButton.setContentAreaFilled(false);
|
||||
todayButton.setVisible(showTodayBtn);
|
||||
|
||||
noneButton = new JButton();
|
||||
noneButton.setBorderPainted(false);
|
||||
noneButton.setContentAreaFilled(false);
|
||||
noneButton.setVisible(showNoneButton);
|
||||
noneButton = new JButton();
|
||||
noneButton.setBorderPainted(false);
|
||||
noneButton.setContentAreaFilled(false);
|
||||
noneButton.setVisible(showNoneButton);
|
||||
|
||||
add(todayButton, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,
|
||||
GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
|
||||
0, 0, 0), 0, 0));
|
||||
add(noneButton, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,
|
||||
GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0,
|
||||
0, 0, 0), 0, 0));
|
||||
add(todayButton, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,
|
||||
GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
|
||||
0, 0, 0), 0, 0));
|
||||
add(noneButton, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,
|
||||
GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0,
|
||||
0, 0, 0), 0, 0));
|
||||
|
||||
currentDate = new Date();
|
||||
validateAgainstVeto();
|
||||
createLocaleAndZoneSensitive();
|
||||
reflectData();
|
||||
currentDate = new Date();
|
||||
validateAgainstVeto();
|
||||
createLocaleAndZoneSensitive();
|
||||
reflectData();
|
||||
|
||||
todayButton.addActionListener(new ActionListener() {
|
||||
todayButton.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
currentDate = new Date();
|
||||
firePropertyChange(PROPERTY_NAME_DATE, null, currentDate);
|
||||
}
|
||||
});
|
||||
noneButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
currentDate = new Date();
|
||||
firePropertyChange(PROPERTY_NAME_DATE, null, currentDate);
|
||||
}
|
||||
});
|
||||
noneButton.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
firePropertyChange(PROPERTY_NAME_DATE, null, null);
|
||||
}
|
||||
});
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
firePropertyChange(PROPERTY_NAME_DATE, null, null);
|
||||
}
|
||||
});
|
||||
|
||||
focusableComponents.add(todayButton);
|
||||
this.addPropertyChangeListener(this);
|
||||
focusableComponents.add(todayButton);
|
||||
this.addPropertyChangeListener(this);
|
||||
|
||||
// Timer timer = new Timer(true);
|
||||
// timer.schedule(new TimerTask() {
|
||||
//
|
||||
// public void run() {
|
||||
// currentDate = new Date();
|
||||
// validateAgainstVeto();
|
||||
// }
|
||||
// }, 0, 60000);
|
||||
// Timer timer = new Timer(true);
|
||||
// timer.schedule(new TimerTask() {
|
||||
//
|
||||
// public void run() {
|
||||
// currentDate = new Date();
|
||||
// validateAgainstVeto();
|
||||
// }
|
||||
// }, 0, 60000);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals("focusable")) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
todayButton.setFocusable(value.booleanValue());
|
||||
noneButton.setFocusable(value.booleanValue());
|
||||
}
|
||||
if (evt.getPropertyName().equals("enabled")) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
todayButton.setEnabled(value.booleanValue());
|
||||
noneButton.setEnabled(value.booleanValue());
|
||||
}
|
||||
if (evt.getPropertyName().equals(PROPERTY_NAME_VETO_MODEL)) {
|
||||
VetoPolicy oldValue = (VetoPolicy) evt.getOldValue();
|
||||
VetoPolicy newValue = (VetoPolicy) evt.getOldValue();
|
||||
if (oldValue != null)
|
||||
oldValue.removeVetoPolicyListener(this);
|
||||
if (newValue != null)
|
||||
newValue.addVetoPolicyListener(this);
|
||||
validateAgainstVeto();
|
||||
}
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals("focusable")) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
todayButton.setFocusable(value.booleanValue());
|
||||
noneButton.setFocusable(value.booleanValue());
|
||||
}
|
||||
if (evt.getPropertyName().equals("enabled")) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
todayButton.setEnabled(value.booleanValue());
|
||||
noneButton.setEnabled(value.booleanValue());
|
||||
}
|
||||
if (evt.getPropertyName().equals(PROPERTY_NAME_VETO_MODEL)) {
|
||||
VetoPolicy oldValue = (VetoPolicy) evt.getOldValue();
|
||||
VetoPolicy newValue = (VetoPolicy) evt.getOldValue();
|
||||
if (oldValue != null)
|
||||
oldValue.removeVetoPolicyListener(this);
|
||||
if (newValue != null)
|
||||
newValue.addVetoPolicyListener(this);
|
||||
validateAgainstVeto();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void createLocaleAndZoneSensitive() {
|
||||
fullDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
|
||||
fullDateFormat.setTimeZone(zone);
|
||||
}
|
||||
private void createLocaleAndZoneSensitive() {
|
||||
fullDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
|
||||
fullDateFormat.setTimeZone(zone);
|
||||
}
|
||||
|
||||
private void reflectData() {
|
||||
String today = resources.getResource(CalendarResources.KEY_TODAY,
|
||||
locale);
|
||||
String none = resources.getResource(CalendarResources.KEY_NONE, locale);
|
||||
todayButton.setText(today + ": " + fullDateFormat.format(currentDate));
|
||||
noneButton.setText(none);
|
||||
private void reflectData() {
|
||||
String today = resources.getResource(CalendarResources.KEY_TODAY,
|
||||
locale);
|
||||
String none = resources.getResource(CalendarResources.KEY_NONE, locale);
|
||||
todayButton.setText(today + ": " + fullDateFormat.format(currentDate));
|
||||
noneButton.setText(none);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
Locale old = this.locale;
|
||||
this.locale = locale;
|
||||
firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
createLocaleAndZoneSensitive();
|
||||
reflectData();
|
||||
}
|
||||
public void setLocale(Locale locale) {
|
||||
Locale old = this.locale;
|
||||
this.locale = locale;
|
||||
firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
createLocaleAndZoneSensitive();
|
||||
reflectData();
|
||||
}
|
||||
|
||||
public Collection getFocusableComponents() {
|
||||
return focusableComponents;
|
||||
}
|
||||
public Collection getFocusableComponents() {
|
||||
return focusableComponents;
|
||||
}
|
||||
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public void setZone(TimeZone zone) {
|
||||
this.zone = zone;
|
||||
createLocaleAndZoneSensitive();
|
||||
reflectData();
|
||||
}
|
||||
public void setZone(TimeZone zone) {
|
||||
this.zone = zone;
|
||||
createLocaleAndZoneSensitive();
|
||||
reflectData();
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return currentDate;
|
||||
}
|
||||
public Date getDate() {
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
public VetoPolicy getVetoModel() {
|
||||
return vetoModel;
|
||||
}
|
||||
public VetoPolicy getVetoModel() {
|
||||
return vetoModel;
|
||||
}
|
||||
|
||||
public void setVetoModel(VetoPolicy vetoModel) {
|
||||
VetoPolicy old = this.vetoModel;
|
||||
this.vetoModel = vetoModel;
|
||||
firePropertyChange(PROPERTY_NAME_VETO_MODEL, old, vetoModel);
|
||||
}
|
||||
public void setVetoModel(VetoPolicy vetoModel) {
|
||||
VetoPolicy old = this.vetoModel;
|
||||
this.vetoModel = vetoModel;
|
||||
firePropertyChange(PROPERTY_NAME_VETO_MODEL, old, vetoModel);
|
||||
}
|
||||
|
||||
public void policyChanged(PolicyEvent event) {
|
||||
validateAgainstVeto();
|
||||
}
|
||||
public void policyChanged(PolicyEvent event) {
|
||||
validateAgainstVeto();
|
||||
}
|
||||
|
||||
private void validateAgainstVeto() {
|
||||
Calendar c = Calendar.getInstance(zone, locale);
|
||||
c.setTime(currentDate);
|
||||
if (vetoModel != null) {
|
||||
todayButton.setEnabled(!vetoModel.isRestricted(this, c));
|
||||
noneButton.setEnabled(!vetoModel.isRestrictNull(this));
|
||||
} else {
|
||||
todayButton.setEnabled(this.isEnabled());
|
||||
noneButton.setEnabled(this.isEnabled());
|
||||
}
|
||||
private void validateAgainstVeto() {
|
||||
Calendar c = Calendar.getInstance(zone, locale);
|
||||
c.setTime(currentDate);
|
||||
if (vetoModel != null) {
|
||||
todayButton.setEnabled(!vetoModel.isRestricted(this, c));
|
||||
noneButton.setEnabled(!vetoModel.isRestrictNull(this));
|
||||
} else {
|
||||
todayButton.setEnabled(this.isEnabled());
|
||||
noneButton.setEnabled(this.isEnabled());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void setShowTodayBtn(boolean value) {
|
||||
showTodayBtn = value;
|
||||
todayButton.setVisible(showTodayBtn);
|
||||
}
|
||||
public void setShowTodayBtn(boolean value) {
|
||||
showTodayBtn = value;
|
||||
todayButton.setVisible(showTodayBtn);
|
||||
}
|
||||
|
||||
public void setResources(CalendarResources resources) {
|
||||
CalendarResources old = this.resources;
|
||||
this.resources = resources;
|
||||
firePropertyChange(PROPERTY_NAME_RESOURCES, old, resources);
|
||||
reflectData();
|
||||
}
|
||||
public void setResources(CalendarResources resources) {
|
||||
CalendarResources old = this.resources;
|
||||
this.resources = resources;
|
||||
firePropertyChange(PROPERTY_NAME_RESOURCES, old, resources);
|
||||
reflectData();
|
||||
}
|
||||
|
||||
public void setShowNoneButton(boolean value) {
|
||||
showNoneButton = value;
|
||||
noneButton.setVisible(showNoneButton);
|
||||
}
|
||||
public void setShowNoneButton(boolean value) {
|
||||
showNoneButton = value;
|
||||
noneButton.setVisible(showNoneButton);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,399 +31,399 @@ import com.michaelbaranov.microba.calendar.VetoPolicy;
|
||||
import com.michaelbaranov.microba.calendar.ui.CalendarPaneUI;
|
||||
|
||||
public class BasicCalendarPaneUI extends CalendarPaneUI implements
|
||||
PropertyChangeListener, FocusListener {
|
||||
PropertyChangeListener, FocusListener {
|
||||
|
||||
protected static final String ESCAPE_KEY = "##CalendarPaneUI.escape##";
|
||||
protected static final String ESCAPE_KEY = "##CalendarPaneUI.escape##";
|
||||
|
||||
protected static final String ENTER_KEY = "##CalendarPaneUI.enter##";
|
||||
protected static final String ENTER_KEY = "##CalendarPaneUI.enter##";
|
||||
|
||||
protected CalendarPane peer;
|
||||
protected CalendarPane peer;
|
||||
|
||||
protected ClassicCalendarPanel classicPanel;
|
||||
protected ClassicCalendarPanel classicPanel;
|
||||
|
||||
protected ModernCalendarPanel modernPanel;
|
||||
protected ModernCalendarPanel modernPanel;
|
||||
|
||||
protected AuxPanel auxPanel;
|
||||
protected AuxPanel auxPanel;
|
||||
|
||||
protected CalendarGridPanel gridPanel;
|
||||
protected CalendarGridPanel gridPanel;
|
||||
|
||||
protected CalendarNumberOfWeekPanel numberOfWeekPanel;
|
||||
protected CalendarNumberOfWeekPanel numberOfWeekPanel;
|
||||
|
||||
protected CalendarHeader headerPanel;
|
||||
protected CalendarHeader headerPanel;
|
||||
|
||||
protected Set focusableComponents = new HashSet();
|
||||
protected Set focusableComponents = new HashSet();
|
||||
|
||||
protected ComponentListener componentListener;
|
||||
protected ComponentListener componentListener;
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new BasicCalendarPaneUI();
|
||||
}
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new BasicCalendarPaneUI();
|
||||
}
|
||||
|
||||
public void installUI(JComponent component) {
|
||||
peer = (CalendarPane) component;
|
||||
createNestedComponents();
|
||||
addNestedComponents();
|
||||
installListeners();
|
||||
installKeyboardActions();
|
||||
}
|
||||
public void installUI(JComponent component) {
|
||||
peer = (CalendarPane) component;
|
||||
createNestedComponents();
|
||||
addNestedComponents();
|
||||
installListeners();
|
||||
installKeyboardActions();
|
||||
}
|
||||
|
||||
public void uninstallUI(JComponent component) {
|
||||
uninstallKeyboardActions();
|
||||
uninstallListeners();
|
||||
removeNestedComponents();
|
||||
destroyNestedComponents();
|
||||
peer = null;
|
||||
}
|
||||
|
||||
protected void uninstallKeyboardActions() {
|
||||
InputMap input = peer
|
||||
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
ActionMap action = peer.getActionMap();
|
||||
|
||||
input.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
|
||||
input.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
|
||||
|
||||
action.remove(ENTER_KEY);
|
||||
action.remove(ESCAPE_KEY);
|
||||
|
||||
}
|
||||
|
||||
protected void installKeyboardActions() {
|
||||
InputMap input = peer
|
||||
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
ActionMap action = peer.getActionMap();
|
||||
|
||||
input.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), ENTER_KEY);
|
||||
input.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ESCAPE_KEY);
|
||||
input.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "pgupkey");
|
||||
input
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0),
|
||||
"pgdownkey");
|
||||
|
||||
action.put(ENTER_KEY, new AbstractAction() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
peer.commitEdit();
|
||||
}
|
||||
});
|
||||
action.put(ESCAPE_KEY, new AbstractAction() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
peer.revertEdit();
|
||||
}
|
||||
});
|
||||
action.put("pgupkey", new AbstractAction() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
classicPanel.addMonth(1);
|
||||
}
|
||||
});
|
||||
action.put("pgdownkey", new AbstractAction() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
classicPanel.addMonth(-1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void uninstallListeners() {
|
||||
peer.removePropertyChangeListener(this);
|
||||
peer.removeFocusListener(this);
|
||||
}
|
||||
|
||||
protected void installListeners() {
|
||||
peer.addPropertyChangeListener(this);
|
||||
peer.addFocusListener(this);
|
||||
}
|
||||
|
||||
protected void createNestedComponents() {
|
||||
Date baseDate = peer.getDate() == null ? new Date() : peer.getDate();
|
||||
|
||||
classicPanel = new ClassicCalendarPanel(baseDate, peer.getLocale(),
|
||||
peer.getZone());
|
||||
modernPanel = new ModernCalendarPanel(baseDate, peer.getLocale(), peer
|
||||
.getZone());
|
||||
headerPanel = new CalendarHeader(peer, baseDate, peer.getLocale(), peer
|
||||
.getZone(), peer.getHolidayPolicy());
|
||||
|
||||
auxPanel = new AuxPanel(peer.getLocale(), peer.getZone(), peer
|
||||
.getVetoPolicy(), peer.isShowTodayButton(), peer
|
||||
.isShowNoneButton(), peer.getResources());
|
||||
|
||||
gridPanel = new CalendarGridPanel(peer, peer.getDate(), peer
|
||||
.getLocale(), peer.getZone(), peer.getVetoPolicy(), peer
|
||||
.getHolidayPolicy());
|
||||
|
||||
numberOfWeekPanel = new CalendarNumberOfWeekPanel(peer.getDate(), peer
|
||||
.getLocale(), peer.getZone());
|
||||
|
||||
focusableComponents.addAll(classicPanel.getFocusableComponents());
|
||||
focusableComponents.addAll(modernPanel.getFocusableComponents());
|
||||
focusableComponents.addAll(auxPanel.getFocusableComponents());
|
||||
focusableComponents.addAll(gridPanel.getFocusableComponents());
|
||||
focusableComponents.addAll(auxPanel.getFocusableComponents());
|
||||
|
||||
componentListener = new ComponentListener();
|
||||
for (int i = 0; i < focusableComponents.size(); i++)
|
||||
((JComponent) focusableComponents.toArray()[i])
|
||||
.addFocusListener(componentListener);
|
||||
|
||||
gridPanel.addPropertyChangeListener(componentListener);
|
||||
modernPanel.addPropertyChangeListener(componentListener);
|
||||
classicPanel.addPropertyChangeListener(componentListener);
|
||||
auxPanel.addPropertyChangeListener(componentListener);
|
||||
|
||||
classicPanel.setEnabled(peer.isEnabled());
|
||||
modernPanel.setEnabled(peer.isEnabled());
|
||||
headerPanel.setEnabled(peer.isEnabled());
|
||||
auxPanel.setEnabled(peer.isEnabled());
|
||||
numberOfWeekPanel.setEnabled(peer.isEnabled());
|
||||
gridPanel.setEnabled(peer.isEnabled());
|
||||
|
||||
}
|
||||
|
||||
protected void destroyNestedComponents() {
|
||||
gridPanel.removePropertyChangeListener(componentListener);
|
||||
modernPanel.removePropertyChangeListener(componentListener);
|
||||
classicPanel.removePropertyChangeListener(componentListener);
|
||||
auxPanel.removePropertyChangeListener(componentListener);
|
||||
componentListener = null;
|
||||
|
||||
for (int i = 0; i < focusableComponents.size(); i++)
|
||||
((JComponent) focusableComponents.toArray()[i])
|
||||
.removeFocusListener(componentListener);
|
||||
focusableComponents.clear();
|
||||
|
||||
classicPanel = null;
|
||||
modernPanel = null;
|
||||
headerPanel = null;
|
||||
auxPanel = null;
|
||||
gridPanel = null;
|
||||
numberOfWeekPanel = null;
|
||||
|
||||
}
|
||||
|
||||
protected void addNestedComponents() {
|
||||
|
||||
peer.removeAll();
|
||||
peer.setLayout(new GridBagLayout());
|
||||
if ((peer.getStyle() & CalendarPane.STYLE_CLASSIC) > 0) {
|
||||
peer.add(classicPanel, new GridBagConstraints(0, 0, 2, 1, 1, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
} else {
|
||||
peer.add(modernPanel, new GridBagConstraints(0, 0, 2, 1, 1, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
}
|
||||
peer.add(headerPanel, new GridBagConstraints(1, 1, 1, 1, 1, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
if (peer.isShowNumberOfWeek()) {
|
||||
peer.add(numberOfWeekPanel, new GridBagConstraints(0, 2, 1, 1, 0,
|
||||
1, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
}
|
||||
peer.add(gridPanel, new GridBagConstraints(1, 2, 1, 1, 1, 1,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
|
||||
0, 0, 0, 0), 0, 0));
|
||||
if (peer.isShowTodayButton()) {
|
||||
peer.add(auxPanel, new GridBagConstraints(0, 3, 2, 1, 1, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
}
|
||||
if (peer.isShowNumberOfWeek()) {
|
||||
// TODO:
|
||||
}
|
||||
peer.revalidate();
|
||||
peer.repaint();
|
||||
|
||||
}
|
||||
|
||||
protected void removeNestedComponents() {
|
||||
peer.removeAll();
|
||||
}
|
||||
|
||||
protected void widgetDateChanged(Date date) {
|
||||
Date baseDate = date == null ? new Date() : date;
|
||||
|
||||
headerPanel.setDate(baseDate);
|
||||
classicPanel.setDate(baseDate);
|
||||
modernPanel.setDate(baseDate);
|
||||
|
||||
gridPanel.setBaseDate(baseDate);
|
||||
gridPanel.setDate(date);
|
||||
numberOfWeekPanel.setBaseDate(baseDate);
|
||||
}
|
||||
|
||||
protected void widgetLocaleChanged(Locale newValue) {
|
||||
classicPanel.setLocale(newValue);
|
||||
modernPanel.setLocale(newValue);
|
||||
gridPanel.setLocale(newValue);
|
||||
headerPanel.setLocale(newValue);
|
||||
auxPanel.setLocale(newValue);
|
||||
numberOfWeekPanel.setLocale(newValue);
|
||||
}
|
||||
|
||||
protected void widgetZoneChanged(TimeZone zone) {
|
||||
classicPanel.setZone(zone);
|
||||
modernPanel.setZone(zone);
|
||||
gridPanel.setZone(zone);
|
||||
headerPanel.setZone(zone);
|
||||
auxPanel.setZone(zone);
|
||||
numberOfWeekPanel.setZone(zone);
|
||||
}
|
||||
|
||||
protected void widgetResourceChanged() {
|
||||
auxPanel.setResources(peer.getResources());
|
||||
}
|
||||
|
||||
public void commit() throws PropertyVetoException {
|
||||
peer.setDate(gridPanel.getDateToCommit());
|
||||
}
|
||||
|
||||
public void revert() {
|
||||
widgetDateChanged(peer.getDate());
|
||||
}
|
||||
|
||||
public void focusGained(FocusEvent e) {
|
||||
gridPanel.requestFocus(true);
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals(CalendarPane.PROPERTY_NAME_DATE)) {
|
||||
widgetDateChanged((Date) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_LOCALE)) {
|
||||
widgetLocaleChanged((Locale) evt.getNewValue());
|
||||
} else if (evt.getPropertyName()
|
||||
.equals(CalendarPane.PROPERTY_NAME_ZONE)) {
|
||||
widgetZoneChanged((TimeZone) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_VETO_POLICY)) {
|
||||
gridPanel.setVetoPolicy((VetoPolicy) evt.getNewValue());
|
||||
auxPanel.setVetoModel((VetoPolicy) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_HOLIDAY_POLICY)) {
|
||||
gridPanel.setHolidayPolicy((HolidayPolicy) evt.getNewValue());
|
||||
headerPanel.setHolidayPolicy((HolidayPolicy) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals("enabled")) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
classicPanel.setEnabled(value);
|
||||
modernPanel.setEnabled(value);
|
||||
headerPanel.setEnabled(value);
|
||||
auxPanel.setEnabled(value);
|
||||
numberOfWeekPanel.setEnabled(value);
|
||||
gridPanel.setEnabled(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_STYLE)) {
|
||||
addNestedComponents();
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_SHOW_TODAY_BTN)) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
auxPanel.setShowTodayBtn(value.booleanValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_SHOW_NONE_BTN)) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
auxPanel.setShowNoneButton(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_SHOW_NUMBER_WEEK)) {
|
||||
addNestedComponents();
|
||||
} else if (evt.getPropertyName().equals("focusable")) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
classicPanel.setFocusable(value.booleanValue());
|
||||
modernPanel.setFocusable(value.booleanValue());
|
||||
gridPanel.setFocusable(value.booleanValue());
|
||||
auxPanel.setFocusable(value.booleanValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_RESOURCES)) {
|
||||
widgetResourceChanged();
|
||||
} else if (evt.getPropertyName()
|
||||
.equals("enabled"/* CalendarPane.PROPERTY_NAME_ENABLED */)) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
classicPanel.setEnabled(value.booleanValue());
|
||||
modernPanel.setEnabled(value.booleanValue());
|
||||
gridPanel.setEnabled(value.booleanValue());
|
||||
auxPanel.setEnabled(value.booleanValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected class ComponentListener implements FocusListener,
|
||||
PropertyChangeListener {
|
||||
public void focusGained(FocusEvent e) {
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
boolean isFocusableComponent = focusableComponents.contains(e
|
||||
.getSource());
|
||||
boolean isNonEmptyOpposite = e.getOppositeComponent() != null;
|
||||
if (isFocusableComponent
|
||||
&& isNonEmptyOpposite
|
||||
&& !SwingUtilities.isDescendingFrom(e
|
||||
.getOppositeComponent(), peer)) {
|
||||
peer.commitOrRevert();
|
||||
}
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getSource() == gridPanel
|
||||
&& evt.getPropertyName().equals(
|
||||
CalendarGridPanel.PROPERTY_NAME_DATE)) {
|
||||
Date newValue = (Date) evt.getNewValue();
|
||||
try {
|
||||
peer.setDate(newValue);
|
||||
} catch (PropertyVetoException e) {
|
||||
// Ignore. Just can not happen, beacause CalendarGridPanel
|
||||
// already checked the date against current peer's
|
||||
// vetoPolicy.
|
||||
}
|
||||
}
|
||||
if (evt.getSource() == gridPanel
|
||||
&& evt.getPropertyName().equals(
|
||||
CalendarGridPanel.PROPERTY_NAME_NOTIFY_SELECTED_DATE_CLICKED)) {
|
||||
peer.fireActionEvent();
|
||||
}
|
||||
if (evt.getSource() == gridPanel
|
||||
&& evt.getPropertyName().equals(
|
||||
CalendarGridPanel.PROPERTY_NAME_BASE_DATE)) {
|
||||
Date newValue = (Date) evt.getNewValue();
|
||||
modernPanel.setDate(newValue);
|
||||
classicPanel.setDate(newValue);
|
||||
}
|
||||
if (evt.getSource() == modernPanel
|
||||
&& evt.getPropertyName().equals(
|
||||
ModernCalendarPanel.PROPERTY_NAME_DATE)) {
|
||||
Date newValue = (Date) evt.getNewValue();
|
||||
|
||||
gridPanel.setBaseDate(newValue);
|
||||
classicPanel.setDate(newValue);
|
||||
numberOfWeekPanel.setBaseDate(newValue);
|
||||
|
||||
}
|
||||
if (evt.getSource() == classicPanel
|
||||
&& evt.getPropertyName().equals(
|
||||
ModernCalendarPanel.PROPERTY_NAME_DATE)) {
|
||||
Date newValue = (Date) evt.getNewValue();
|
||||
|
||||
gridPanel.setBaseDate(newValue);
|
||||
modernPanel.setDate(newValue);
|
||||
numberOfWeekPanel.setBaseDate(newValue);
|
||||
|
||||
}
|
||||
if (evt.getSource() == auxPanel
|
||||
&& evt.getPropertyName()
|
||||
.equals(AuxPanel.PROPERTY_NAME_DATE)) {
|
||||
Date date = (Date) evt.getNewValue();
|
||||
|
||||
gridPanel.setDate(date);
|
||||
peer.commitEdit();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public void uninstallUI(JComponent component) {
|
||||
uninstallKeyboardActions();
|
||||
uninstallListeners();
|
||||
removeNestedComponents();
|
||||
destroyNestedComponents();
|
||||
peer = null;
|
||||
}
|
||||
|
||||
protected void uninstallKeyboardActions() {
|
||||
InputMap input = peer
|
||||
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
ActionMap action = peer.getActionMap();
|
||||
|
||||
input.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
|
||||
input.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
|
||||
|
||||
action.remove(ENTER_KEY);
|
||||
action.remove(ESCAPE_KEY);
|
||||
|
||||
}
|
||||
|
||||
protected void installKeyboardActions() {
|
||||
InputMap input = peer
|
||||
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
ActionMap action = peer.getActionMap();
|
||||
|
||||
input.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), ENTER_KEY);
|
||||
input.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ESCAPE_KEY);
|
||||
input.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "pgupkey");
|
||||
input
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0),
|
||||
"pgdownkey");
|
||||
|
||||
action.put(ENTER_KEY, new AbstractAction() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
peer.commitEdit();
|
||||
}
|
||||
});
|
||||
action.put(ESCAPE_KEY, new AbstractAction() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
peer.revertEdit();
|
||||
}
|
||||
});
|
||||
action.put("pgupkey", new AbstractAction() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
classicPanel.addMonth(1);
|
||||
}
|
||||
});
|
||||
action.put("pgdownkey", new AbstractAction() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
classicPanel.addMonth(-1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void uninstallListeners() {
|
||||
peer.removePropertyChangeListener(this);
|
||||
peer.removeFocusListener(this);
|
||||
}
|
||||
|
||||
protected void installListeners() {
|
||||
peer.addPropertyChangeListener(this);
|
||||
peer.addFocusListener(this);
|
||||
}
|
||||
|
||||
protected void createNestedComponents() {
|
||||
Date baseDate = peer.getDate() == null ? new Date() : peer.getDate();
|
||||
|
||||
classicPanel = new ClassicCalendarPanel(baseDate, peer.getLocale(),
|
||||
peer.getZone());
|
||||
modernPanel = new ModernCalendarPanel(baseDate, peer.getLocale(), peer
|
||||
.getZone());
|
||||
headerPanel = new CalendarHeader(peer, baseDate, peer.getLocale(), peer
|
||||
.getZone(), peer.getHolidayPolicy());
|
||||
|
||||
auxPanel = new AuxPanel(peer.getLocale(), peer.getZone(), peer
|
||||
.getVetoPolicy(), peer.isShowTodayButton(), peer
|
||||
.isShowNoneButton(), peer.getResources());
|
||||
|
||||
gridPanel = new CalendarGridPanel(peer, peer.getDate(), peer
|
||||
.getLocale(), peer.getZone(), peer.getVetoPolicy(), peer
|
||||
.getHolidayPolicy());
|
||||
|
||||
numberOfWeekPanel = new CalendarNumberOfWeekPanel(peer.getDate(), peer
|
||||
.getLocale(), peer.getZone());
|
||||
|
||||
focusableComponents.addAll(classicPanel.getFocusableComponents());
|
||||
focusableComponents.addAll(modernPanel.getFocusableComponents());
|
||||
focusableComponents.addAll(auxPanel.getFocusableComponents());
|
||||
focusableComponents.addAll(gridPanel.getFocusableComponents());
|
||||
focusableComponents.addAll(auxPanel.getFocusableComponents());
|
||||
|
||||
componentListener = new ComponentListener();
|
||||
for (int i = 0; i < focusableComponents.size(); i++)
|
||||
((JComponent) focusableComponents.toArray()[i])
|
||||
.addFocusListener(componentListener);
|
||||
|
||||
gridPanel.addPropertyChangeListener(componentListener);
|
||||
modernPanel.addPropertyChangeListener(componentListener);
|
||||
classicPanel.addPropertyChangeListener(componentListener);
|
||||
auxPanel.addPropertyChangeListener(componentListener);
|
||||
|
||||
classicPanel.setEnabled(peer.isEnabled());
|
||||
modernPanel.setEnabled(peer.isEnabled());
|
||||
headerPanel.setEnabled(peer.isEnabled());
|
||||
auxPanel.setEnabled(peer.isEnabled());
|
||||
numberOfWeekPanel.setEnabled(peer.isEnabled());
|
||||
gridPanel.setEnabled(peer.isEnabled());
|
||||
|
||||
}
|
||||
|
||||
protected void destroyNestedComponents() {
|
||||
gridPanel.removePropertyChangeListener(componentListener);
|
||||
modernPanel.removePropertyChangeListener(componentListener);
|
||||
classicPanel.removePropertyChangeListener(componentListener);
|
||||
auxPanel.removePropertyChangeListener(componentListener);
|
||||
componentListener = null;
|
||||
|
||||
for (int i = 0; i < focusableComponents.size(); i++)
|
||||
((JComponent) focusableComponents.toArray()[i])
|
||||
.removeFocusListener(componentListener);
|
||||
focusableComponents.clear();
|
||||
|
||||
classicPanel = null;
|
||||
modernPanel = null;
|
||||
headerPanel = null;
|
||||
auxPanel = null;
|
||||
gridPanel = null;
|
||||
numberOfWeekPanel = null;
|
||||
|
||||
}
|
||||
|
||||
protected void addNestedComponents() {
|
||||
|
||||
peer.removeAll();
|
||||
peer.setLayout(new GridBagLayout());
|
||||
if ((peer.getStyle() & CalendarPane.STYLE_CLASSIC) > 0) {
|
||||
peer.add(classicPanel, new GridBagConstraints(0, 0, 2, 1, 1, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
} else {
|
||||
peer.add(modernPanel, new GridBagConstraints(0, 0, 2, 1, 1, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
}
|
||||
peer.add(headerPanel, new GridBagConstraints(1, 1, 1, 1, 1, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
if (peer.isShowNumberOfWeek()) {
|
||||
peer.add(numberOfWeekPanel, new GridBagConstraints(0, 2, 1, 1, 0,
|
||||
1, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
}
|
||||
peer.add(gridPanel, new GridBagConstraints(1, 2, 1, 1, 1, 1,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
|
||||
0, 0, 0, 0), 0, 0));
|
||||
if (peer.isShowTodayButton()) {
|
||||
peer.add(auxPanel, new GridBagConstraints(0, 3, 2, 1, 1, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 0, 0, 0), 0, 0));
|
||||
}
|
||||
if (peer.isShowNumberOfWeek()) {
|
||||
// TODO:
|
||||
}
|
||||
peer.revalidate();
|
||||
peer.repaint();
|
||||
|
||||
}
|
||||
|
||||
protected void removeNestedComponents() {
|
||||
peer.removeAll();
|
||||
}
|
||||
|
||||
protected void widgetDateChanged(Date date) {
|
||||
Date baseDate = date == null ? new Date() : date;
|
||||
|
||||
headerPanel.setDate(baseDate);
|
||||
classicPanel.setDate(baseDate);
|
||||
modernPanel.setDate(baseDate);
|
||||
|
||||
gridPanel.setBaseDate(baseDate);
|
||||
gridPanel.setDate(date);
|
||||
numberOfWeekPanel.setBaseDate(baseDate);
|
||||
}
|
||||
|
||||
protected void widgetLocaleChanged(Locale newValue) {
|
||||
classicPanel.setLocale(newValue);
|
||||
modernPanel.setLocale(newValue);
|
||||
gridPanel.setLocale(newValue);
|
||||
headerPanel.setLocale(newValue);
|
||||
auxPanel.setLocale(newValue);
|
||||
numberOfWeekPanel.setLocale(newValue);
|
||||
}
|
||||
|
||||
protected void widgetZoneChanged(TimeZone zone) {
|
||||
classicPanel.setZone(zone);
|
||||
modernPanel.setZone(zone);
|
||||
gridPanel.setZone(zone);
|
||||
headerPanel.setZone(zone);
|
||||
auxPanel.setZone(zone);
|
||||
numberOfWeekPanel.setZone(zone);
|
||||
}
|
||||
|
||||
protected void widgetResourceChanged() {
|
||||
auxPanel.setResources(peer.getResources());
|
||||
}
|
||||
|
||||
public void commit() throws PropertyVetoException {
|
||||
peer.setDate(gridPanel.getDateToCommit());
|
||||
}
|
||||
|
||||
public void revert() {
|
||||
widgetDateChanged(peer.getDate());
|
||||
}
|
||||
|
||||
public void focusGained(FocusEvent e) {
|
||||
gridPanel.requestFocus(true);
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals(CalendarPane.PROPERTY_NAME_DATE)) {
|
||||
widgetDateChanged((Date) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_LOCALE)) {
|
||||
widgetLocaleChanged((Locale) evt.getNewValue());
|
||||
} else if (evt.getPropertyName()
|
||||
.equals(CalendarPane.PROPERTY_NAME_ZONE)) {
|
||||
widgetZoneChanged((TimeZone) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_VETO_POLICY)) {
|
||||
gridPanel.setVetoPolicy((VetoPolicy) evt.getNewValue());
|
||||
auxPanel.setVetoModel((VetoPolicy) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_HOLIDAY_POLICY)) {
|
||||
gridPanel.setHolidayPolicy((HolidayPolicy) evt.getNewValue());
|
||||
headerPanel.setHolidayPolicy((HolidayPolicy) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals("enabled")) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
classicPanel.setEnabled(value);
|
||||
modernPanel.setEnabled(value);
|
||||
headerPanel.setEnabled(value);
|
||||
auxPanel.setEnabled(value);
|
||||
numberOfWeekPanel.setEnabled(value);
|
||||
gridPanel.setEnabled(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_STYLE)) {
|
||||
addNestedComponents();
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_SHOW_TODAY_BTN)) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
auxPanel.setShowTodayBtn(value.booleanValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_SHOW_NONE_BTN)) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
auxPanel.setShowNoneButton(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_SHOW_NUMBER_WEEK)) {
|
||||
addNestedComponents();
|
||||
} else if (evt.getPropertyName().equals("focusable")) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
classicPanel.setFocusable(value.booleanValue());
|
||||
modernPanel.setFocusable(value.booleanValue());
|
||||
gridPanel.setFocusable(value.booleanValue());
|
||||
auxPanel.setFocusable(value.booleanValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
CalendarPane.PROPERTY_NAME_RESOURCES)) {
|
||||
widgetResourceChanged();
|
||||
} else if (evt.getPropertyName()
|
||||
.equals("enabled"/* CalendarPane.PROPERTY_NAME_ENABLED */)) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
classicPanel.setEnabled(value.booleanValue());
|
||||
modernPanel.setEnabled(value.booleanValue());
|
||||
gridPanel.setEnabled(value.booleanValue());
|
||||
auxPanel.setEnabled(value.booleanValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected class ComponentListener implements FocusListener,
|
||||
PropertyChangeListener {
|
||||
public void focusGained(FocusEvent e) {
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
boolean isFocusableComponent = focusableComponents.contains(e
|
||||
.getSource());
|
||||
boolean isNonEmptyOpposite = e.getOppositeComponent() != null;
|
||||
if (isFocusableComponent
|
||||
&& isNonEmptyOpposite
|
||||
&& !SwingUtilities.isDescendingFrom(e
|
||||
.getOppositeComponent(), peer)) {
|
||||
peer.commitOrRevert();
|
||||
}
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getSource() == gridPanel
|
||||
&& evt.getPropertyName().equals(
|
||||
CalendarGridPanel.PROPERTY_NAME_DATE)) {
|
||||
Date newValue = (Date) evt.getNewValue();
|
||||
try {
|
||||
peer.setDate(newValue);
|
||||
} catch (PropertyVetoException e) {
|
||||
// Ignore. Just can not happen, beacause CalendarGridPanel
|
||||
// already checked the date against current peer's
|
||||
// vetoPolicy.
|
||||
}
|
||||
}
|
||||
if (evt.getSource() == gridPanel
|
||||
&& evt.getPropertyName().equals(
|
||||
CalendarGridPanel.PROPERTY_NAME_NOTIFY_SELECTED_DATE_CLICKED)) {
|
||||
peer.fireActionEvent();
|
||||
}
|
||||
if (evt.getSource() == gridPanel
|
||||
&& evt.getPropertyName().equals(
|
||||
CalendarGridPanel.PROPERTY_NAME_BASE_DATE)) {
|
||||
Date newValue = (Date) evt.getNewValue();
|
||||
modernPanel.setDate(newValue);
|
||||
classicPanel.setDate(newValue);
|
||||
}
|
||||
if (evt.getSource() == modernPanel
|
||||
&& evt.getPropertyName().equals(
|
||||
ModernCalendarPanel.PROPERTY_NAME_DATE)) {
|
||||
Date newValue = (Date) evt.getNewValue();
|
||||
|
||||
gridPanel.setBaseDate(newValue);
|
||||
classicPanel.setDate(newValue);
|
||||
numberOfWeekPanel.setBaseDate(newValue);
|
||||
|
||||
}
|
||||
if (evt.getSource() == classicPanel
|
||||
&& evt.getPropertyName().equals(
|
||||
ModernCalendarPanel.PROPERTY_NAME_DATE)) {
|
||||
Date newValue = (Date) evt.getNewValue();
|
||||
|
||||
gridPanel.setBaseDate(newValue);
|
||||
modernPanel.setDate(newValue);
|
||||
numberOfWeekPanel.setBaseDate(newValue);
|
||||
|
||||
}
|
||||
if (evt.getSource() == auxPanel
|
||||
&& evt.getPropertyName()
|
||||
.equals(AuxPanel.PROPERTY_NAME_DATE)) {
|
||||
Date date = (Date) evt.getNewValue();
|
||||
|
||||
gridPanel.setDate(date);
|
||||
peer.commitEdit();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,364 +40,364 @@ import com.michaelbaranov.microba.common.CommitEvent;
|
||||
import com.michaelbaranov.microba.common.CommitListener;
|
||||
|
||||
public class BasicDatePickerUI extends DatePickerUI implements
|
||||
PropertyChangeListener {
|
||||
PropertyChangeListener {
|
||||
|
||||
protected static final String POPUP_KEY = "##BasicVetoDatePickerUI.popup##";
|
||||
protected static final String POPUP_KEY = "##BasicVetoDatePickerUI.popup##";
|
||||
|
||||
protected DatePicker peer;
|
||||
protected DatePicker peer;
|
||||
|
||||
protected CalendarPane calendarPane;
|
||||
protected CalendarPane calendarPane;
|
||||
|
||||
protected JButton button;
|
||||
protected JButton button;
|
||||
|
||||
protected JPopupMenu popup;
|
||||
protected JPopupMenu popup;
|
||||
|
||||
protected JFormattedTextField field;
|
||||
protected JFormattedTextField field;
|
||||
|
||||
protected ComponentListener componentListener;
|
||||
protected ComponentListener componentListener;
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new BasicDatePickerUI();
|
||||
}
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new BasicDatePickerUI();
|
||||
}
|
||||
|
||||
public void installUI(JComponent c) {
|
||||
peer = (DatePicker) c;
|
||||
installComponents();
|
||||
istallListeners();
|
||||
installKeyboardActions();
|
||||
}
|
||||
public void installUI(JComponent c) {
|
||||
peer = (DatePicker) c;
|
||||
installComponents();
|
||||
istallListeners();
|
||||
installKeyboardActions();
|
||||
}
|
||||
|
||||
public void uninstallUI(JComponent c) {
|
||||
uninstallKeyboardActions();
|
||||
uninstallListeners();
|
||||
uninstallComponents();
|
||||
peer = null;
|
||||
}
|
||||
public void uninstallUI(JComponent c) {
|
||||
uninstallKeyboardActions();
|
||||
uninstallListeners();
|
||||
uninstallComponents();
|
||||
peer = null;
|
||||
}
|
||||
|
||||
protected void installKeyboardActions() {
|
||||
InputMap input = peer
|
||||
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
input.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK),
|
||||
POPUP_KEY);
|
||||
input.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), POPUP_KEY);
|
||||
protected void installKeyboardActions() {
|
||||
InputMap input = peer
|
||||
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
input.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK),
|
||||
POPUP_KEY);
|
||||
input.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), POPUP_KEY);
|
||||
|
||||
peer.getActionMap().put(POPUP_KEY, new AbstractAction() {
|
||||
peer.getActionMap().put(POPUP_KEY, new AbstractAction() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
showPopup(true);
|
||||
}
|
||||
});
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
showPopup(true);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void uninstallKeyboardActions() {
|
||||
InputMap input = peer
|
||||
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
input
|
||||
.remove(KeyStroke.getKeyStroke(KeyEvent.VK_C,
|
||||
InputEvent.ALT_MASK));
|
||||
input.remove(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0));
|
||||
protected void uninstallKeyboardActions() {
|
||||
InputMap input = peer
|
||||
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
input
|
||||
.remove(KeyStroke.getKeyStroke(KeyEvent.VK_C,
|
||||
InputEvent.ALT_MASK));
|
||||
input.remove(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0));
|
||||
|
||||
peer.getActionMap().remove(POPUP_KEY);
|
||||
}
|
||||
peer.getActionMap().remove(POPUP_KEY);
|
||||
}
|
||||
|
||||
protected void istallListeners() {
|
||||
peer.addPropertyChangeListener(this);
|
||||
}
|
||||
protected void istallListeners() {
|
||||
peer.addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
protected void uninstallListeners() {
|
||||
peer.removePropertyChangeListener(this);
|
||||
}
|
||||
protected void uninstallListeners() {
|
||||
peer.removePropertyChangeListener(this);
|
||||
}
|
||||
|
||||
protected void uninstallComponents() {
|
||||
button.removeActionListener(componentListener);
|
||||
field.removePropertyChangeListener(componentListener);
|
||||
protected void uninstallComponents() {
|
||||
button.removeActionListener(componentListener);
|
||||
field.removePropertyChangeListener(componentListener);
|
||||
|
||||
calendarPane.removePropertyChangeListener(componentListener);
|
||||
calendarPane.removeCommitListener(componentListener);
|
||||
calendarPane.removeActionListener(componentListener);
|
||||
calendarPane.removePropertyChangeListener(componentListener);
|
||||
calendarPane.removeCommitListener(componentListener);
|
||||
calendarPane.removeActionListener(componentListener);
|
||||
|
||||
peer.remove(field);
|
||||
peer.remove(button);
|
||||
popup = null;
|
||||
calendarPane = null;
|
||||
button = null;
|
||||
field = null;
|
||||
peer.remove(field);
|
||||
peer.remove(button);
|
||||
popup = null;
|
||||
calendarPane = null;
|
||||
button = null;
|
||||
field = null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void installComponents() {
|
||||
field = new JFormattedTextField(createFormatterFactory());
|
||||
field.setValue(peer.getDate());
|
||||
field.setFocusLostBehavior(peer.getFocusLostBehavior());
|
||||
field.setEditable(peer.isFieldEditable());
|
||||
field.setToolTipText(peer.getToolTipText());
|
||||
// button
|
||||
button = new JButton();
|
||||
button.setFocusable(false);
|
||||
button.setMargin(new Insets(0, 0, 0, 0));
|
||||
button.setToolTipText(peer.getToolTipText());
|
||||
protected void installComponents() {
|
||||
field = new JFormattedTextField(createFormatterFactory());
|
||||
field.setValue(peer.getDate());
|
||||
field.setFocusLostBehavior(peer.getFocusLostBehavior());
|
||||
field.setEditable(peer.isFieldEditable());
|
||||
field.setToolTipText(peer.getToolTipText());
|
||||
// button
|
||||
button = new JButton();
|
||||
button.setFocusable(false);
|
||||
button.setMargin(new Insets(0, 0, 0, 0));
|
||||
button.setToolTipText(peer.getToolTipText());
|
||||
|
||||
setSimpeLook(false);
|
||||
// calendar
|
||||
calendarPane = new CalendarPane(peer.getStyle());
|
||||
calendarPane.setShowTodayButton(peer.isShowTodayButton());
|
||||
calendarPane.setFocusLostBehavior(JFormattedTextField.REVERT);
|
||||
calendarPane.setFocusCycleRoot(true);
|
||||
calendarPane.setBorder(BorderFactory.createEmptyBorder(1, 3, 0, 3));
|
||||
calendarPane.setStripTime(false);
|
||||
calendarPane.setLocale(peer.getLocale());
|
||||
calendarPane.setZone(peer.getZone());
|
||||
calendarPane.setFocusable(peer.isDropdownFocusable());
|
||||
calendarPane.setColorOverrideMap(peer.getColorOverrideMap());
|
||||
// popup
|
||||
popup = new JPopupMenu();
|
||||
popup.setLayout(new BorderLayout());
|
||||
popup.add(calendarPane, BorderLayout.CENTER);
|
||||
popup.setLightWeightPopupEnabled(true);
|
||||
// add
|
||||
peer.setLayout(new BorderLayout());
|
||||
setSimpeLook(false);
|
||||
// calendar
|
||||
calendarPane = new CalendarPane(peer.getStyle());
|
||||
calendarPane.setShowTodayButton(peer.isShowTodayButton());
|
||||
calendarPane.setFocusLostBehavior(JFormattedTextField.REVERT);
|
||||
calendarPane.setFocusCycleRoot(true);
|
||||
calendarPane.setBorder(BorderFactory.createEmptyBorder(1, 3, 0, 3));
|
||||
calendarPane.setStripTime(false);
|
||||
calendarPane.setLocale(peer.getLocale());
|
||||
calendarPane.setZone(peer.getZone());
|
||||
calendarPane.setFocusable(peer.isDropdownFocusable());
|
||||
calendarPane.setColorOverrideMap(peer.getColorOverrideMap());
|
||||
// popup
|
||||
popup = new JPopupMenu();
|
||||
popup.setLayout(new BorderLayout());
|
||||
popup.add(calendarPane, BorderLayout.CENTER);
|
||||
popup.setLightWeightPopupEnabled(true);
|
||||
// add
|
||||
peer.setLayout(new BorderLayout());
|
||||
|
||||
switch (peer.getPickerStyle()) {
|
||||
case DatePicker.PICKER_STYLE_FIELD_AND_BUTTON:
|
||||
peer.add(field, BorderLayout.CENTER);
|
||||
peer.add(button, BorderLayout.EAST);
|
||||
break;
|
||||
case DatePicker.PICKER_STYLE_BUTTON:
|
||||
peer.add(button, BorderLayout.EAST);
|
||||
break;
|
||||
}
|
||||
switch (peer.getPickerStyle()) {
|
||||
case DatePicker.PICKER_STYLE_FIELD_AND_BUTTON:
|
||||
peer.add(field, BorderLayout.CENTER);
|
||||
peer.add(button, BorderLayout.EAST);
|
||||
break;
|
||||
case DatePicker.PICKER_STYLE_BUTTON:
|
||||
peer.add(button, BorderLayout.EAST);
|
||||
break;
|
||||
}
|
||||
|
||||
peer.revalidate();
|
||||
peer.repaint();
|
||||
peer.revalidate();
|
||||
peer.repaint();
|
||||
|
||||
componentListener = new ComponentListener();
|
||||
componentListener = new ComponentListener();
|
||||
|
||||
button.addActionListener(componentListener);
|
||||
field.addPropertyChangeListener(componentListener);
|
||||
button.addActionListener(componentListener);
|
||||
field.addPropertyChangeListener(componentListener);
|
||||
|
||||
calendarPane.addPropertyChangeListener(componentListener);
|
||||
calendarPane.addCommitListener(componentListener);
|
||||
calendarPane.addActionListener(componentListener);
|
||||
calendarPane.addPropertyChangeListener(componentListener);
|
||||
calendarPane.addCommitListener(componentListener);
|
||||
calendarPane.addActionListener(componentListener);
|
||||
|
||||
peerDateChanged(peer.getDate());
|
||||
}
|
||||
peerDateChanged(peer.getDate());
|
||||
}
|
||||
|
||||
public void setSimpeLook(boolean b) {
|
||||
if (b) {
|
||||
field.setBorder(BorderFactory.createEmptyBorder());
|
||||
button.setText("...");
|
||||
button.setIcon(null);
|
||||
} else {
|
||||
field.setBorder(new JTextField().getBorder());
|
||||
button.setText("");
|
||||
button.setIcon(new ImageIcon(Resource.class
|
||||
.getResource("picker-16.png")));
|
||||
}
|
||||
public void setSimpeLook(boolean b) {
|
||||
if (b) {
|
||||
field.setBorder(BorderFactory.createEmptyBorder());
|
||||
button.setText("...");
|
||||
button.setIcon(null);
|
||||
} else {
|
||||
field.setBorder(new JTextField().getBorder());
|
||||
button.setText("");
|
||||
button.setIcon(new ImageIcon(Resource.class
|
||||
.getResource("picker-16.png")));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void showPopup(boolean visible) {
|
||||
if (visible) {
|
||||
public void showPopup(boolean visible) {
|
||||
if (visible) {
|
||||
|
||||
// try to apply date to calendar pane popup, but not cause commit
|
||||
if (peer.isKeepTime())
|
||||
try {
|
||||
AbstractFormatter formatter = field.getFormatter();
|
||||
Date value = (Date) formatter
|
||||
.stringToValue(field.getText());
|
||||
calendarPane
|
||||
.removePropertyChangeListener(componentListener);
|
||||
calendarPane.setDate(value);
|
||||
calendarPane.addPropertyChangeListener(componentListener);
|
||||
// try to apply date to calendar pane popup, but not cause commit
|
||||
if (peer.isKeepTime())
|
||||
try {
|
||||
AbstractFormatter formatter = field.getFormatter();
|
||||
Date value = (Date) formatter
|
||||
.stringToValue(field.getText());
|
||||
calendarPane
|
||||
.removePropertyChangeListener(componentListener);
|
||||
calendarPane.setDate(value);
|
||||
calendarPane.addPropertyChangeListener(componentListener);
|
||||
|
||||
} catch (ParseException e) {
|
||||
// ignore
|
||||
} catch (PropertyVetoException e) {
|
||||
// can not happen
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
// ignore
|
||||
} catch (PropertyVetoException e) {
|
||||
// can not happen
|
||||
}
|
||||
|
||||
popup.show(peer, 0, peer.getHeight());
|
||||
calendarPane.requestFocus(false);
|
||||
} else {
|
||||
popup.setVisible(false);
|
||||
}
|
||||
}
|
||||
popup.show(peer, 0, peer.getHeight());
|
||||
calendarPane.requestFocus(false);
|
||||
} else {
|
||||
popup.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (JComponent.TOOL_TIP_TEXT_KEY.equals(evt.getPropertyName())) {
|
||||
field.setToolTipText((String) evt.getNewValue());
|
||||
button.setToolTipText((String) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(DatePicker.PROPERTY_NAME_DATE)) {
|
||||
Date newValue = (Date) evt.getNewValue();
|
||||
peerDateChanged(newValue);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_FIELD_EDITABLE)) {
|
||||
field.setEditable(peer.isFieldEditable());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_FOCUS_LOST_BEHAVIOR)) {
|
||||
field.setFocusLostBehavior(peer.getFocusLostBehavior());
|
||||
} else if (evt.getPropertyName()
|
||||
.equals(DatePicker.PROPERTY_NAME_LOCALE)) {
|
||||
field.setFormatterFactory(createFormatterFactory());
|
||||
calendarPane.setLocale(peer.getLocale());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_DATE_FORMAT)) {
|
||||
field.setFormatterFactory(createFormatterFactory());
|
||||
} else if (evt.getPropertyName().equals(DatePicker.PROPERTY_NAME_ZONE)) {
|
||||
field.setFormatterFactory(createFormatterFactory());
|
||||
calendarPane.setZone((TimeZone) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_SHOW_TODAY_BTN)) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
calendarPane.setShowTodayButton(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_SHOW_NONE_BTN)) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
calendarPane.setShowNoneButton(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_SHOW_NUMBER_WEEK)) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
calendarPane.setShowNumberOfWeek(value);
|
||||
} else if (evt.getPropertyName().equals(DatePicker.PROPERTY_NAME_STYLE)) {
|
||||
int value = ((Integer) evt.getNewValue()).intValue();
|
||||
calendarPane.setStyle(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_VETO_POLICY)) {
|
||||
calendarPane.setVetoPolicy((VetoPolicy) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_HOLIDAY_POLICY)) {
|
||||
calendarPane.setHolidayPolicy((HolidayPolicy) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals("focusable")) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
field.setFocusable(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_RESOURCES)) {
|
||||
CalendarResources resources = (CalendarResources) evt.getNewValue();
|
||||
calendarPane.setResources(resources);
|
||||
} else if (evt.getPropertyName()
|
||||
.equals("enabled"/* DatePicker.PROPERTY_NAME_ENABLED */)) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
field.setEnabled(value);
|
||||
button.setEnabled(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_PICKER_STYLE)) {
|
||||
peer.updateUI();
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_DROPDOWN_FOCUSABLE)) {
|
||||
calendarPane.setFocusable(peer.isDropdownFocusable());
|
||||
}
|
||||
}
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (JComponent.TOOL_TIP_TEXT_KEY.equals(evt.getPropertyName())) {
|
||||
field.setToolTipText((String) evt.getNewValue());
|
||||
button.setToolTipText((String) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(DatePicker.PROPERTY_NAME_DATE)) {
|
||||
Date newValue = (Date) evt.getNewValue();
|
||||
peerDateChanged(newValue);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_FIELD_EDITABLE)) {
|
||||
field.setEditable(peer.isFieldEditable());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_FOCUS_LOST_BEHAVIOR)) {
|
||||
field.setFocusLostBehavior(peer.getFocusLostBehavior());
|
||||
} else if (evt.getPropertyName()
|
||||
.equals(DatePicker.PROPERTY_NAME_LOCALE)) {
|
||||
field.setFormatterFactory(createFormatterFactory());
|
||||
calendarPane.setLocale(peer.getLocale());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_DATE_FORMAT)) {
|
||||
field.setFormatterFactory(createFormatterFactory());
|
||||
} else if (evt.getPropertyName().equals(DatePicker.PROPERTY_NAME_ZONE)) {
|
||||
field.setFormatterFactory(createFormatterFactory());
|
||||
calendarPane.setZone((TimeZone) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_SHOW_TODAY_BTN)) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
calendarPane.setShowTodayButton(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_SHOW_NONE_BTN)) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
calendarPane.setShowNoneButton(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_SHOW_NUMBER_WEEK)) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
calendarPane.setShowNumberOfWeek(value);
|
||||
} else if (evt.getPropertyName().equals(DatePicker.PROPERTY_NAME_STYLE)) {
|
||||
int value = ((Integer) evt.getNewValue()).intValue();
|
||||
calendarPane.setStyle(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_VETO_POLICY)) {
|
||||
calendarPane.setVetoPolicy((VetoPolicy) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_HOLIDAY_POLICY)) {
|
||||
calendarPane.setHolidayPolicy((HolidayPolicy) evt.getNewValue());
|
||||
} else if (evt.getPropertyName().equals("focusable")) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
field.setFocusable(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_RESOURCES)) {
|
||||
CalendarResources resources = (CalendarResources) evt.getNewValue();
|
||||
calendarPane.setResources(resources);
|
||||
} else if (evt.getPropertyName()
|
||||
.equals("enabled"/* DatePicker.PROPERTY_NAME_ENABLED */)) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
field.setEnabled(value);
|
||||
button.setEnabled(value);
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_PICKER_STYLE)) {
|
||||
peer.updateUI();
|
||||
} else if (evt.getPropertyName().equals(
|
||||
DatePicker.PROPERTY_NAME_DROPDOWN_FOCUSABLE)) {
|
||||
calendarPane.setFocusable(peer.isDropdownFocusable());
|
||||
}
|
||||
}
|
||||
|
||||
private void peerDateChanged(Date newValue) {
|
||||
try {
|
||||
calendarPane.removePropertyChangeListener(componentListener);
|
||||
calendarPane.setDate(newValue);
|
||||
calendarPane.addPropertyChangeListener(componentListener);
|
||||
} catch (PropertyVetoException e) {
|
||||
// Ignore. CalendarPane has no VetoModel here.
|
||||
}
|
||||
field.removePropertyChangeListener(componentListener);
|
||||
field.setValue(newValue);
|
||||
field.addPropertyChangeListener(componentListener);
|
||||
}
|
||||
private void peerDateChanged(Date newValue) {
|
||||
try {
|
||||
calendarPane.removePropertyChangeListener(componentListener);
|
||||
calendarPane.setDate(newValue);
|
||||
calendarPane.addPropertyChangeListener(componentListener);
|
||||
} catch (PropertyVetoException e) {
|
||||
// Ignore. CalendarPane has no VetoModel here.
|
||||
}
|
||||
field.removePropertyChangeListener(componentListener);
|
||||
field.setValue(newValue);
|
||||
field.addPropertyChangeListener(componentListener);
|
||||
}
|
||||
|
||||
private DefaultFormatterFactory createFormatterFactory() {
|
||||
return new DefaultFormatterFactory(new DateFormatter(peer
|
||||
.getDateFormat()));
|
||||
}
|
||||
private DefaultFormatterFactory createFormatterFactory() {
|
||||
return new DefaultFormatterFactory(new DateFormatter(peer
|
||||
.getDateFormat()));
|
||||
}
|
||||
|
||||
protected class ComponentListener implements ActionListener,
|
||||
PropertyChangeListener, CommitListener {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
protected class ComponentListener implements ActionListener,
|
||||
PropertyChangeListener, CommitListener {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
if (e.getSource() != calendarPane)
|
||||
showPopup(true);
|
||||
else
|
||||
showPopup(false);
|
||||
if (e.getSource() != calendarPane)
|
||||
showPopup(true);
|
||||
else
|
||||
showPopup(false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getSource() == calendarPane) {
|
||||
if (CalendarPane.PROPERTY_NAME_DATE.equals(evt
|
||||
.getPropertyName())) {
|
||||
showPopup(false);
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getSource() == calendarPane) {
|
||||
if (CalendarPane.PROPERTY_NAME_DATE.equals(evt
|
||||
.getPropertyName())) {
|
||||
showPopup(false);
|
||||
|
||||
Date fieldValue = null;
|
||||
try {
|
||||
AbstractFormatter formatter = field.getFormatter();
|
||||
fieldValue = (Date) formatter.stringToValue(field
|
||||
.getText());
|
||||
Date fieldValue = null;
|
||||
try {
|
||||
AbstractFormatter formatter = field.getFormatter();
|
||||
fieldValue = (Date) formatter.stringToValue(field
|
||||
.getText());
|
||||
|
||||
} catch (ParseException e) {
|
||||
fieldValue = (Date) field.getValue();
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
fieldValue = (Date) field.getValue();
|
||||
}
|
||||
|
||||
if (fieldValue != null || evt.getNewValue() != null) {
|
||||
if (fieldValue != null || evt.getNewValue() != null) {
|
||||
|
||||
if (peer.isKeepTime() && fieldValue != null
|
||||
&& evt.getNewValue() != null) {
|
||||
if (peer.isKeepTime() && fieldValue != null
|
||||
&& evt.getNewValue() != null) {
|
||||
|
||||
Calendar fieldCal = Calendar.getInstance(peer
|
||||
.getZone(), peer.getLocale());
|
||||
fieldCal.setTime(fieldValue);
|
||||
Calendar fieldCal = Calendar.getInstance(peer
|
||||
.getZone(), peer.getLocale());
|
||||
fieldCal.setTime(fieldValue);
|
||||
|
||||
Calendar valueCal = Calendar.getInstance(peer
|
||||
.getZone(), peer.getLocale());
|
||||
valueCal.setTime((Date) evt.getNewValue());
|
||||
Calendar valueCal = Calendar.getInstance(peer
|
||||
.getZone(), peer.getLocale());
|
||||
valueCal.setTime((Date) evt.getNewValue());
|
||||
|
||||
// era
|
||||
fieldCal.set(Calendar.ERA, valueCal
|
||||
.get(Calendar.ERA));
|
||||
// year
|
||||
fieldCal.set(Calendar.YEAR, valueCal
|
||||
.get(Calendar.YEAR));
|
||||
// month
|
||||
fieldCal.set(Calendar.MONTH, valueCal
|
||||
.get(Calendar.MONTH));
|
||||
// date
|
||||
fieldCal.set(Calendar.DAY_OF_MONTH, valueCal
|
||||
.get(Calendar.DAY_OF_MONTH));
|
||||
field.setValue(fieldCal.getTime());
|
||||
} else
|
||||
field.setValue((Date) evt.getNewValue());
|
||||
// era
|
||||
fieldCal.set(Calendar.ERA, valueCal
|
||||
.get(Calendar.ERA));
|
||||
// year
|
||||
fieldCal.set(Calendar.YEAR, valueCal
|
||||
.get(Calendar.YEAR));
|
||||
// month
|
||||
fieldCal.set(Calendar.MONTH, valueCal
|
||||
.get(Calendar.MONTH));
|
||||
// date
|
||||
fieldCal.set(Calendar.DAY_OF_MONTH, valueCal
|
||||
.get(Calendar.DAY_OF_MONTH));
|
||||
field.setValue(fieldCal.getTime());
|
||||
} else
|
||||
field.setValue((Date) evt.getNewValue());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evt.getSource() == field) {
|
||||
if ("value".equals(evt.getPropertyName())) {
|
||||
Date value = (Date) field.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evt.getSource() == field) {
|
||||
if ("value".equals(evt.getPropertyName())) {
|
||||
Date value = (Date) field.getValue();
|
||||
|
||||
try {
|
||||
peer.setDate(value);
|
||||
} catch (PropertyVetoException e) {
|
||||
field.setValue(peer.getDate());
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
peer.setDate(value);
|
||||
} catch (PropertyVetoException e) {
|
||||
field.setValue(peer.getDate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void commit(CommitEvent action) {
|
||||
showPopup(false);
|
||||
if (field.getValue() != null || calendarPane.getDate() != null)
|
||||
field.setValue(calendarPane.getDate());
|
||||
}
|
||||
public void commit(CommitEvent action) {
|
||||
showPopup(false);
|
||||
if (field.getValue() != null || calendarPane.getDate() != null)
|
||||
field.setValue(calendarPane.getDate());
|
||||
}
|
||||
|
||||
public void revert(CommitEvent action) {
|
||||
showPopup(false);
|
||||
public void revert(CommitEvent action) {
|
||||
showPopup(false);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void commit() throws PropertyVetoException, ParseException {
|
||||
field.commitEdit();
|
||||
}
|
||||
public void commit() throws PropertyVetoException, ParseException {
|
||||
field.commitEdit();
|
||||
}
|
||||
|
||||
public void revert() {
|
||||
peerDateChanged(peer.getDate());
|
||||
}
|
||||
public void revert() {
|
||||
peerDateChanged(peer.getDate());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,133 +21,133 @@ import com.michaelbaranov.microba.calendar.HolidayPolicy;
|
||||
|
||||
class CalendarHeader extends JPanel {
|
||||
|
||||
private Locale locale;
|
||||
private Locale locale;
|
||||
|
||||
private TimeZone zone;
|
||||
private TimeZone zone;
|
||||
|
||||
private Date date;
|
||||
private Date date;
|
||||
|
||||
private HolidayPolicy holidayPolicy;
|
||||
private HolidayPolicy holidayPolicy;
|
||||
|
||||
private Color backgroundColorActive;
|
||||
private Color backgroundColorActive;
|
||||
|
||||
private Color backgroundColorInactive;
|
||||
private Color backgroundColorInactive;
|
||||
|
||||
private Color foregroundColorActive;
|
||||
private Color foregroundColorActive;
|
||||
|
||||
private Color foregroundColorInactive;
|
||||
private Color foregroundColorInactive;
|
||||
|
||||
private Color foregroundColorWeekendEnabled;
|
||||
private Color foregroundColorWeekendEnabled;
|
||||
|
||||
private Color foregroundColorWeekendDisabled;
|
||||
private Color foregroundColorWeekendDisabled;
|
||||
|
||||
public CalendarHeader(CalendarPane peer, Date date, Locale locale,
|
||||
TimeZone zone, HolidayPolicy holidayPolicy) {
|
||||
super();
|
||||
public CalendarHeader(CalendarPane peer, Date date, Locale locale,
|
||||
TimeZone zone, HolidayPolicy holidayPolicy) {
|
||||
super();
|
||||
|
||||
backgroundColorActive = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_BACKGROUND_ENABLED, peer,
|
||||
UIManager.getColor("activeCaption"));
|
||||
backgroundColorInactive = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_BACKGROUND_DISABLED, peer,
|
||||
UIManager.getColor("inactiveCaption"));
|
||||
foregroundColorActive = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_FOREGROUND_ENABLED, peer,
|
||||
UIManager.getColor("controlText"));
|
||||
foregroundColorInactive = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_FOREGROUND_DISABLED, peer,
|
||||
UIManager.getColor("textInactiveText"));
|
||||
foregroundColorWeekendEnabled = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_FOREGROUND_WEEKEND_ENABLED,
|
||||
peer, Color.RED);
|
||||
foregroundColorWeekendDisabled = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_FOREGROUND_WEEKEND_DISABLED,
|
||||
peer, foregroundColorInactive);
|
||||
backgroundColorActive = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_BACKGROUND_ENABLED, peer,
|
||||
UIManager.getColor("activeCaption"));
|
||||
backgroundColorInactive = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_BACKGROUND_DISABLED, peer,
|
||||
UIManager.getColor("inactiveCaption"));
|
||||
foregroundColorActive = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_FOREGROUND_ENABLED, peer,
|
||||
UIManager.getColor("controlText"));
|
||||
foregroundColorInactive = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_FOREGROUND_DISABLED, peer,
|
||||
UIManager.getColor("textInactiveText"));
|
||||
foregroundColorWeekendEnabled = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_FOREGROUND_WEEKEND_ENABLED,
|
||||
peer, Color.RED);
|
||||
foregroundColorWeekendDisabled = Microba.getOverridenColor(
|
||||
CalendarPane.COLOR_CALENDAR_HEADER_FOREGROUND_WEEKEND_DISABLED,
|
||||
peer, foregroundColorInactive);
|
||||
|
||||
this.locale = locale;
|
||||
this.zone = zone;
|
||||
this.date = date;
|
||||
this.holidayPolicy = holidayPolicy;
|
||||
reflectData();
|
||||
}
|
||||
this.locale = locale;
|
||||
this.zone = zone;
|
||||
this.date = date;
|
||||
this.holidayPolicy = holidayPolicy;
|
||||
reflectData();
|
||||
}
|
||||
|
||||
private void reflectData() {
|
||||
private void reflectData() {
|
||||
|
||||
Calendar cal = Calendar.getInstance(zone, locale);
|
||||
cal.setTime(date == null ? new Date() : date);
|
||||
Calendar cal = Calendar.getInstance(zone, locale);
|
||||
cal.setTime(date == null ? new Date() : date);
|
||||
|
||||
SimpleDateFormat fmt = new SimpleDateFormat("E", locale);
|
||||
fmt.setTimeZone(zone);
|
||||
SimpleDateFormat fmt = new SimpleDateFormat("E", locale);
|
||||
fmt.setTimeZone(zone);
|
||||
|
||||
int numDaysInWeek = cal.getActualMaximum(Calendar.DAY_OF_WEEK)
|
||||
- cal.getActualMinimum(Calendar.DAY_OF_WEEK) + 1;
|
||||
int firstDayOfWeek = cal.getFirstDayOfWeek();
|
||||
int numDaysInWeek = cal.getActualMaximum(Calendar.DAY_OF_WEEK)
|
||||
- cal.getActualMinimum(Calendar.DAY_OF_WEEK) + 1;
|
||||
int firstDayOfWeek = cal.getFirstDayOfWeek();
|
||||
|
||||
cal.set(Calendar.DAY_OF_WEEK, firstDayOfWeek);
|
||||
cal.set(Calendar.DAY_OF_WEEK, firstDayOfWeek);
|
||||
|
||||
removeAll();
|
||||
setLayout(new GridLayout(1, numDaysInWeek, 2, 2));
|
||||
removeAll();
|
||||
setLayout(new GridLayout(1, numDaysInWeek, 2, 2));
|
||||
|
||||
setBackground(isEnabled() ? backgroundColorActive
|
||||
: backgroundColorInactive);
|
||||
setBackground(isEnabled() ? backgroundColorActive
|
||||
: backgroundColorInactive);
|
||||
|
||||
for (int i = 0; i < numDaysInWeek; i++) {
|
||||
JLabel label = new JLabel();
|
||||
// TODO: add option to control limit length:
|
||||
label.setText(fmt.format(cal.getTime())/* .substring(0,1) */);
|
||||
label.setForeground(isEnabled() ? foregroundColorActive
|
||||
: foregroundColorInactive);
|
||||
label.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
label.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0));
|
||||
Font boldFont = label.getFont().deriveFont(Font.BOLD);
|
||||
label.setFont(boldFont);
|
||||
add(label);
|
||||
for (int i = 0; i < numDaysInWeek; i++) {
|
||||
JLabel label = new JLabel();
|
||||
// TODO: add option to control limit length:
|
||||
label.setText(fmt.format(cal.getTime())/* .substring(0,1) */);
|
||||
label.setForeground(isEnabled() ? foregroundColorActive
|
||||
: foregroundColorInactive);
|
||||
label.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
label.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0));
|
||||
Font boldFont = label.getFont().deriveFont(Font.BOLD);
|
||||
label.setFont(boldFont);
|
||||
add(label);
|
||||
|
||||
boolean isHolliday = false;
|
||||
if (holidayPolicy != null) {
|
||||
isHolliday = holidayPolicy.isWeekend(this, cal);
|
||||
}
|
||||
boolean isHolliday = false;
|
||||
if (holidayPolicy != null) {
|
||||
isHolliday = holidayPolicy.isWeekend(this, cal);
|
||||
}
|
||||
|
||||
if (isHolliday)
|
||||
label.setForeground(isEnabled() ? foregroundColorWeekendEnabled
|
||||
: foregroundColorWeekendDisabled);
|
||||
if (isHolliday)
|
||||
label.setForeground(isEnabled() ? foregroundColorWeekendEnabled
|
||||
: foregroundColorWeekendDisabled);
|
||||
|
||||
cal.add(Calendar.DAY_OF_WEEK, 1);
|
||||
}
|
||||
setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 1));
|
||||
revalidate();
|
||||
repaint();
|
||||
cal.add(Calendar.DAY_OF_WEEK, 1);
|
||||
}
|
||||
setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 1));
|
||||
revalidate();
|
||||
repaint();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
this.locale = locale;
|
||||
reflectData();
|
||||
}
|
||||
public void setLocale(Locale locale) {
|
||||
this.locale = locale;
|
||||
reflectData();
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
reflectData();
|
||||
}
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
reflectData();
|
||||
}
|
||||
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public void setZone(TimeZone zone) {
|
||||
this.zone = zone;
|
||||
reflectData();
|
||||
}
|
||||
public void setZone(TimeZone zone) {
|
||||
this.zone = zone;
|
||||
reflectData();
|
||||
}
|
||||
|
||||
public void setHolidayPolicy(HolidayPolicy holidayPolicy) {
|
||||
this.holidayPolicy = holidayPolicy;
|
||||
reflectData();
|
||||
public void setHolidayPolicy(HolidayPolicy holidayPolicy) {
|
||||
this.holidayPolicy = holidayPolicy;
|
||||
reflectData();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
reflectData();
|
||||
}
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
reflectData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,117 +16,117 @@ import javax.swing.JPanel;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
public class CalendarNumberOfWeekPanel extends JPanel /*
|
||||
* implements
|
||||
* PropertyChangeListener
|
||||
*/{
|
||||
* implements
|
||||
* PropertyChangeListener
|
||||
*/{
|
||||
|
||||
public static final String PROPERTY_NAME_BASE_DATE = "baseDate";
|
||||
public static final String PROPERTY_NAME_BASE_DATE = "baseDate";
|
||||
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
|
||||
public static final String PROPERTY_NAME_ZONE = "zone";
|
||||
public static final String PROPERTY_NAME_ZONE = "zone";
|
||||
|
||||
private Color backgroundColorActive = UIManager.getColor("activeCaption");
|
||||
private Color backgroundColorActive = UIManager.getColor("activeCaption");
|
||||
|
||||
private Color backgroundColorInactive = UIManager
|
||||
.getColor("inactiveCaption");
|
||||
private Color backgroundColorInactive = UIManager
|
||||
.getColor("inactiveCaption");
|
||||
|
||||
private Date baseDate;
|
||||
private Date baseDate;
|
||||
|
||||
private Locale locale;
|
||||
private Locale locale;
|
||||
|
||||
private TimeZone zone;
|
||||
private TimeZone zone;
|
||||
|
||||
private JLabel[] labels = new JLabel[6];
|
||||
private JLabel[] labels = new JLabel[6];
|
||||
|
||||
public CalendarNumberOfWeekPanel(Date baseDate, Locale locale,
|
||||
TimeZone timeZone) {
|
||||
super();
|
||||
this.baseDate = baseDate == null ? new Date() : baseDate;
|
||||
this.locale = locale;
|
||||
this.zone = timeZone;
|
||||
public CalendarNumberOfWeekPanel(Date baseDate, Locale locale,
|
||||
TimeZone timeZone) {
|
||||
super();
|
||||
this.baseDate = baseDate == null ? new Date() : baseDate;
|
||||
this.locale = locale;
|
||||
this.zone = timeZone;
|
||||
|
||||
setLayout(new GridLayout(6, 1, 2, 2));
|
||||
setLayout(new GridLayout(6, 1, 2, 2));
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
JLabel l = new JLabel();
|
||||
labels[i] = l;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
JLabel l = new JLabel();
|
||||
labels[i] = l;
|
||||
|
||||
add(l);
|
||||
}
|
||||
add(l);
|
||||
}
|
||||
|
||||
setBorder(BorderFactory.createEmptyBorder(1, 4, 1, 4));
|
||||
setBorder(BorderFactory.createEmptyBorder(1, 4, 1, 4));
|
||||
|
||||
reflectBaseDate();
|
||||
}
|
||||
reflectBaseDate();
|
||||
}
|
||||
|
||||
public void setBaseDate(Date baseDate) {
|
||||
this.baseDate = baseDate;
|
||||
reflectBaseDate();
|
||||
}
|
||||
public void setBaseDate(Date baseDate) {
|
||||
this.baseDate = baseDate;
|
||||
reflectBaseDate();
|
||||
}
|
||||
|
||||
private void reflectBaseDate() {
|
||||
Calendar calendar = getCalendar(baseDate);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
private void reflectBaseDate() {
|
||||
Calendar calendar = getCalendar(baseDate);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
int skipBefore = calendar.get(Calendar.DAY_OF_WEEK)
|
||||
- calendar.getFirstDayOfWeek();
|
||||
if (skipBefore < 0)
|
||||
skipBefore = 7 + skipBefore;
|
||||
int skipBefore = calendar.get(Calendar.DAY_OF_WEEK)
|
||||
- calendar.getFirstDayOfWeek();
|
||||
if (skipBefore < 0)
|
||||
skipBefore = 7 + skipBefore;
|
||||
|
||||
int activeDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
int activeDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
|
||||
int numActiveWeeks = (activeDays + skipBefore) / 7;
|
||||
if ((activeDays + skipBefore) % 7 > 0)
|
||||
numActiveWeeks++;
|
||||
int numActiveWeeks = (activeDays + skipBefore) / 7;
|
||||
if ((activeDays + skipBefore) % 7 > 0)
|
||||
numActiveWeeks++;
|
||||
|
||||
int startWeek = calendar.get(Calendar.WEEK_OF_YEAR);
|
||||
int startWeek = calendar.get(Calendar.WEEK_OF_YEAR);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
labels[i].setText(startWeek > 0 && numActiveWeeks > 0 ? String
|
||||
.valueOf(startWeek) : "");
|
||||
for (int i = 0; i < 6; i++) {
|
||||
labels[i].setText(startWeek > 0 && numActiveWeeks > 0 ? String
|
||||
.valueOf(startWeek) : "");
|
||||
|
||||
labels[i].setForeground(isEnabled() ? UIManager
|
||||
.getColor("controlText") : UIManager
|
||||
.getColor("textInactiveText"));
|
||||
|
||||
calendar.add(Calendar.WEEK_OF_YEAR, 1);
|
||||
startWeek = calendar.get(Calendar.WEEK_OF_YEAR);
|
||||
labels[i].setForeground(isEnabled() ? UIManager
|
||||
.getColor("controlText") : UIManager
|
||||
.getColor("textInactiveText"));
|
||||
|
||||
calendar.add(Calendar.WEEK_OF_YEAR, 1);
|
||||
startWeek = calendar.get(Calendar.WEEK_OF_YEAR);
|
||||
|
||||
numActiveWeeks--;
|
||||
}
|
||||
numActiveWeeks--;
|
||||
}
|
||||
|
||||
setBackground(isEnabled() ? backgroundColorActive
|
||||
: backgroundColorInactive);
|
||||
}
|
||||
setBackground(isEnabled() ? backgroundColorActive
|
||||
: backgroundColorInactive);
|
||||
}
|
||||
|
||||
private Calendar getCalendar(Date date) {
|
||||
Calendar c = Calendar.getInstance(zone, locale);
|
||||
c.setTime(date);
|
||||
return c;
|
||||
}
|
||||
private Calendar getCalendar(Date date) {
|
||||
Calendar c = Calendar.getInstance(zone, locale);
|
||||
c.setTime(date);
|
||||
return c;
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
this.locale = locale;
|
||||
reflectBaseDate();
|
||||
}
|
||||
public void setLocale(Locale locale) {
|
||||
this.locale = locale;
|
||||
reflectBaseDate();
|
||||
}
|
||||
|
||||
public void setZone(TimeZone zone) {
|
||||
this.zone = zone;
|
||||
reflectBaseDate();
|
||||
}
|
||||
public void setZone(TimeZone zone) {
|
||||
this.zone = zone;
|
||||
reflectBaseDate();
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
FontMetrics fm = g.getFontMetrics(labels[0].getFont());
|
||||
Dimension dimension = new Dimension(fm.stringWidth("00") + 8, 1);
|
||||
setMinimumSize(dimension);
|
||||
setPreferredSize(dimension);
|
||||
super.paint(g);
|
||||
}
|
||||
public void paint(Graphics g) {
|
||||
FontMetrics fm = g.getFontMetrics(labels[0].getFont());
|
||||
Dimension dimension = new Dimension(fm.stringWidth("00") + 8, 1);
|
||||
setMinimumSize(dimension);
|
||||
setPreferredSize(dimension);
|
||||
super.paint(g);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
reflectBaseDate();
|
||||
}
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
reflectBaseDate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,238 +28,238 @@ import javax.swing.SwingConstants;
|
||||
import com.michaelbaranov.microba.calendar.resource.Resource;
|
||||
|
||||
class ClassicCalendarPanel extends JPanel implements
|
||||
PropertyChangeListener {
|
||||
PropertyChangeListener {
|
||||
|
||||
public static final String PROPERTY_NAME_DATE = "date";
|
||||
public static final String PROPERTY_NAME_DATE = "date";
|
||||
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
|
||||
public static final String PROPERTY_NAME_ZONE = "zone";
|
||||
public static final String PROPERTY_NAME_ZONE = "zone";
|
||||
|
||||
private Locale locale;
|
||||
private Locale locale;
|
||||
|
||||
private TimeZone zone;
|
||||
private TimeZone zone;
|
||||
|
||||
private Calendar calendar;
|
||||
private Calendar calendar;
|
||||
|
||||
private JButton prevButton;
|
||||
private JButton prevButton;
|
||||
|
||||
private JButton nextButton;
|
||||
private JButton nextButton;
|
||||
|
||||
private JLabel selectedDateLabel;
|
||||
private JLabel selectedDateLabel;
|
||||
|
||||
private DateFormat format;
|
||||
private DateFormat format;
|
||||
|
||||
private Set focusableComponents = new HashSet();
|
||||
private Set focusableComponents = new HashSet();
|
||||
|
||||
private JButton fastPrevButton;
|
||||
private JButton fastPrevButton;
|
||||
|
||||
private JButton fastNextButton;
|
||||
private JButton fastNextButton;
|
||||
|
||||
public ClassicCalendarPanel(Date aDate, Locale aLocale, TimeZone zone) {
|
||||
this.locale = aLocale;
|
||||
this.zone = zone;
|
||||
public ClassicCalendarPanel(Date aDate, Locale aLocale, TimeZone zone) {
|
||||
this.locale = aLocale;
|
||||
this.zone = zone;
|
||||
|
||||
prevButton = new JButton();
|
||||
nextButton = new JButton();
|
||||
prevButton = new JButton();
|
||||
nextButton = new JButton();
|
||||
|
||||
fastPrevButton = new JButton();
|
||||
fastNextButton = new JButton();
|
||||
fastPrevButton = new JButton();
|
||||
fastNextButton = new JButton();
|
||||
|
||||
nextButton.setIcon(new ImageIcon(Resource.class.getResource("forward-16.png")));
|
||||
prevButton.setIcon(new ImageIcon(Resource.class.getResource("back-16.png")));
|
||||
fastNextButton.setIcon(new ImageIcon(Resource.class.getResource("forward-fast-16.png")));
|
||||
fastPrevButton.setIcon(new ImageIcon(Resource.class.getResource("back-fast-16.png")));
|
||||
prevButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
nextButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
fastPrevButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
fastNextButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
nextButton.setIcon(new ImageIcon(Resource.class.getResource("forward-16.png")));
|
||||
prevButton.setIcon(new ImageIcon(Resource.class.getResource("back-16.png")));
|
||||
fastNextButton.setIcon(new ImageIcon(Resource.class.getResource("forward-fast-16.png")));
|
||||
fastPrevButton.setIcon(new ImageIcon(Resource.class.getResource("back-fast-16.png")));
|
||||
prevButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
nextButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
fastPrevButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
fastNextButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
|
||||
Dimension psz = nextButton.getPreferredSize();
|
||||
Dimension npsz = new Dimension(psz.height, psz.height);
|
||||
Dimension psz = nextButton.getPreferredSize();
|
||||
Dimension npsz = new Dimension(psz.height, psz.height);
|
||||
|
||||
nextButton.setPreferredSize(npsz);
|
||||
prevButton.setPreferredSize(npsz);
|
||||
nextButton.setPreferredSize(npsz);
|
||||
prevButton.setPreferredSize(npsz);
|
||||
|
||||
selectedDateLabel = new JLabel();
|
||||
selectedDateLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
selectedDateLabel.setFont(selectedDateLabel.getFont().deriveFont(
|
||||
Font.BOLD));
|
||||
setLayout(new GridBagLayout());
|
||||
add(fastPrevButton, new GridBagConstraints(0, 0, 1, 1, 0, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
0, 0, 3, 0), 0, 0));
|
||||
add(prevButton, new GridBagConstraints(1, 0, 1, 1, 0, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
0, 0, 3, 0), 0, 0));
|
||||
add(selectedDateLabel, new GridBagConstraints(2, 0, 1, 1, 1.0, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 3, 3, 3), 0, 0));
|
||||
add(nextButton, new GridBagConstraints(3, 0, 1, 1, 0, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
0, 0, 3, 0), 0, 0));
|
||||
add(fastNextButton, new GridBagConstraints(4, 0, 1, 1, 0, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
0, 0, 3, 0), 0, 0));
|
||||
selectedDateLabel = new JLabel();
|
||||
selectedDateLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
selectedDateLabel.setFont(selectedDateLabel.getFont().deriveFont(
|
||||
Font.BOLD));
|
||||
setLayout(new GridBagLayout());
|
||||
add(fastPrevButton, new GridBagConstraints(0, 0, 1, 1, 0, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
0, 0, 3, 0), 0, 0));
|
||||
add(prevButton, new GridBagConstraints(1, 0, 1, 1, 0, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
0, 0, 3, 0), 0, 0));
|
||||
add(selectedDateLabel, new GridBagConstraints(2, 0, 1, 1, 1.0, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 3, 3, 3), 0, 0));
|
||||
add(nextButton, new GridBagConstraints(3, 0, 1, 1, 0, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
0, 0, 3, 0), 0, 0));
|
||||
add(fastNextButton, new GridBagConstraints(4, 0, 1, 1, 0, 0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
0, 0, 3, 0), 0, 0));
|
||||
|
||||
nextButton.addActionListener(new ActionListener() {
|
||||
nextButton.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Date old = calendar.getTime();
|
||||
calendar.add(Calendar.MONTH, 1);
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, getDate());
|
||||
reflectData();
|
||||
}
|
||||
});
|
||||
prevButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Date old = calendar.getTime();
|
||||
calendar.add(Calendar.MONTH, 1);
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, getDate());
|
||||
reflectData();
|
||||
}
|
||||
});
|
||||
prevButton.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Date old = calendar.getTime();
|
||||
calendar.add(Calendar.MONTH, -1);
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, getDate());
|
||||
reflectData();
|
||||
}
|
||||
});
|
||||
fastNextButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Date old = calendar.getTime();
|
||||
calendar.add(Calendar.MONTH, -1);
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, getDate());
|
||||
reflectData();
|
||||
}
|
||||
});
|
||||
fastNextButton.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Date old = calendar.getTime();
|
||||
calendar.add(Calendar.YEAR, 1);
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, getDate());
|
||||
reflectData();
|
||||
}
|
||||
});
|
||||
fastPrevButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Date old = calendar.getTime();
|
||||
calendar.add(Calendar.YEAR, 1);
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, getDate());
|
||||
reflectData();
|
||||
}
|
||||
});
|
||||
fastPrevButton.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Date old = calendar.getTime();
|
||||
calendar.add(Calendar.YEAR, -1);
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, getDate());
|
||||
reflectData();
|
||||
}
|
||||
});
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Date old = calendar.getTime();
|
||||
calendar.add(Calendar.YEAR, -1);
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, getDate());
|
||||
reflectData();
|
||||
}
|
||||
});
|
||||
|
||||
this.addPropertyChangeListener(this);
|
||||
this.addPropertyChangeListener(this);
|
||||
|
||||
focusableComponents.add(prevButton);
|
||||
focusableComponents.add(nextButton);
|
||||
focusableComponents.add(fastNextButton);
|
||||
focusableComponents.add(fastPrevButton);
|
||||
focusableComponents.add(prevButton);
|
||||
focusableComponents.add(nextButton);
|
||||
focusableComponents.add(fastNextButton);
|
||||
focusableComponents.add(fastPrevButton);
|
||||
|
||||
createLocaleAndZoneSensitive();
|
||||
calendar.setTime(aDate);
|
||||
reflectData();
|
||||
}
|
||||
createLocaleAndZoneSensitive();
|
||||
calendar.setTime(aDate);
|
||||
reflectData();
|
||||
}
|
||||
|
||||
private void createLocaleAndZoneSensitive() {
|
||||
if (calendar != null) {
|
||||
Date old = calendar.getTime();
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
calendar.setTime(old);
|
||||
} else
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
private void createLocaleAndZoneSensitive() {
|
||||
if (calendar != null) {
|
||||
Date old = calendar.getTime();
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
calendar.setTime(old);
|
||||
} else
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
|
||||
format = new SimpleDateFormat("MMMMM yyyy", locale);
|
||||
format.setTimeZone(zone);
|
||||
format = new SimpleDateFormat("MMMMM yyyy", locale);
|
||||
format.setTimeZone(zone);
|
||||
|
||||
setPreferredLabelSize();
|
||||
setPreferredLabelSize();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void setPreferredLabelSize() {
|
||||
Calendar c = Calendar.getInstance(zone, locale);
|
||||
c.setTime(getDate());
|
||||
private void setPreferredLabelSize() {
|
||||
Calendar c = Calendar.getInstance(zone, locale);
|
||||
c.setTime(getDate());
|
||||
|
||||
JLabel l = new JLabel();
|
||||
l.setFont(selectedDateLabel.getFont());
|
||||
JLabel l = new JLabel();
|
||||
l.setFont(selectedDateLabel.getFont());
|
||||
|
||||
int maxWidth = Integer.MIN_VALUE;
|
||||
for (int i = 0; i <= c.getActualMaximum(Calendar.MONTH); i++) {
|
||||
c.set(Calendar.MONTH, i);
|
||||
String text = format.format(c.getTime());
|
||||
l.setText(text);
|
||||
int w = l.getPreferredSize().width;
|
||||
if (w > maxWidth)
|
||||
maxWidth = w;
|
||||
}
|
||||
Dimension d = l.getPreferredSize();
|
||||
d.width = maxWidth + 10;
|
||||
selectedDateLabel.setMinimumSize(d);
|
||||
selectedDateLabel.setPreferredSize(d);
|
||||
this.revalidate();
|
||||
}
|
||||
int maxWidth = Integer.MIN_VALUE;
|
||||
for (int i = 0; i <= c.getActualMaximum(Calendar.MONTH); i++) {
|
||||
c.set(Calendar.MONTH, i);
|
||||
String text = format.format(c.getTime());
|
||||
l.setText(text);
|
||||
int w = l.getPreferredSize().width;
|
||||
if (w > maxWidth)
|
||||
maxWidth = w;
|
||||
}
|
||||
Dimension d = l.getPreferredSize();
|
||||
d.width = maxWidth + 10;
|
||||
selectedDateLabel.setMinimumSize(d);
|
||||
selectedDateLabel.setPreferredSize(d);
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
private void reflectData() {
|
||||
selectedDateLabel.setText(format.format(calendar.getTime()));
|
||||
}
|
||||
private void reflectData() {
|
||||
selectedDateLabel.setText(format.format(calendar.getTime()));
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return calendar.getTime();
|
||||
}
|
||||
public Date getDate() {
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
Date old = getDate();
|
||||
calendar.setTime(date);
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, date);
|
||||
reflectData();
|
||||
}
|
||||
public void setDate(Date date) {
|
||||
Date old = getDate();
|
||||
calendar.setTime(date);
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, date);
|
||||
reflectData();
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
Locale old = this.locale;
|
||||
this.locale = locale;
|
||||
createLocaleAndZoneSensitive();
|
||||
firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
reflectData();
|
||||
}
|
||||
public void setLocale(Locale locale) {
|
||||
Locale old = this.locale;
|
||||
this.locale = locale;
|
||||
createLocaleAndZoneSensitive();
|
||||
firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
reflectData();
|
||||
}
|
||||
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public void setZone(TimeZone zone) {
|
||||
TimeZone old = this.zone;
|
||||
this.zone = zone;
|
||||
createLocaleAndZoneSensitive();
|
||||
firePropertyChange(PROPERTY_NAME_ZONE, old, locale);
|
||||
reflectData();
|
||||
}
|
||||
public void setZone(TimeZone zone) {
|
||||
TimeZone old = this.zone;
|
||||
this.zone = zone;
|
||||
createLocaleAndZoneSensitive();
|
||||
firePropertyChange(PROPERTY_NAME_ZONE, old, locale);
|
||||
reflectData();
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals("focusable")) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
prevButton.setFocusable(value.booleanValue());
|
||||
nextButton.setFocusable(value.booleanValue());
|
||||
fastNextButton.setFocusable(value.booleanValue());
|
||||
fastPrevButton.setFocusable(value.booleanValue());
|
||||
}
|
||||
if (evt.getPropertyName().equals("enabled")) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
prevButton.setEnabled(value.booleanValue());
|
||||
nextButton.setEnabled(value.booleanValue());
|
||||
fastNextButton.setEnabled(value.booleanValue());
|
||||
fastPrevButton.setEnabled(value.booleanValue());
|
||||
}
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals("focusable")) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
prevButton.setFocusable(value.booleanValue());
|
||||
nextButton.setFocusable(value.booleanValue());
|
||||
fastNextButton.setFocusable(value.booleanValue());
|
||||
fastPrevButton.setFocusable(value.booleanValue());
|
||||
}
|
||||
if (evt.getPropertyName().equals("enabled")) {
|
||||
Boolean value = (Boolean) evt.getNewValue();
|
||||
prevButton.setEnabled(value.booleanValue());
|
||||
nextButton.setEnabled(value.booleanValue());
|
||||
fastNextButton.setEnabled(value.booleanValue());
|
||||
fastPrevButton.setEnabled(value.booleanValue());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Collection getFocusableComponents() {
|
||||
return focusableComponents;
|
||||
}
|
||||
public Collection getFocusableComponents() {
|
||||
return focusableComponents;
|
||||
}
|
||||
|
||||
public void addMonth(int m) {
|
||||
int modM = m > 0 ? m : -m;
|
||||
int sign = m > 0 ? 1 : -1;
|
||||
Date old = calendar.getTime();
|
||||
for (int i = 0; i < modM; i++) {
|
||||
calendar.add(Calendar.MONTH, sign);
|
||||
}
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, getDate());
|
||||
reflectData();
|
||||
public void addMonth(int m) {
|
||||
int modM = m > 0 ? m : -m;
|
||||
int sign = m > 0 ? 1 : -1;
|
||||
Date old = calendar.getTime();
|
||||
for (int i = 0; i < modM; i++) {
|
||||
calendar.add(Calendar.MONTH, sign);
|
||||
}
|
||||
firePropertyChange(PROPERTY_NAME_DATE, old, getDate());
|
||||
reflectData();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,149 +18,149 @@ import javax.swing.JPanel;
|
||||
|
||||
class ModernCalendarPanel extends JPanel implements PropertyChangeListener {
|
||||
|
||||
public static final String PROPERTY_NAME_DATE = "date";
|
||||
public static final String PROPERTY_NAME_DATE = "date";
|
||||
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
|
||||
public static final String PROPERTY_NAME_ZONE = "zone";
|
||||
public static final String PROPERTY_NAME_ZONE = "zone";
|
||||
|
||||
private Date date;
|
||||
private Date date;
|
||||
|
||||
private Locale locale;
|
||||
private Locale locale;
|
||||
|
||||
private TimeZone zone;
|
||||
private TimeZone zone;
|
||||
|
||||
private YearSpinnerModel yearSpinnerModel;
|
||||
private YearSpinnerModel yearSpinnerModel;
|
||||
|
||||
private NoGroupingSpinner yearSpinner;
|
||||
private NoGroupingSpinner yearSpinner;
|
||||
|
||||
private MonthComboBoxModel monthComboBoxModel;
|
||||
private MonthComboBoxModel monthComboBoxModel;
|
||||
|
||||
private MonthComboBoxRenderer monthComboBoxRenderer;
|
||||
private MonthComboBoxRenderer monthComboBoxRenderer;
|
||||
|
||||
private JComboBox monthCombo;
|
||||
private JComboBox monthCombo;
|
||||
|
||||
private Set focusableComponents = new HashSet();
|
||||
private Set focusableComponents = new HashSet();
|
||||
|
||||
public ModernCalendarPanel(Date aDate, Locale aLocale, TimeZone zone) {
|
||||
this.date = aDate;
|
||||
this.locale = aLocale;
|
||||
this.zone = zone;
|
||||
public ModernCalendarPanel(Date aDate, Locale aLocale, TimeZone zone) {
|
||||
this.date = aDate;
|
||||
this.locale = aLocale;
|
||||
this.zone = zone;
|
||||
|
||||
monthComboBoxModel = new MonthComboBoxModel(aDate, aLocale, zone);
|
||||
monthComboBoxRenderer = new MonthComboBoxRenderer(aLocale, zone);
|
||||
monthCombo = new JComboBox(monthComboBoxModel);
|
||||
monthComboBoxModel = new MonthComboBoxModel(aDate, aLocale, zone);
|
||||
monthComboBoxRenderer = new MonthComboBoxRenderer(aLocale, zone);
|
||||
monthCombo = new JComboBox(monthComboBoxModel);
|
||||
|
||||
monthCombo.setRenderer(monthComboBoxRenderer);
|
||||
monthCombo.setRenderer(monthComboBoxRenderer);
|
||||
|
||||
yearSpinnerModel = new YearSpinnerModel(aDate, aLocale, zone);
|
||||
yearSpinner = new NoGroupingSpinner(yearSpinnerModel);
|
||||
yearSpinnerModel = new YearSpinnerModel(aDate, aLocale, zone);
|
||||
yearSpinner = new NoGroupingSpinner(yearSpinnerModel);
|
||||
|
||||
setLayout(new GridBagLayout());
|
||||
add(monthCombo, new GridBagConstraints(0, 0, 1, 1, 1.0, 0,
|
||||
GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0,
|
||||
0, 3, 0), 0, 0));
|
||||
add(yearSpinner, new GridBagConstraints(1, 0, 1, 1, 0, 0,
|
||||
GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
|
||||
new Insets(0, 3, 3, 0), 0, 0));
|
||||
setLayout(new GridBagLayout());
|
||||
add(monthCombo, new GridBagConstraints(0, 0, 1, 1, 1.0, 0,
|
||||
GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0,
|
||||
0, 3, 0), 0, 0));
|
||||
add(yearSpinner, new GridBagConstraints(1, 0, 1, 1, 0, 0,
|
||||
GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
|
||||
new Insets(0, 3, 3, 0), 0, 0));
|
||||
|
||||
focusableComponents.add(yearSpinner);
|
||||
focusableComponents.add(monthCombo);
|
||||
focusableComponents.add(yearSpinner);
|
||||
focusableComponents.add(monthCombo);
|
||||
|
||||
monthComboBoxModel
|
||||
.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
monthComboBoxModel
|
||||
.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals(
|
||||
MonthComboBoxModel.PROPERTY_NAME_DATE)) {
|
||||
Date newDate = (Date) evt.getNewValue();
|
||||
setDate(newDate);
|
||||
}
|
||||
}
|
||||
});
|
||||
yearSpinnerModel
|
||||
.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals(
|
||||
MonthComboBoxModel.PROPERTY_NAME_DATE)) {
|
||||
Date newDate = (Date) evt.getNewValue();
|
||||
setDate(newDate);
|
||||
}
|
||||
}
|
||||
});
|
||||
yearSpinnerModel
|
||||
.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals(
|
||||
YearSpinnerModel.PROPERTY_NAME_DATE)) {
|
||||
Date newDate = (Date) evt.getNewValue();
|
||||
setDate(newDate);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.addPropertyChangeListener(this);
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals(
|
||||
YearSpinnerModel.PROPERTY_NAME_DATE)) {
|
||||
Date newDate = (Date) evt.getNewValue();
|
||||
setDate(newDate);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.addPropertyChangeListener(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
monthCombo.setEnabled(enabled);
|
||||
yearSpinner.setEnabled(enabled);
|
||||
}
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
monthCombo.setEnabled(enabled);
|
||||
yearSpinner.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void setFocusable(boolean focusable) {
|
||||
super.setFocusable(focusable);
|
||||
monthCombo.setFocusable(focusable);
|
||||
yearSpinner.setFocusable(focusable);
|
||||
}
|
||||
public void setFocusable(boolean focusable) {
|
||||
super.setFocusable(focusable);
|
||||
monthCombo.setFocusable(focusable);
|
||||
yearSpinner.setFocusable(focusable);
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
Date oldDate = this.date;
|
||||
this.date = date;
|
||||
firePropertyChange(PROPERTY_NAME_DATE, oldDate, date);
|
||||
monthComboBoxModel.setDate(date);
|
||||
yearSpinnerModel.setDate(date);
|
||||
}
|
||||
public void setDate(Date date) {
|
||||
Date oldDate = this.date;
|
||||
this.date = date;
|
||||
firePropertyChange(PROPERTY_NAME_DATE, oldDate, date);
|
||||
monthComboBoxModel.setDate(date);
|
||||
yearSpinnerModel.setDate(date);
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
Locale old = this.locale;
|
||||
this.locale = locale;
|
||||
monthComboBoxRenderer.setLocale(locale);
|
||||
monthComboBoxModel.setLocale(locale);
|
||||
yearSpinnerModel.setLocale(locale);
|
||||
firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
}
|
||||
public void setLocale(Locale locale) {
|
||||
Locale old = this.locale;
|
||||
this.locale = locale;
|
||||
monthComboBoxRenderer.setLocale(locale);
|
||||
monthComboBoxModel.setLocale(locale);
|
||||
yearSpinnerModel.setLocale(locale);
|
||||
firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
}
|
||||
|
||||
public Collection getFocusableComponents() {
|
||||
return focusableComponents;
|
||||
}
|
||||
public Collection getFocusableComponents() {
|
||||
return focusableComponents;
|
||||
}
|
||||
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public void setZone(TimeZone zone) {
|
||||
TimeZone old = this.zone;
|
||||
this.zone = zone;
|
||||
monthComboBoxRenderer.setZone(zone);
|
||||
monthComboBoxModel.setZone(zone);
|
||||
yearSpinnerModel.setZone(zone);
|
||||
firePropertyChange(PROPERTY_NAME_ZONE, old, zone);
|
||||
}
|
||||
public void setZone(TimeZone zone) {
|
||||
TimeZone old = this.zone;
|
||||
this.zone = zone;
|
||||
monthComboBoxRenderer.setZone(zone);
|
||||
monthComboBoxModel.setZone(zone);
|
||||
yearSpinnerModel.setZone(zone);
|
||||
firePropertyChange(PROPERTY_NAME_ZONE, old, zone);
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals("focusable")) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
yearSpinner.setFocusable(value);
|
||||
Component children[] = yearSpinner.getEditor().getComponents();
|
||||
for (int i = 0; i < children.length; i++)
|
||||
children[i].setFocusable(value);
|
||||
monthCombo.setFocusable(value);
|
||||
}
|
||||
if (evt.getPropertyName().equals("enabled")) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
yearSpinner.setEnabled(value);
|
||||
monthCombo.setEnabled(value);
|
||||
}
|
||||
}
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals("focusable")) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
yearSpinner.setFocusable(value);
|
||||
Component children[] = yearSpinner.getEditor().getComponents();
|
||||
for (int i = 0; i < children.length; i++)
|
||||
children[i].setFocusable(value);
|
||||
monthCombo.setFocusable(value);
|
||||
}
|
||||
if (evt.getPropertyName().equals("enabled")) {
|
||||
boolean value = ((Boolean) evt.getNewValue()).booleanValue();
|
||||
yearSpinner.setEnabled(value);
|
||||
monthCombo.setEnabled(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,125 +11,125 @@ import javax.swing.AbstractListModel;
|
||||
import javax.swing.ComboBoxModel;
|
||||
|
||||
class MonthComboBoxModel extends AbstractListModel implements
|
||||
ComboBoxModel {
|
||||
ComboBoxModel {
|
||||
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
|
||||
public static final String PROPERTY_NAME_DATE = "date";
|
||||
public static final String PROPERTY_NAME_DATE = "date";
|
||||
|
||||
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
|
||||
this);
|
||||
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
|
||||
this);
|
||||
|
||||
private Calendar calendar;
|
||||
private Calendar calendar;
|
||||
|
||||
private Locale locale;
|
||||
private Locale locale;
|
||||
|
||||
private TimeZone zone;
|
||||
private TimeZone zone;
|
||||
|
||||
public MonthComboBoxModel(Date date, Locale locale, TimeZone zone) {
|
||||
super();
|
||||
this.locale = locale;
|
||||
this.zone = zone;
|
||||
public MonthComboBoxModel(Date date, Locale locale, TimeZone zone) {
|
||||
super();
|
||||
this.locale = locale;
|
||||
this.zone = zone;
|
||||
|
||||
createLocaleAndZoneSensitive();
|
||||
calendar.setTime(date);
|
||||
}
|
||||
createLocaleAndZoneSensitive();
|
||||
calendar.setTime(date);
|
||||
}
|
||||
|
||||
private void createLocaleAndZoneSensitive() {
|
||||
if (calendar != null) {
|
||||
Date old = calendar.getTime();
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
calendar.setTime(old);
|
||||
} else
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
}
|
||||
private void createLocaleAndZoneSensitive() {
|
||||
if (calendar != null) {
|
||||
Date old = calendar.getTime();
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
calendar.setTime(old);
|
||||
} else
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
Locale old = this.locale;
|
||||
this.locale = locale;
|
||||
createLocaleAndZoneSensitive();
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
fireContentsChanged(this, 0, getSize() - 1);
|
||||
}
|
||||
public void setLocale(Locale locale) {
|
||||
Locale old = this.locale;
|
||||
this.locale = locale;
|
||||
createLocaleAndZoneSensitive();
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
fireContentsChanged(this, 0, getSize() - 1);
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return calendar.getTime();
|
||||
}
|
||||
public Date getDate() {
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
Date old = getDate();
|
||||
calendar.setTime(date);
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_DATE, old, date);
|
||||
fireContentsChanged(this, 0, getSize() - 1);
|
||||
}
|
||||
public void setDate(Date date) {
|
||||
Date old = getDate();
|
||||
calendar.setTime(date);
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_DATE, old, date);
|
||||
fireContentsChanged(this, 0, getSize() - 1);
|
||||
}
|
||||
|
||||
public void setSelectedItem(Object anItem) {
|
||||
Date aDate = (Date) anItem;
|
||||
setDate(aDate);
|
||||
}
|
||||
public void setSelectedItem(Object anItem) {
|
||||
Date aDate = (Date) anItem;
|
||||
setDate(aDate);
|
||||
}
|
||||
|
||||
public Object getSelectedItem() {
|
||||
return calendar.getTime();
|
||||
}
|
||||
public Object getSelectedItem() {
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return calendar.getActualMaximum(Calendar.MONTH) + 1;
|
||||
}
|
||||
public int getSize() {
|
||||
return calendar.getActualMaximum(Calendar.MONTH) + 1;
|
||||
}
|
||||
|
||||
public Object getElementAt(int index) {
|
||||
Calendar c = Calendar.getInstance(locale);
|
||||
c.setTime(calendar.getTime());
|
||||
public Object getElementAt(int index) {
|
||||
Calendar c = Calendar.getInstance(locale);
|
||||
c.setTime(calendar.getTime());
|
||||
|
||||
c.set(Calendar.MONTH, 0);
|
||||
for (int i = 0; i < index; i++)
|
||||
c.add(Calendar.MONTH, 1);
|
||||
c.set(Calendar.MONTH, 0);
|
||||
for (int i = 0; i < index; i++)
|
||||
c.add(Calendar.MONTH, 1);
|
||||
|
||||
return c.getTime();
|
||||
}
|
||||
return c.getTime();
|
||||
}
|
||||
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public void setZone(TimeZone zone) {
|
||||
this.zone = zone;
|
||||
createLocaleAndZoneSensitive();
|
||||
fireContentsChanged(this, 0, getSize() - 1);
|
||||
}
|
||||
public void setZone(TimeZone zone) {
|
||||
this.zone = zone;
|
||||
createLocaleAndZoneSensitive();
|
||||
fireContentsChanged(this, 0, getSize() - 1);
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
changeSupport.addPropertyChangeListener(listener);
|
||||
}
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
changeSupport.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener) {
|
||||
changeSupport.addPropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
public void addPropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener) {
|
||||
changeSupport.addPropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
|
||||
public PropertyChangeListener[] getPropertyChangeListeners() {
|
||||
return changeSupport.getPropertyChangeListeners();
|
||||
}
|
||||
public PropertyChangeListener[] getPropertyChangeListeners() {
|
||||
return changeSupport.getPropertyChangeListeners();
|
||||
}
|
||||
|
||||
public PropertyChangeListener[] getPropertyChangeListeners(
|
||||
String propertyName) {
|
||||
return changeSupport.getPropertyChangeListeners(propertyName);
|
||||
}
|
||||
public PropertyChangeListener[] getPropertyChangeListeners(
|
||||
String propertyName) {
|
||||
return changeSupport.getPropertyChangeListeners(propertyName);
|
||||
}
|
||||
|
||||
public boolean hasListeners(String propertyName) {
|
||||
return changeSupport.hasListeners(propertyName);
|
||||
}
|
||||
public boolean hasListeners(String propertyName) {
|
||||
return changeSupport.hasListeners(propertyName);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
changeSupport.removePropertyChangeListener(listener);
|
||||
}
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
changeSupport.removePropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener) {
|
||||
changeSupport.removePropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
public void removePropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener) {
|
||||
changeSupport.removePropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,47 +11,47 @@ import javax.swing.JList;
|
||||
|
||||
class MonthComboBoxRenderer extends DefaultListCellRenderer {
|
||||
|
||||
// private Locale locale;
|
||||
// private Locale locale;
|
||||
|
||||
private TimeZone zone;
|
||||
private TimeZone zone;
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat dateFormat;
|
||||
|
||||
public MonthComboBoxRenderer(Locale locale, TimeZone zone) {
|
||||
// this.locale = locale;
|
||||
this.zone = zone;
|
||||
dateFormat = new SimpleDateFormat("MMMM", locale);
|
||||
dateFormat.setTimeZone(zone);
|
||||
}
|
||||
public MonthComboBoxRenderer(Locale locale, TimeZone zone) {
|
||||
// this.locale = locale;
|
||||
this.zone = zone;
|
||||
dateFormat = new SimpleDateFormat("MMMM", locale);
|
||||
dateFormat.setTimeZone(zone);
|
||||
}
|
||||
|
||||
public Component getListCellRendererComponent(JList list, Object value,
|
||||
int index, boolean isSelected, boolean cellHasFocus) {
|
||||
super.getListCellRendererComponent(list, value, index, isSelected,
|
||||
cellHasFocus);
|
||||
public Component getListCellRendererComponent(JList list, Object value,
|
||||
int index, boolean isSelected, boolean cellHasFocus) {
|
||||
super.getListCellRendererComponent(list, value, index, isSelected,
|
||||
cellHasFocus);
|
||||
|
||||
Date date = (Date) value;
|
||||
setText(dateFormat.format(date));
|
||||
Date date = (Date) value;
|
||||
setText(dateFormat.format(date));
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
// this.locale = locale;
|
||||
dateFormat = new SimpleDateFormat("MMMM", locale);
|
||||
dateFormat.setTimeZone(zone);
|
||||
}
|
||||
public void setLocale(Locale locale) {
|
||||
// this.locale = locale;
|
||||
dateFormat = new SimpleDateFormat("MMMM", locale);
|
||||
dateFormat.setTimeZone(zone);
|
||||
}
|
||||
|
||||
public void setZone(TimeZone zone) {
|
||||
this.zone = zone;
|
||||
dateFormat.setTimeZone(zone);
|
||||
}
|
||||
public void setZone(TimeZone zone) {
|
||||
this.zone = zone;
|
||||
dateFormat.setTimeZone(zone);
|
||||
}
|
||||
|
||||
// public Locale getLocale() {
|
||||
// return locale;
|
||||
// }
|
||||
//
|
||||
// public TimeZone getZone() {
|
||||
// return zone;
|
||||
// }
|
||||
// public Locale getLocale() {
|
||||
// return locale;
|
||||
// }
|
||||
//
|
||||
// public TimeZone getZone() {
|
||||
// return zone;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -12,30 +12,30 @@ import javax.swing.text.NumberFormatter;
|
||||
|
||||
class NoGroupingSpinner extends JSpinner {
|
||||
|
||||
public static class NoGroupingNumberEditor extends NumberEditor {
|
||||
public static class NoGroupingNumberEditor extends NumberEditor {
|
||||
|
||||
public NoGroupingNumberEditor(JSpinner spinner, SpinnerModel model) {
|
||||
super(spinner);
|
||||
JFormattedTextField ftf = (JFormattedTextField) this
|
||||
.getComponent(0);
|
||||
NumberFormat fmt = NumberFormat.getIntegerInstance();
|
||||
fmt.setGroupingUsed(false);
|
||||
ftf.setFormatterFactory(new DefaultFormatterFactory(
|
||||
new NumberFormatter(fmt)));
|
||||
revalidate();
|
||||
}
|
||||
public NoGroupingNumberEditor(JSpinner spinner, SpinnerModel model) {
|
||||
super(spinner);
|
||||
JFormattedTextField ftf = (JFormattedTextField) this
|
||||
.getComponent(0);
|
||||
NumberFormat fmt = NumberFormat.getIntegerInstance();
|
||||
fmt.setGroupingUsed(false);
|
||||
ftf.setFormatterFactory(new DefaultFormatterFactory(
|
||||
new NumberFormatter(fmt)));
|
||||
revalidate();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public NoGroupingSpinner(SpinnerModel spinnerModel) {
|
||||
super(spinnerModel);
|
||||
}
|
||||
public NoGroupingSpinner(SpinnerModel spinnerModel) {
|
||||
super(spinnerModel);
|
||||
}
|
||||
|
||||
protected JComponent createEditor(SpinnerModel model) {
|
||||
if (model instanceof SpinnerNumberModel)
|
||||
return new NoGroupingNumberEditor(this, model);
|
||||
protected JComponent createEditor(SpinnerModel model) {
|
||||
if (model instanceof SpinnerNumberModel)
|
||||
return new NoGroupingNumberEditor(this, model);
|
||||
|
||||
return super.createEditor(model);
|
||||
}
|
||||
return super.createEditor(model);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,148 +11,148 @@ import javax.swing.SpinnerNumberModel;
|
||||
|
||||
class YearSpinnerModel extends SpinnerNumberModel {
|
||||
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
public static final String PROPERTY_NAME_LOCALE = "locale";
|
||||
|
||||
public static final String PROPERTY_NAME_DATE = "date";
|
||||
public static final String PROPERTY_NAME_DATE = "date";
|
||||
|
||||
public static final String PROPERTY_NAME_ZONE = "zone";
|
||||
public static final String PROPERTY_NAME_ZONE = "zone";
|
||||
|
||||
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
|
||||
this);
|
||||
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
|
||||
this);
|
||||
|
||||
private Locale locale;
|
||||
private Locale locale;
|
||||
|
||||
private TimeZone zone;
|
||||
private TimeZone zone;
|
||||
|
||||
private Calendar calendar;
|
||||
private Calendar calendar;
|
||||
|
||||
public YearSpinnerModel(Date date, Locale locale, TimeZone zone) {
|
||||
this.locale = locale;
|
||||
this.zone = zone;
|
||||
createLocaleAndZoneSensitive();
|
||||
calendar.setTime(date);
|
||||
}
|
||||
public YearSpinnerModel(Date date, Locale locale, TimeZone zone) {
|
||||
this.locale = locale;
|
||||
this.zone = zone;
|
||||
createLocaleAndZoneSensitive();
|
||||
calendar.setTime(date);
|
||||
}
|
||||
|
||||
private void createLocaleAndZoneSensitive() {
|
||||
if (calendar != null) {
|
||||
Date old = calendar.getTime();
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
calendar.setTime(old);
|
||||
} else
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
}
|
||||
private void createLocaleAndZoneSensitive() {
|
||||
if (calendar != null) {
|
||||
Date old = calendar.getTime();
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
calendar.setTime(old);
|
||||
} else
|
||||
calendar = Calendar.getInstance(zone, locale);
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return new Integer(calendar.get(Calendar.YEAR));
|
||||
}
|
||||
public Object getValue() {
|
||||
return new Integer(calendar.get(Calendar.YEAR));
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
Number newVal = (Number) value;
|
||||
Number oldVal = (Number) getValue();
|
||||
if (oldVal.longValue() != newVal.longValue()) {
|
||||
public void setValue(Object value) {
|
||||
Number newVal = (Number) value;
|
||||
Number oldVal = (Number) getValue();
|
||||
if (oldVal.longValue() != newVal.longValue()) {
|
||||
|
||||
int diff = newVal.intValue() - oldVal.intValue();
|
||||
int sign = diff > 0 ? 1 : -1;
|
||||
if (diff < 0)
|
||||
diff = -diff;
|
||||
Date oldDate = calendar.getTime();
|
||||
int diff = newVal.intValue() - oldVal.intValue();
|
||||
int sign = diff > 0 ? 1 : -1;
|
||||
if (diff < 0)
|
||||
diff = -diff;
|
||||
Date oldDate = calendar.getTime();
|
||||
|
||||
for (int i = 0; i < diff; i++)
|
||||
calendar.add(Calendar.YEAR, sign);
|
||||
for (int i = 0; i < diff; i++)
|
||||
calendar.add(Calendar.YEAR, sign);
|
||||
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_DATE, oldDate,
|
||||
getDate());
|
||||
fireStateChanged();
|
||||
}
|
||||
}
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_DATE, oldDate,
|
||||
getDate());
|
||||
fireStateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Object getNextValue() {
|
||||
public Object getNextValue() {
|
||||
|
||||
Integer currVal = (Integer) getValue();
|
||||
int newVal = currVal.intValue() + 1;
|
||||
Integer currVal = (Integer) getValue();
|
||||
int newVal = currVal.intValue() + 1;
|
||||
|
||||
if (newVal <= calendar.getActualMaximum(Calendar.YEAR))
|
||||
return new Integer(newVal);
|
||||
if (newVal <= calendar.getActualMaximum(Calendar.YEAR))
|
||||
return new Integer(newVal);
|
||||
|
||||
return currVal;
|
||||
}
|
||||
return currVal;
|
||||
}
|
||||
|
||||
public Object getPreviousValue() {
|
||||
Integer currVal = (Integer) getValue();
|
||||
int newVal = currVal.intValue() - 1;
|
||||
public Object getPreviousValue() {
|
||||
Integer currVal = (Integer) getValue();
|
||||
int newVal = currVal.intValue() - 1;
|
||||
|
||||
if (newVal >= calendar.getActualMinimum(Calendar.YEAR))
|
||||
return new Integer(newVal);
|
||||
if (newVal >= calendar.getActualMinimum(Calendar.YEAR))
|
||||
return new Integer(newVal);
|
||||
|
||||
return currVal;
|
||||
}
|
||||
return currVal;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return calendar.getTime();
|
||||
}
|
||||
public Date getDate() {
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
Date old = calendar.getTime();
|
||||
if (!old.equals(date)) {
|
||||
calendar.setTime(date);
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_DATE, old, date);
|
||||
fireStateChanged();
|
||||
}
|
||||
}
|
||||
public void setDate(Date date) {
|
||||
Date old = calendar.getTime();
|
||||
if (!old.equals(date)) {
|
||||
calendar.setTime(date);
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_DATE, old, date);
|
||||
fireStateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
Locale old = this.locale;
|
||||
this.locale = locale;
|
||||
createLocaleAndZoneSensitive();
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
fireStateChanged();
|
||||
}
|
||||
public void setLocale(Locale locale) {
|
||||
Locale old = this.locale;
|
||||
this.locale = locale;
|
||||
createLocaleAndZoneSensitive();
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
fireStateChanged();
|
||||
}
|
||||
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
public TimeZone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public void setZone(TimeZone zone) {
|
||||
TimeZone old = this.zone;
|
||||
this.zone = zone;
|
||||
createLocaleAndZoneSensitive();
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
fireStateChanged();
|
||||
}
|
||||
public void setZone(TimeZone zone) {
|
||||
TimeZone old = this.zone;
|
||||
this.zone = zone;
|
||||
createLocaleAndZoneSensitive();
|
||||
changeSupport.firePropertyChange(PROPERTY_NAME_LOCALE, old, locale);
|
||||
fireStateChanged();
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
changeSupport.addPropertyChangeListener(listener);
|
||||
}
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
changeSupport.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener) {
|
||||
changeSupport.addPropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
public void addPropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener) {
|
||||
changeSupport.addPropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
changeSupport.removePropertyChangeListener(listener);
|
||||
}
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
changeSupport.removePropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener) {
|
||||
changeSupport.removePropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
public void removePropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener) {
|
||||
changeSupport.removePropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
|
||||
public PropertyChangeListener[] getPropertyChangeListeners() {
|
||||
return changeSupport.getPropertyChangeListeners();
|
||||
}
|
||||
public PropertyChangeListener[] getPropertyChangeListeners() {
|
||||
return changeSupport.getPropertyChangeListeners();
|
||||
}
|
||||
|
||||
public PropertyChangeListener[] getPropertyChangeListeners(
|
||||
String propertyName) {
|
||||
return changeSupport.getPropertyChangeListeners(propertyName);
|
||||
}
|
||||
public PropertyChangeListener[] getPropertyChangeListeners(
|
||||
String propertyName) {
|
||||
return changeSupport.getPropertyChangeListeners(propertyName);
|
||||
}
|
||||
|
||||
public boolean hasListeners(String propertyName) {
|
||||
return changeSupport.hasListeners(propertyName);
|
||||
}
|
||||
public boolean hasListeners(String propertyName) {
|
||||
return changeSupport.hasListeners(propertyName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,52 +13,52 @@ import javax.swing.table.AbstractTableModel;
|
||||
* @author Michael Baranov
|
||||
*/
|
||||
public abstract class AbstractBoundedTableModel extends AbstractTableModel
|
||||
implements BoundedTableModel {
|
||||
|
||||
private PropertyChangeSupport propertySupport=new PropertyChangeSupport(this);
|
||||
implements BoundedTableModel {
|
||||
|
||||
private PropertyChangeSupport propertySupport=new PropertyChangeSupport(this);
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
propertySupport.addPropertyChangeListener(listener);
|
||||
}
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
propertySupport.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
|
||||
propertySupport.addPropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
|
||||
propertySupport.addPropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
|
||||
public void firePropertyChange(PropertyChangeEvent evt) {
|
||||
propertySupport.firePropertyChange(evt);
|
||||
}
|
||||
public void firePropertyChange(PropertyChangeEvent evt) {
|
||||
propertySupport.firePropertyChange(evt);
|
||||
}
|
||||
|
||||
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
|
||||
propertySupport.firePropertyChange(propertyName, oldValue, newValue);
|
||||
}
|
||||
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
|
||||
propertySupport.firePropertyChange(propertyName, oldValue, newValue);
|
||||
}
|
||||
|
||||
public void firePropertyChange(String propertyName, int oldValue, int newValue) {
|
||||
propertySupport.firePropertyChange(propertyName, oldValue, newValue);
|
||||
}
|
||||
public void firePropertyChange(String propertyName, int oldValue, int newValue) {
|
||||
propertySupport.firePropertyChange(propertyName, oldValue, newValue);
|
||||
}
|
||||
|
||||
public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
|
||||
propertySupport.firePropertyChange(propertyName, oldValue, newValue);
|
||||
}
|
||||
public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
|
||||
propertySupport.firePropertyChange(propertyName, oldValue, newValue);
|
||||
}
|
||||
|
||||
public PropertyChangeListener[] getPropertyChangeListeners() {
|
||||
return propertySupport.getPropertyChangeListeners();
|
||||
}
|
||||
public PropertyChangeListener[] getPropertyChangeListeners() {
|
||||
return propertySupport.getPropertyChangeListeners();
|
||||
}
|
||||
|
||||
public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
|
||||
return propertySupport.getPropertyChangeListeners(propertyName);
|
||||
}
|
||||
public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
|
||||
return propertySupport.getPropertyChangeListeners(propertyName);
|
||||
}
|
||||
|
||||
public boolean hasListeners(String propertyName) {
|
||||
return propertySupport.hasListeners(propertyName);
|
||||
}
|
||||
public boolean hasListeners(String propertyName) {
|
||||
return propertySupport.hasListeners(propertyName);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
propertySupport.removePropertyChangeListener(listener);
|
||||
}
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
propertySupport.removePropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
|
||||
propertySupport.removePropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
|
||||
propertySupport.removePropertyChangeListener(propertyName, listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,114 +15,114 @@ import javax.swing.event.ListSelectionListener;
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractBoundedTableModelWithSelection extends
|
||||
AbstractBoundedTableModel implements ListSelectionModel {
|
||||
AbstractBoundedTableModel implements ListSelectionModel {
|
||||
|
||||
private DefaultListSelectionModel selection = new DefaultListSelectionModel();
|
||||
private DefaultListSelectionModel selection = new DefaultListSelectionModel();
|
||||
|
||||
public AbstractBoundedTableModelWithSelection() {
|
||||
super();
|
||||
}
|
||||
public AbstractBoundedTableModelWithSelection() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void addListSelectionListener(ListSelectionListener l) {
|
||||
selection.addListSelectionListener(l);
|
||||
}
|
||||
public void addListSelectionListener(ListSelectionListener l) {
|
||||
selection.addListSelectionListener(l);
|
||||
}
|
||||
|
||||
public void addSelectionInterval(int index0, int index1) {
|
||||
selection.addSelectionInterval(index0, index1);
|
||||
}
|
||||
public void addSelectionInterval(int index0, int index1) {
|
||||
selection.addSelectionInterval(index0, index1);
|
||||
}
|
||||
|
||||
public void clearSelection() {
|
||||
selection.clearSelection();
|
||||
}
|
||||
public void clearSelection() {
|
||||
selection.clearSelection();
|
||||
}
|
||||
|
||||
public int getAnchorSelectionIndex() {
|
||||
return selection.getAnchorSelectionIndex();
|
||||
}
|
||||
public int getAnchorSelectionIndex() {
|
||||
return selection.getAnchorSelectionIndex();
|
||||
}
|
||||
|
||||
public int getLeadSelectionIndex() {
|
||||
return selection.getLeadSelectionIndex();
|
||||
}
|
||||
public int getLeadSelectionIndex() {
|
||||
return selection.getLeadSelectionIndex();
|
||||
}
|
||||
|
||||
public EventListener[] getListeners(Class listenerType) {
|
||||
return selection.getListeners(listenerType);
|
||||
}
|
||||
public EventListener[] getListeners(Class listenerType) {
|
||||
return selection.getListeners(listenerType);
|
||||
}
|
||||
|
||||
public ListSelectionListener[] getListSelectionListeners() {
|
||||
return selection.getListSelectionListeners();
|
||||
}
|
||||
public ListSelectionListener[] getListSelectionListeners() {
|
||||
return selection.getListSelectionListeners();
|
||||
}
|
||||
|
||||
public int getMaxSelectionIndex() {
|
||||
return selection.getMaxSelectionIndex();
|
||||
}
|
||||
public int getMaxSelectionIndex() {
|
||||
return selection.getMaxSelectionIndex();
|
||||
}
|
||||
|
||||
public int getMinSelectionIndex() {
|
||||
return selection.getMinSelectionIndex();
|
||||
}
|
||||
public int getMinSelectionIndex() {
|
||||
return selection.getMinSelectionIndex();
|
||||
}
|
||||
|
||||
public int getSelectionMode() {
|
||||
return selection.getSelectionMode();
|
||||
}
|
||||
public int getSelectionMode() {
|
||||
return selection.getSelectionMode();
|
||||
}
|
||||
|
||||
public boolean getValueIsAdjusting() {
|
||||
return selection.getValueIsAdjusting();
|
||||
}
|
||||
public boolean getValueIsAdjusting() {
|
||||
return selection.getValueIsAdjusting();
|
||||
}
|
||||
|
||||
public void insertIndexInterval(int index, int length, boolean before) {
|
||||
selection.insertIndexInterval(index, length, before);
|
||||
}
|
||||
public void insertIndexInterval(int index, int length, boolean before) {
|
||||
selection.insertIndexInterval(index, length, before);
|
||||
}
|
||||
|
||||
public boolean isLeadAnchorNotificationEnabled() {
|
||||
return selection.isLeadAnchorNotificationEnabled();
|
||||
}
|
||||
public boolean isLeadAnchorNotificationEnabled() {
|
||||
return selection.isLeadAnchorNotificationEnabled();
|
||||
}
|
||||
|
||||
public boolean isSelectedIndex(int index) {
|
||||
return selection.isSelectedIndex(index);
|
||||
}
|
||||
public boolean isSelectedIndex(int index) {
|
||||
return selection.isSelectedIndex(index);
|
||||
}
|
||||
|
||||
public boolean isSelectionEmpty() {
|
||||
return selection.isSelectionEmpty();
|
||||
}
|
||||
public boolean isSelectionEmpty() {
|
||||
return selection.isSelectionEmpty();
|
||||
}
|
||||
|
||||
// J2SE5
|
||||
// ////////////////////////////////////////////////////
|
||||
// public void moveLeadSelectionIndex(int leadIndex) {
|
||||
// selection.moveLeadSelectionIndex(leadIndex);
|
||||
// }
|
||||
// J2SE5
|
||||
// ////////////////////////////////////////////////////
|
||||
// public void moveLeadSelectionIndex(int leadIndex) {
|
||||
// selection.moveLeadSelectionIndex(leadIndex);
|
||||
// }
|
||||
|
||||
public void removeIndexInterval(int index0, int index1) {
|
||||
selection.removeIndexInterval(index0, index1);
|
||||
}
|
||||
public void removeIndexInterval(int index0, int index1) {
|
||||
selection.removeIndexInterval(index0, index1);
|
||||
}
|
||||
|
||||
public void removeListSelectionListener(ListSelectionListener l) {
|
||||
selection.removeListSelectionListener(l);
|
||||
}
|
||||
public void removeListSelectionListener(ListSelectionListener l) {
|
||||
selection.removeListSelectionListener(l);
|
||||
}
|
||||
|
||||
public void removeSelectionInterval(int index0, int index1) {
|
||||
selection.removeSelectionInterval(index0, index1);
|
||||
}
|
||||
public void removeSelectionInterval(int index0, int index1) {
|
||||
selection.removeSelectionInterval(index0, index1);
|
||||
}
|
||||
|
||||
public void setAnchorSelectionIndex(int anchorIndex) {
|
||||
selection.setAnchorSelectionIndex(anchorIndex);
|
||||
}
|
||||
public void setAnchorSelectionIndex(int anchorIndex) {
|
||||
selection.setAnchorSelectionIndex(anchorIndex);
|
||||
}
|
||||
|
||||
public void setLeadAnchorNotificationEnabled(boolean flag) {
|
||||
selection.setLeadAnchorNotificationEnabled(flag);
|
||||
}
|
||||
public void setLeadAnchorNotificationEnabled(boolean flag) {
|
||||
selection.setLeadAnchorNotificationEnabled(flag);
|
||||
}
|
||||
|
||||
public void setLeadSelectionIndex(int leadIndex) {
|
||||
selection.setLeadSelectionIndex(leadIndex);
|
||||
}
|
||||
public void setLeadSelectionIndex(int leadIndex) {
|
||||
selection.setLeadSelectionIndex(leadIndex);
|
||||
}
|
||||
|
||||
public void setSelectionInterval(int index0, int index1) {
|
||||
selection.setSelectionInterval(index0, index1);
|
||||
}
|
||||
public void setSelectionInterval(int index0, int index1) {
|
||||
selection.setSelectionInterval(index0, index1);
|
||||
}
|
||||
|
||||
public void setSelectionMode(int selectionMode) {
|
||||
selection.setSelectionMode(selectionMode);
|
||||
}
|
||||
public void setSelectionMode(int selectionMode) {
|
||||
selection.setSelectionMode(selectionMode);
|
||||
}
|
||||
|
||||
public void setValueIsAdjusting(boolean isAdjusting) {
|
||||
selection.setValueIsAdjusting(isAdjusting);
|
||||
}
|
||||
public void setValueIsAdjusting(boolean isAdjusting) {
|
||||
selection.setValueIsAdjusting(isAdjusting);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,27 +10,27 @@ import javax.swing.event.EventListenerList;
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractPolicy implements Policy {
|
||||
private EventListenerList vetoPolicyListenerList = new EventListenerList();
|
||||
private EventListenerList vetoPolicyListenerList = new EventListenerList();
|
||||
|
||||
public void addVetoPolicyListener(PolicyListener listener) {
|
||||
vetoPolicyListenerList.add(PolicyListener.class, listener);
|
||||
}
|
||||
public void addVetoPolicyListener(PolicyListener listener) {
|
||||
vetoPolicyListenerList.add(PolicyListener.class, listener);
|
||||
}
|
||||
|
||||
public void removeVetoPolicyListener(PolicyListener listener) {
|
||||
vetoPolicyListenerList.remove(PolicyListener.class, listener);
|
||||
public void removeVetoPolicyListener(PolicyListener listener) {
|
||||
vetoPolicyListenerList.remove(PolicyListener.class, listener);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires a {@link PolicyEvent} to all related {@link PolicyListener}s.
|
||||
*/
|
||||
protected void fireVetoPolicyChangeAction() {
|
||||
Object[] listeners = vetoPolicyListenerList.getListenerList();
|
||||
/**
|
||||
* Fires a {@link PolicyEvent} to all related {@link PolicyListener}s.
|
||||
*/
|
||||
protected void fireVetoPolicyChangeAction() {
|
||||
Object[] listeners = vetoPolicyListenerList.getListenerList();
|
||||
|
||||
for (int i = listeners.length - 2; i >= 0; i -= 2)
|
||||
if (listeners[i] == PolicyListener.class)
|
||||
((PolicyListener) listeners[i + 1])
|
||||
.policyChanged(new PolicyEvent(this));
|
||||
}
|
||||
for (int i = listeners.length - 2; i >= 0; i -= 2)
|
||||
if (listeners[i] == PolicyListener.class)
|
||||
((PolicyListener) listeners[i + 1])
|
||||
.policyChanged(new PolicyEvent(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,38 +20,38 @@ import javax.swing.table.TableModel;
|
||||
*/
|
||||
public interface BoundedTableModel extends TableModel {
|
||||
|
||||
/**
|
||||
* The name of the bound property, that holds lower bound value.
|
||||
*/
|
||||
public static final String PROPERTY_LOWER_BOUND = "lowerBound";
|
||||
/**
|
||||
* The name of the bound property, that holds lower bound value.
|
||||
*/
|
||||
public static final String PROPERTY_LOWER_BOUND = "lowerBound";
|
||||
|
||||
/**
|
||||
* The name of the bound property, that holds upper bound value.
|
||||
*/
|
||||
public static final String PROPERTY_UPPER_BOUND = "upperBound";
|
||||
/**
|
||||
* The name of the bound property, that holds upper bound value.
|
||||
*/
|
||||
public static final String PROPERTY_UPPER_BOUND = "upperBound";
|
||||
|
||||
/**
|
||||
* Returns some lower bound, further describing the data.
|
||||
*
|
||||
* @return lower bound.
|
||||
*/
|
||||
int getLowerBound();
|
||||
/**
|
||||
* Returns some lower bound, further describing the data.
|
||||
*
|
||||
* @return lower bound.
|
||||
*/
|
||||
int getLowerBound();
|
||||
|
||||
/**
|
||||
* Returns some upper bound, further describing the data.
|
||||
*
|
||||
* @return upper bound.
|
||||
*/
|
||||
int getUpperBound();
|
||||
/**
|
||||
* Returns some upper bound, further describing the data.
|
||||
*
|
||||
* @return upper bound.
|
||||
*/
|
||||
int getUpperBound();
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener);
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener);
|
||||
|
||||
public void addPropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener);
|
||||
public void addPropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener);
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener);
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener);
|
||||
|
||||
public void removePropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener);
|
||||
public void removePropertyChangeListener(String propertyName,
|
||||
PropertyChangeListener listener);
|
||||
|
||||
}
|
||||
|
||||
@@ -11,30 +11,30 @@ import java.util.EventObject;
|
||||
*/
|
||||
public class CommitEvent extends EventObject {
|
||||
|
||||
private boolean commit;
|
||||
private boolean commit;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param source
|
||||
* a control that fired the event
|
||||
* @param commit
|
||||
* <code>true</code> to indicate commit, <code>false</code>
|
||||
* to indicate revert (rollback)
|
||||
*/
|
||||
public CommitEvent(Object source, boolean commit) {
|
||||
super(source);
|
||||
this.commit = commit;
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param source
|
||||
* a control that fired the event
|
||||
* @param commit
|
||||
* <code>true</code> to indicate commit, <code>false</code>
|
||||
* to indicate revert (rollback)
|
||||
*/
|
||||
public CommitEvent(Object source, boolean commit) {
|
||||
super(source);
|
||||
this.commit = commit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the event.
|
||||
*
|
||||
* @return <code>true</code> if a change has been commited to a control,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean isCommit() {
|
||||
return commit;
|
||||
}
|
||||
/**
|
||||
* Returns the type of the event.
|
||||
*
|
||||
* @return <code>true</code> if a change has been commited to a control,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean isCommit() {
|
||||
return commit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import java.util.EventListener;
|
||||
*
|
||||
*/
|
||||
public interface CommitListener extends EventListener {
|
||||
/**
|
||||
* Called when a {@link CommitEvent} is fired.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
public void commit(CommitEvent event);
|
||||
/**
|
||||
* Called when a {@link CommitEvent} is fired.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
public void commit(CommitEvent event);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,68 +18,68 @@ import com.michaelbaranov.microba.Microba;
|
||||
*/
|
||||
public class MicrobaComponent extends JComponent {
|
||||
|
||||
public static final String PROPERTY_NAME_COLOR_OVERRIDE_MAP = "colorOverrideMap";
|
||||
public static final String PROPERTY_NAME_COLOR_OVERRIDE_MAP = "colorOverrideMap";
|
||||
|
||||
static {
|
||||
Microba.init();
|
||||
}
|
||||
static {
|
||||
Microba.init();
|
||||
}
|
||||
|
||||
protected Map colorOverrideMap;
|
||||
protected Map colorOverrideMap;
|
||||
|
||||
public ComponentUI getUI() {
|
||||
return ui;
|
||||
}
|
||||
public ComponentUI getUI() {
|
||||
return ui;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the UI delegate of this component to the corresponding UI delegate
|
||||
* taken from UIManager.
|
||||
* <p>
|
||||
* This implementation has a workarount to fix the problem with non-standard
|
||||
* class-loaders.
|
||||
*/
|
||||
public void updateUI() {
|
||||
UIManager.getDefaults().put(UIManager.get(this.getUIClassID()), null);
|
||||
ComponentUI delegate = UIManager.getUI(this);
|
||||
/**
|
||||
* Sets the UI delegate of this component to the corresponding UI delegate
|
||||
* taken from UIManager.
|
||||
* <p>
|
||||
* This implementation has a workarount to fix the problem with non-standard
|
||||
* class-loaders.
|
||||
*/
|
||||
public void updateUI() {
|
||||
UIManager.getDefaults().put(UIManager.get(this.getUIClassID()), null);
|
||||
ComponentUI delegate = UIManager.getUI(this);
|
||||
|
||||
setUI(delegate);
|
||||
invalidate();
|
||||
}
|
||||
setUI(delegate);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns per-instance (only for this instance) map of color overrides. May
|
||||
* be <code>null</code>.
|
||||
* <p>
|
||||
* NOTE: returned map is unmodifiable. Use {@link #setColorOverrideMap(Map)}
|
||||
* to change the map.
|
||||
*
|
||||
* @return keys in the map are {@link String} constants, valuse are of type
|
||||
* {@link Color} or of type {@link String} (in this case,
|
||||
* {@link Color} values are obtained via
|
||||
* {@link UIManager#getColor(Object)})
|
||||
*/
|
||||
public Map getColorOverrideMap() {
|
||||
if (colorOverrideMap == null)
|
||||
return null;
|
||||
/**
|
||||
* Returns per-instance (only for this instance) map of color overrides. May
|
||||
* be <code>null</code>.
|
||||
* <p>
|
||||
* NOTE: returned map is unmodifiable. Use {@link #setColorOverrideMap(Map)}
|
||||
* to change the map.
|
||||
*
|
||||
* @return keys in the map are {@link String} constants, valuse are of type
|
||||
* {@link Color} or of type {@link String} (in this case,
|
||||
* {@link Color} values are obtained via
|
||||
* {@link UIManager#getColor(Object)})
|
||||
*/
|
||||
public Map getColorOverrideMap() {
|
||||
if (colorOverrideMap == null)
|
||||
return null;
|
||||
|
||||
return Collections.unmodifiableMap(colorOverrideMap);
|
||||
}
|
||||
return Collections.unmodifiableMap(colorOverrideMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets per-instance (only for this instance) map of color overrides.
|
||||
*
|
||||
* @param colorOverrideMap
|
||||
* keys in the map are {@link String} constants, valuse are of
|
||||
* type {@link Color} or of type {@link String} (in this case,
|
||||
* {@link Color} values are obtained via
|
||||
* {@link UIManager#getColor(Object)}). May be <code>null</code>.
|
||||
*/
|
||||
public void setColorOverrideMap(Map colorOverrideMap) {
|
||||
Object old = this.colorOverrideMap;
|
||||
this.colorOverrideMap = colorOverrideMap;
|
||||
firePropertyChange(PROPERTY_NAME_COLOR_OVERRIDE_MAP, old,
|
||||
colorOverrideMap);
|
||||
/**
|
||||
* Sets per-instance (only for this instance) map of color overrides.
|
||||
*
|
||||
* @param colorOverrideMap
|
||||
* keys in the map are {@link String} constants, valuse are of
|
||||
* type {@link Color} or of type {@link String} (in this case,
|
||||
* {@link Color} values are obtained via
|
||||
* {@link UIManager#getColor(Object)}). May be <code>null</code>.
|
||||
*/
|
||||
public void setColorOverrideMap(Map colorOverrideMap) {
|
||||
Object old = this.colorOverrideMap;
|
||||
this.colorOverrideMap = colorOverrideMap;
|
||||
firePropertyChange(PROPERTY_NAME_COLOR_OVERRIDE_MAP, old,
|
||||
colorOverrideMap);
|
||||
|
||||
updateUI();
|
||||
}
|
||||
updateUI();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.michaelbaranov.microba.common;
|
||||
|
||||
public interface Policy {
|
||||
/**
|
||||
* Adds a {@link PolicyListener}.
|
||||
*
|
||||
* @param listener
|
||||
* a {@link PolicyListener} to add
|
||||
*/
|
||||
public void addVetoPolicyListener(PolicyListener listener);
|
||||
/**
|
||||
* Adds a {@link PolicyListener}.
|
||||
*
|
||||
* @param listener
|
||||
* a {@link PolicyListener} to add
|
||||
*/
|
||||
public void addVetoPolicyListener(PolicyListener listener);
|
||||
|
||||
/**
|
||||
* Removes a {@link PolicyListener}.
|
||||
*
|
||||
* @param listener
|
||||
* a {@link PolicyListener} to remove
|
||||
*/
|
||||
public void removeVetoPolicyListener(PolicyListener listener);
|
||||
/**
|
||||
* Removes a {@link PolicyListener}.
|
||||
*
|
||||
* @param listener
|
||||
* a {@link PolicyListener} to remove
|
||||
*/
|
||||
public void removeVetoPolicyListener(PolicyListener listener);
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ import java.util.EventObject;
|
||||
*/
|
||||
public class PolicyEvent extends EventObject {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param source
|
||||
* an object whose policy has changed
|
||||
*/
|
||||
public PolicyEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param source
|
||||
* an object whose policy has changed
|
||||
*/
|
||||
public PolicyEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import java.util.EventListener;
|
||||
*/
|
||||
public interface PolicyListener extends EventListener {
|
||||
|
||||
/**
|
||||
* Called when a {@link PolicyEvent} is fired.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
public void policyChanged(PolicyEvent event);
|
||||
/**
|
||||
* Called when a {@link PolicyEvent} is fired.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
public void policyChanged(PolicyEvent event);
|
||||
}
|
||||
|
||||
@@ -40,249 +40,249 @@ import com.michaelbaranov.microba.marker.MarkerBar;
|
||||
|
||||
public class Demo extends JApplet {
|
||||
|
||||
static MarkerBar bar;
|
||||
static MarkerBar bar;
|
||||
|
||||
static BoundedTableModel model;
|
||||
static BoundedTableModel model;
|
||||
|
||||
private static JFrame frame;
|
||||
private static JFrame frame;
|
||||
|
||||
private static JPanel panel;
|
||||
private static JPanel panel;
|
||||
|
||||
public static void main(String[] s) {
|
||||
public static void main(String[] s) {
|
||||
|
||||
Demo demo = new Demo();
|
||||
demo.run();
|
||||
Demo demo = new Demo();
|
||||
demo.run();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void run() {
|
||||
frame = new JFrame();
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.getContentPane().setLayout(new BorderLayout());
|
||||
private void run() {
|
||||
frame = new JFrame();
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.getContentPane().setLayout(new BorderLayout());
|
||||
|
||||
JTabbedPane tabs = new JTabbedPane();
|
||||
tabs.addTab("CalendarPane", buildCalendarPaneTab());
|
||||
tabs.addTab("Gradient", buildGradientTab());
|
||||
tabs.addTab("CellEditor", buildCellEditorTab());
|
||||
tabs.addTab("DatePicker", buildDatePickerTab());
|
||||
JTabbedPane tabs = new JTabbedPane();
|
||||
tabs.addTab("CalendarPane", buildCalendarPaneTab());
|
||||
tabs.addTab("Gradient", buildGradientTab());
|
||||
tabs.addTab("CellEditor", buildCellEditorTab());
|
||||
tabs.addTab("DatePicker", buildDatePickerTab());
|
||||
|
||||
frame.getContentPane().add(tabs, BorderLayout.CENTER);
|
||||
frame.setSize(500, 300);
|
||||
frame.setVisible(true);
|
||||
frame.getContentPane().add(tabs, BorderLayout.CENTER);
|
||||
frame.setSize(500, 300);
|
||||
frame.setVisible(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// public void init() {
|
||||
// super.init();
|
||||
// System.out.println("init");
|
||||
// panel = new JPanel();
|
||||
// panel.setLayout(new BorderLayout());
|
||||
//
|
||||
// JTabbedPane tabs = new JTabbedPane();
|
||||
// tabs.addTab("CalendarPane", buildCalendarPaneTab());
|
||||
// tabs.addTab("Gradient", buildGradientTab());
|
||||
// tabs.addTab("CellEditor", buildCellEditorTab());
|
||||
// tabs.addTab("DatePicker", buildDatePickerTab());
|
||||
//
|
||||
// panel.add(tabs, BorderLayout.CENTER);
|
||||
// this.setContentPane(panel);
|
||||
// }
|
||||
//
|
||||
// public void init() {
|
||||
// super.init();
|
||||
// System.out.println("init");
|
||||
// panel = new JPanel();
|
||||
// panel.setLayout(new BorderLayout());
|
||||
//
|
||||
// JTabbedPane tabs = new JTabbedPane();
|
||||
// tabs.addTab("CalendarPane", buildCalendarPaneTab());
|
||||
// tabs.addTab("Gradient", buildGradientTab());
|
||||
// tabs.addTab("CellEditor", buildCellEditorTab());
|
||||
// tabs.addTab("DatePicker", buildDatePickerTab());
|
||||
//
|
||||
// panel.add(tabs, BorderLayout.CENTER);
|
||||
// this.setContentPane(panel);
|
||||
// }
|
||||
|
||||
public void start() {
|
||||
System.out.println("start");
|
||||
super.start();
|
||||
}
|
||||
public void start() {
|
||||
System.out.println("start");
|
||||
super.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
System.out.println("stop");
|
||||
super.stop();
|
||||
}
|
||||
public void stop() {
|
||||
System.out.println("stop");
|
||||
super.stop();
|
||||
}
|
||||
|
||||
private class Hol extends AbstractPolicy implements HolidayPolicy {
|
||||
private class Hol extends AbstractPolicy implements HolidayPolicy {
|
||||
|
||||
public String getHollidayName(Object source, Calendar date) {
|
||||
return null;
|
||||
}
|
||||
public String getHollidayName(Object source, Calendar date) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isHolliday(Object source, Calendar date) {
|
||||
return false;
|
||||
}
|
||||
public boolean isHolliday(Object source, Calendar date) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isWeekend(Object source, Calendar date) {
|
||||
return date.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
|
||||
}
|
||||
public boolean isWeekend(Object source, Calendar date) {
|
||||
return date.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private JComponent buildCalendarPaneTab() {
|
||||
JPanel panel = new JPanel();
|
||||
final CalendarPane calendarPane = new CalendarPane();
|
||||
private JComponent buildCalendarPaneTab() {
|
||||
JPanel panel = new JPanel();
|
||||
final CalendarPane calendarPane = new CalendarPane();
|
||||
|
||||
// calendarPane.setEnabled(false);
|
||||
calendarPane.setHolidayPolicy(new Hol());
|
||||
// calendarPane.setEnabled(false);
|
||||
calendarPane.setHolidayPolicy(new Hol());
|
||||
|
||||
Map ov = new HashMap();
|
||||
Map ov = new HashMap();
|
||||
|
||||
ov.put(CalendarPane.COLOR_CALENDAR_GRID_FOREGROUND_ENABLED,
|
||||
Color.ORANGE);
|
||||
|
||||
calendarPane.setColorOverrideMap(ov);
|
||||
ov.put(CalendarPane.COLOR_CALENDAR_GRID_FOREGROUND_ENABLED,
|
||||
Color.ORANGE);
|
||||
|
||||
calendarPane.setColorOverrideMap(ov);
|
||||
|
||||
try {
|
||||
calendarPane.setDate(new Date());
|
||||
} catch (PropertyVetoException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
calendarPane.setDate(new Date());
|
||||
} catch (PropertyVetoException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
calendarPane.addActionListener(new ActionListener() {
|
||||
calendarPane.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("CalendarPane:" + calendarPane.getDate());
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("CalendarPane:" + calendarPane.getDate());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
panel.setLayout(new GridBagLayout());
|
||||
panel.add(calendarPane, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
5, 5, 5, 5), 0, 0));
|
||||
panel.setLayout(new GridBagLayout());
|
||||
panel.add(calendarPane, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
5, 5, 5, 5), 0, 0));
|
||||
|
||||
return panel;
|
||||
return panel;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private JComponent buildDatePickerTab() {
|
||||
JPanel panel = new JPanel();
|
||||
final DatePicker datePicker = new DatePicker();
|
||||
// datePicker.setDateFormat(new SimpleDateFormat("HH dd yyyy"));
|
||||
datePicker.setDateFormat(SimpleDateFormat.getDateTimeInstance());
|
||||
// datePicker.setStripTime(false);
|
||||
datePicker.setEnabled(false);
|
||||
datePicker.setKeepTime(true);
|
||||
datePicker.setStripTime(false);
|
||||
datePicker.setShowNumberOfWeek(true);
|
||||
// datePicker.setEnabled(false);
|
||||
// datePicker.setPickerStyle(DatePicker.PICKER_STYLE_BUTTON);
|
||||
// datePicker.showButtonOnly(false);
|
||||
// datePicker.setToolTipText("hello!!!!");
|
||||
// datePicker.setShowNumberOfWeek(true);
|
||||
|
||||
Map ov = new HashMap();
|
||||
private JComponent buildDatePickerTab() {
|
||||
JPanel panel = new JPanel();
|
||||
final DatePicker datePicker = new DatePicker();
|
||||
// datePicker.setDateFormat(new SimpleDateFormat("HH dd yyyy"));
|
||||
datePicker.setDateFormat(SimpleDateFormat.getDateTimeInstance());
|
||||
// datePicker.setStripTime(false);
|
||||
datePicker.setEnabled(false);
|
||||
datePicker.setKeepTime(true);
|
||||
datePicker.setStripTime(false);
|
||||
datePicker.setShowNumberOfWeek(true);
|
||||
// datePicker.setEnabled(false);
|
||||
// datePicker.setPickerStyle(DatePicker.PICKER_STYLE_BUTTON);
|
||||
// datePicker.showButtonOnly(false);
|
||||
// datePicker.setToolTipText("hello!!!!");
|
||||
// datePicker.setShowNumberOfWeek(true);
|
||||
|
||||
Map ov = new HashMap();
|
||||
|
||||
ov.put(CalendarPane.COLOR_CALENDAR_GRID_FOREGROUND_ENABLED,
|
||||
Color.ORANGE);
|
||||
|
||||
datePicker.setColorOverrideMap(ov);
|
||||
ov.put(CalendarPane.COLOR_CALENDAR_GRID_FOREGROUND_ENABLED,
|
||||
Color.ORANGE);
|
||||
|
||||
datePicker.setColorOverrideMap(ov);
|
||||
|
||||
panel.setLayout(new GridBagLayout());
|
||||
panel.add(datePicker, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
5, 5, 5, 5), 0, 0));
|
||||
panel.setLayout(new GridBagLayout());
|
||||
panel.add(datePicker, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
|
||||
5, 5, 5, 5), 0, 0));
|
||||
|
||||
datePicker.addActionListener(new ActionListener() {
|
||||
datePicker.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("DatePicker:" + datePicker.getDate());
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("DatePicker:" + datePicker.getDate());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return panel;
|
||||
return panel;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private JComponent buildCellEditorTab() {
|
||||
JPanel panel = new JPanel();
|
||||
DatePicker datePicker = new DatePicker();
|
||||
private JComponent buildCellEditorTab() {
|
||||
JPanel panel = new JPanel();
|
||||
DatePicker datePicker = new DatePicker();
|
||||
|
||||
datePicker.setDropdownFocusable(true);
|
||||
datePicker.setDropdownFocusable(true);
|
||||
|
||||
DatePickerCellEditor cellEditor = new DatePickerCellEditor(datePicker);
|
||||
cellEditor.setClickCountToStart(2);
|
||||
DatePickerCellEditor cellEditor = new DatePickerCellEditor(datePicker);
|
||||
cellEditor.setClickCountToStart(2);
|
||||
|
||||
JTable table = new JTable(100, 3);
|
||||
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
JTable table = new JTable(100, 3);
|
||||
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
|
||||
table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
|
||||
table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
|
||||
|
||||
panel.setLayout(new GridBagLayout());
|
||||
panel.add(scrollPane, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
|
||||
5, 5, 5, 5), 0, 0));
|
||||
return panel;
|
||||
panel.setLayout(new GridBagLayout());
|
||||
panel.add(scrollPane, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
|
||||
5, 5, 5, 5), 0, 0));
|
||||
return panel;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private JComponent buildGradientTab() {
|
||||
JPanel panel = new JPanel();
|
||||
GradientBar gradient;
|
||||
private JComponent buildGradientTab() {
|
||||
JPanel panel = new JPanel();
|
||||
GradientBar gradient;
|
||||
|
||||
GradientEditor editor;
|
||||
JColorChooser colorChooser;
|
||||
GradientEditor editor;
|
||||
JColorChooser colorChooser;
|
||||
|
||||
colorChooser = new JColorChooser();
|
||||
editor = new GradientEditor();
|
||||
colorChooser = new JColorChooser();
|
||||
editor = new GradientEditor();
|
||||
|
||||
// editor.setOrientation(SwingConstants.VERTICAL);
|
||||
// editor.setOrientation(SwingConstants.VERTICAL);
|
||||
|
||||
ColorAdaptor adaptor = new ColorAdaptor(editor, colorChooser);
|
||||
ColorAdaptor adaptor = new ColorAdaptor(editor, colorChooser);
|
||||
|
||||
panel.add(editor, BorderLayout.NORTH);
|
||||
panel.add(colorChooser, BorderLayout.CENTER);
|
||||
panel.add(editor, BorderLayout.NORTH);
|
||||
panel.add(colorChooser, BorderLayout.CENTER);
|
||||
|
||||
MarkerBar bar = new MarkerBar();
|
||||
bar.setDataModel(editor.getDataModel());
|
||||
bar.setPositionColumn(editor.getColorPositionColumn());
|
||||
bar.setColorColumn(editor.getColorColumn());
|
||||
bar.setFliped(true);
|
||||
bar.setOrientation(SwingConstants.VERTICAL);
|
||||
panel.add(bar, BorderLayout.EAST);
|
||||
return panel;
|
||||
}
|
||||
MarkerBar bar = new MarkerBar();
|
||||
bar.setDataModel(editor.getDataModel());
|
||||
bar.setPositionColumn(editor.getColorPositionColumn());
|
||||
bar.setColorColumn(editor.getColorColumn());
|
||||
bar.setFliped(true);
|
||||
bar.setOrientation(SwingConstants.VERTICAL);
|
||||
panel.add(bar, BorderLayout.EAST);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private static class ColorAdaptor implements ChangeListener,
|
||||
ListSelectionListener {
|
||||
private static class ColorAdaptor implements ChangeListener,
|
||||
ListSelectionListener {
|
||||
|
||||
private GradientEditor editor;
|
||||
private GradientEditor editor;
|
||||
|
||||
private JColorChooser chooser;
|
||||
private JColorChooser chooser;
|
||||
|
||||
public ColorAdaptor(GradientEditor editor, JColorChooser chooser) {
|
||||
super();
|
||||
this.editor = editor;
|
||||
this.chooser = chooser;
|
||||
public ColorAdaptor(GradientEditor editor, JColorChooser chooser) {
|
||||
super();
|
||||
this.editor = editor;
|
||||
this.chooser = chooser;
|
||||
|
||||
editor.getColorSelectionModel().addListSelectionListener(this);
|
||||
chooser.getSelectionModel().addChangeListener(this);
|
||||
}
|
||||
editor.getColorSelectionModel().addListSelectionListener(this);
|
||||
chooser.getSelectionModel().addChangeListener(this);
|
||||
}
|
||||
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
int index = editor.getColorSelectionModel().getLeadSelectionIndex();
|
||||
// System.out.println(index);
|
||||
// System.out.println(e.getFirstIndex());
|
||||
// System.out.println(e.getLastIndex());
|
||||
// System.out.println("-------");
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
int index = editor.getColorSelectionModel().getLeadSelectionIndex();
|
||||
// System.out.println(index);
|
||||
// System.out.println(e.getFirstIndex());
|
||||
// System.out.println(e.getLastIndex());
|
||||
// System.out.println("-------");
|
||||
|
||||
Color c = (Color) editor.getDataModel().getValueAt(index,
|
||||
editor.getColorColumn());
|
||||
chooser.setColor(c);
|
||||
}
|
||||
Color c = (Color) editor.getDataModel().getValueAt(index,
|
||||
editor.getColorColumn());
|
||||
chooser.setColor(c);
|
||||
}
|
||||
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
|
||||
if (!editor.getColorSelectionModel().isSelectionEmpty()) {
|
||||
int index = editor.getColorSelectionModel()
|
||||
.getLeadSelectionIndex();
|
||||
if (!editor.getColorSelectionModel().isSelectionEmpty()) {
|
||||
int index = editor.getColorSelectionModel()
|
||||
.getLeadSelectionIndex();
|
||||
|
||||
editor.getDataModel().setValueAt(chooser.getColor(), index,
|
||||
editor.getColorColumn());
|
||||
}
|
||||
editor.getDataModel().setValueAt(chooser.getColor(), index,
|
||||
editor.getColorColumn());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,95 +16,95 @@ import com.michaelbaranov.microba.common.AbstractBoundedTableModel;
|
||||
*/
|
||||
public class DefaultGradientModel extends AbstractBoundedTableModel {
|
||||
|
||||
protected static final int POSITION_COLUMN = 0;
|
||||
protected static final int POSITION_COLUMN = 0;
|
||||
|
||||
protected static final int COLOR_COLUMN = 1;
|
||||
protected static final int COLOR_COLUMN = 1;
|
||||
|
||||
protected List positionList = new ArrayList(32);
|
||||
protected List positionList = new ArrayList(32);
|
||||
|
||||
protected List colorList = new ArrayList(32);
|
||||
protected List colorList = new ArrayList(32);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DefaultGradientModel() {
|
||||
super();
|
||||
positionList.add(new Integer(0));
|
||||
colorList.add(Color.YELLOW);
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DefaultGradientModel() {
|
||||
super();
|
||||
positionList.add(new Integer(0));
|
||||
colorList.add(Color.YELLOW);
|
||||
|
||||
positionList.add(new Integer(50));
|
||||
colorList.add(Color.RED);
|
||||
positionList.add(new Integer(50));
|
||||
colorList.add(Color.RED);
|
||||
|
||||
positionList.add(new Integer(100));
|
||||
colorList.add(Color.GREEN);
|
||||
}
|
||||
positionList.add(new Integer(100));
|
||||
colorList.add(Color.GREEN);
|
||||
}
|
||||
|
||||
public int getLowerBound() {
|
||||
return 0;
|
||||
}
|
||||
public int getLowerBound() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getUpperBound() {
|
||||
return 100;
|
||||
}
|
||||
public int getUpperBound() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return positionList.size();
|
||||
}
|
||||
public int getRowCount() {
|
||||
return positionList.size();
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
}
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case POSITION_COLUMN:
|
||||
return Integer.class;
|
||||
case COLOR_COLUMN:
|
||||
return Color.class;
|
||||
}
|
||||
return super.getColumnClass(columnIndex);
|
||||
}
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case POSITION_COLUMN:
|
||||
return Integer.class;
|
||||
case COLOR_COLUMN:
|
||||
return Color.class;
|
||||
}
|
||||
return super.getColumnClass(columnIndex);
|
||||
}
|
||||
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case POSITION_COLUMN:
|
||||
return positionList.get(rowIndex);
|
||||
case COLOR_COLUMN:
|
||||
return colorList.get(rowIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case POSITION_COLUMN:
|
||||
return positionList.get(rowIndex);
|
||||
case COLOR_COLUMN:
|
||||
return colorList.get(rowIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a color point.
|
||||
*
|
||||
* @param color
|
||||
* @param position
|
||||
*/
|
||||
public void add(Color color, int position) {
|
||||
colorList.add(color);
|
||||
positionList.add(new Integer(position));
|
||||
fireTableDataChanged();
|
||||
}
|
||||
/**
|
||||
* Adds a color point.
|
||||
*
|
||||
* @param color
|
||||
* @param position
|
||||
*/
|
||||
public void add(Color color, int position) {
|
||||
colorList.add(color);
|
||||
positionList.add(new Integer(position));
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a color point at specified index.
|
||||
*
|
||||
* @param index
|
||||
*/
|
||||
public void remove(int index) {
|
||||
colorList.remove(index);
|
||||
positionList.remove(index);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
/**
|
||||
* Removes a color point at specified index.
|
||||
*
|
||||
* @param index
|
||||
*/
|
||||
public void remove(int index) {
|
||||
colorList.remove(index);
|
||||
positionList.remove(index);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all color points.
|
||||
*/
|
||||
public void clear() {
|
||||
colorList.clear();
|
||||
positionList.clear();
|
||||
fireTableDataChanged();
|
||||
}
|
||||
/**
|
||||
* Removes all color points.
|
||||
*/
|
||||
public void clear() {
|
||||
colorList.clear();
|
||||
positionList.clear();
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,265 +46,265 @@ import com.michaelbaranov.microba.common.MicrobaComponent;
|
||||
*/
|
||||
public class GradientBar extends MicrobaComponent {
|
||||
|
||||
/**
|
||||
* The name of a "dataModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_DATA_MODEL = "dataModel";
|
||||
/**
|
||||
* The name of a "dataModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_DATA_MODEL = "dataModel";
|
||||
|
||||
/**
|
||||
* The name of a "alphaModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_ALPHA_MODEL = "alphaModel";
|
||||
/**
|
||||
* The name of a "alphaModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_ALPHA_MODEL = "alphaModel";
|
||||
|
||||
/**
|
||||
* The name of a "colorPositionColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_COLOR_POSITION_COLUMN = "colorPositionColumn";
|
||||
/**
|
||||
* The name of a "colorPositionColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_COLOR_POSITION_COLUMN = "colorPositionColumn";
|
||||
|
||||
/**
|
||||
* The name of a "alphaPositionColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_ALPHA_POSITION_COLUMN = "alphaPositionColumn";
|
||||
/**
|
||||
* The name of a "alphaPositionColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_ALPHA_POSITION_COLUMN = "alphaPositionColumn";
|
||||
|
||||
/**
|
||||
* The name of a "colorColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_COLOR_COLUMN = "colorColumn";
|
||||
/**
|
||||
* The name of a "colorColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_COLOR_COLUMN = "colorColumn";
|
||||
|
||||
/**
|
||||
* The name of a "alphaColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_ALPHA_COLUMN = "alphaColumn";
|
||||
/**
|
||||
* The name of a "alphaColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_ALPHA_COLUMN = "alphaColumn";
|
||||
|
||||
/**
|
||||
* The name of a "orientation" property.
|
||||
*/
|
||||
public static final String PROPERTY_ORIENTATION = "orientation";
|
||||
/**
|
||||
* The name of a "orientation" property.
|
||||
*/
|
||||
public static final String PROPERTY_ORIENTATION = "orientation";
|
||||
|
||||
private static final String uiClassID = "microba.GradientUI";
|
||||
private static final String uiClassID = "microba.GradientUI";
|
||||
|
||||
protected BoundedTableModel dataModel;
|
||||
protected BoundedTableModel dataModel;
|
||||
|
||||
protected BoundedTableModel alphaModel;
|
||||
protected BoundedTableModel alphaModel;
|
||||
|
||||
protected int colorPositionColumn = 0;
|
||||
protected int colorPositionColumn = 0;
|
||||
|
||||
protected int alphaPositionColumn = 0;
|
||||
protected int alphaPositionColumn = 0;
|
||||
|
||||
protected int colorColumn = 1;
|
||||
protected int colorColumn = 1;
|
||||
|
||||
protected int alphaColumn = 1;
|
||||
protected int alphaColumn = 1;
|
||||
|
||||
protected int orientation = SwingConstants.HORIZONTAL;
|
||||
protected int orientation = SwingConstants.HORIZONTAL;
|
||||
|
||||
public String getUIClassID() {
|
||||
return uiClassID;
|
||||
}
|
||||
public String getUIClassID() {
|
||||
return uiClassID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public GradientBar() {
|
||||
super();
|
||||
dataModel = new DefaultGradientModel();
|
||||
setFocusable(false);
|
||||
updateUI();
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public GradientBar() {
|
||||
super();
|
||||
dataModel = new DefaultGradientModel();
|
||||
setFocusable(false);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public GradientBar(BoundedTableModel model) {
|
||||
super();
|
||||
dataModel = model;
|
||||
setFocusable(false);
|
||||
updateUI();
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public GradientBar(BoundedTableModel model) {
|
||||
super();
|
||||
dataModel = model;
|
||||
setFocusable(false);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public GradientBar(BoundedTableModel model, int orientation) {
|
||||
super();
|
||||
dataModel = model;
|
||||
this.orientation = orientation;
|
||||
setFocusable(false);
|
||||
updateUI();
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public GradientBar(BoundedTableModel model, int orientation) {
|
||||
super();
|
||||
dataModel = model;
|
||||
this.orientation = orientation;
|
||||
setFocusable(false);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the color column for the data model.
|
||||
*
|
||||
* @return index of color column
|
||||
* @see #setColorColumn(int)
|
||||
*/
|
||||
public int getColorColumn() {
|
||||
return colorColumn;
|
||||
}
|
||||
/**
|
||||
* Returns the index of the color column for the data model.
|
||||
*
|
||||
* @return index of color column
|
||||
* @see #setColorColumn(int)
|
||||
*/
|
||||
public int getColorColumn() {
|
||||
return colorColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the index of the color column for the data model.
|
||||
*
|
||||
* @param colorColumn
|
||||
* index of color column
|
||||
* @see #getColorColumn()
|
||||
*/
|
||||
public void setColorColumn(int colorColumn) {
|
||||
int old = this.colorColumn;
|
||||
this.colorColumn = colorColumn;
|
||||
firePropertyChange(PROPERTY_COLOR_COLUMN, old, colorColumn);
|
||||
}
|
||||
/**
|
||||
* Sets the index of the color column for the data model.
|
||||
*
|
||||
* @param colorColumn
|
||||
* index of color column
|
||||
* @see #getColorColumn()
|
||||
*/
|
||||
public void setColorColumn(int colorColumn) {
|
||||
int old = this.colorColumn;
|
||||
this.colorColumn = colorColumn;
|
||||
firePropertyChange(PROPERTY_COLOR_COLUMN, old, colorColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the alpha column for the alpha model.
|
||||
*
|
||||
* @return index of alpha column
|
||||
* @see #setAlphaColumn(int)
|
||||
*/
|
||||
public int getAlphaColumn() {
|
||||
return alphaColumn;
|
||||
}
|
||||
/**
|
||||
* Returns the index of the alpha column for the alpha model.
|
||||
*
|
||||
* @return index of alpha column
|
||||
* @see #setAlphaColumn(int)
|
||||
*/
|
||||
public int getAlphaColumn() {
|
||||
return alphaColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the index of the alpha column for the alpha model.
|
||||
*
|
||||
* @param alphaColumn
|
||||
* index of alpha column
|
||||
* @see #getAlphaColumn()
|
||||
*/
|
||||
public void setAlphaColumn(int alphaColumn) {
|
||||
int old = this.colorColumn;
|
||||
this.alphaColumn = alphaColumn;
|
||||
firePropertyChange(PROPERTY_ALPHA_COLUMN, old, alphaColumn);
|
||||
}
|
||||
/**
|
||||
* Sets the index of the alpha column for the alpha model.
|
||||
*
|
||||
* @param alphaColumn
|
||||
* index of alpha column
|
||||
* @see #getAlphaColumn()
|
||||
*/
|
||||
public void setAlphaColumn(int alphaColumn) {
|
||||
int old = this.colorColumn;
|
||||
this.alphaColumn = alphaColumn;
|
||||
firePropertyChange(PROPERTY_ALPHA_COLUMN, old, alphaColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regturns the current data model. The data model provides key points for
|
||||
* interpolation (position & color).
|
||||
*
|
||||
* @return current data model
|
||||
* @see #setDataModel(BoundedTableModel)
|
||||
* @see #getColorColumn()
|
||||
*/
|
||||
public BoundedTableModel getDataModel() {
|
||||
return dataModel;
|
||||
}
|
||||
/**
|
||||
* Regturns the current data model. The data model provides key points for
|
||||
* interpolation (position & color).
|
||||
*
|
||||
* @return current data model
|
||||
* @see #setDataModel(BoundedTableModel)
|
||||
* @see #getColorColumn()
|
||||
*/
|
||||
public BoundedTableModel getDataModel() {
|
||||
return dataModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current data model. The data model provides key points for
|
||||
* interpolation (position & color).
|
||||
*
|
||||
* @param dataModel
|
||||
* current data model
|
||||
* @see #getDataModel()
|
||||
* @see #getColorColumn()
|
||||
*/
|
||||
public void setDataModel(BoundedTableModel dataModel) {
|
||||
BoundedTableModel old = this.dataModel;
|
||||
this.dataModel = dataModel;
|
||||
firePropertyChange(PROPERTY_DATA_MODEL, old, dataModel);
|
||||
}
|
||||
/**
|
||||
* Sets the current data model. The data model provides key points for
|
||||
* interpolation (position & color).
|
||||
*
|
||||
* @param dataModel
|
||||
* current data model
|
||||
* @see #getDataModel()
|
||||
* @see #getColorColumn()
|
||||
*/
|
||||
public void setDataModel(BoundedTableModel dataModel) {
|
||||
BoundedTableModel old = this.dataModel;
|
||||
this.dataModel = dataModel;
|
||||
firePropertyChange(PROPERTY_DATA_MODEL, old, dataModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regturns the current alpha model. The data model provides alpha key
|
||||
* points for interpolation (position & alpha).
|
||||
*
|
||||
* @return current alpha model
|
||||
* @see #setAlphaModel(BoundedTableModel)
|
||||
* @see #getAlphaColumn()
|
||||
*/
|
||||
public BoundedTableModel getAlphaModel() {
|
||||
return alphaModel;
|
||||
}
|
||||
/**
|
||||
* Regturns the current alpha model. The data model provides alpha key
|
||||
* points for interpolation (position & alpha).
|
||||
*
|
||||
* @return current alpha model
|
||||
* @see #setAlphaModel(BoundedTableModel)
|
||||
* @see #getAlphaColumn()
|
||||
*/
|
||||
public BoundedTableModel getAlphaModel() {
|
||||
return alphaModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current alpha model. The alpha model provides alpha key points
|
||||
* for interpolation (position & alpha).
|
||||
*
|
||||
* @param alphaModel
|
||||
* current alpha model
|
||||
* @see #getAlphaModel()
|
||||
* @see #getAlphaColumn()
|
||||
*/
|
||||
public void setAlphaModel(BoundedTableModel alphaModel) {
|
||||
BoundedTableModel old = this.alphaModel;
|
||||
this.alphaModel = alphaModel;
|
||||
firePropertyChange(PROPERTY_ALPHA_MODEL, old, alphaModel);
|
||||
}
|
||||
/**
|
||||
* Sets the current alpha model. The alpha model provides alpha key points
|
||||
* for interpolation (position & alpha).
|
||||
*
|
||||
* @param alphaModel
|
||||
* current alpha model
|
||||
* @see #getAlphaModel()
|
||||
* @see #getAlphaColumn()
|
||||
*/
|
||||
public void setAlphaModel(BoundedTableModel alphaModel) {
|
||||
BoundedTableModel old = this.alphaModel;
|
||||
this.alphaModel = alphaModel;
|
||||
firePropertyChange(PROPERTY_ALPHA_MODEL, old, alphaModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current orientation of the component. Possible values are:
|
||||
* <ul>
|
||||
* <li>SwingConstants.HORIZONTAL
|
||||
* <li>SwingConstants.VERTICAL
|
||||
* </ul>
|
||||
*
|
||||
* @return orientation
|
||||
* @see #setOrientation(int)
|
||||
*/
|
||||
public int getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
/**
|
||||
* Returns current orientation of the component. Possible values are:
|
||||
* <ul>
|
||||
* <li>SwingConstants.HORIZONTAL
|
||||
* <li>SwingConstants.VERTICAL
|
||||
* </ul>
|
||||
*
|
||||
* @return orientation
|
||||
* @see #setOrientation(int)
|
||||
*/
|
||||
public int getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets orientation of the component. Possible values are:
|
||||
* <ul>
|
||||
* <li>SwingConstants.HORIZONTAL
|
||||
* <li>SwingConstants.VERTICAL
|
||||
* </ul>
|
||||
*
|
||||
* @param orientation
|
||||
*/
|
||||
public void setOrientation(int orientation) {
|
||||
int old = this.orientation;
|
||||
this.orientation = orientation;
|
||||
firePropertyChange(PROPERTY_ORIENTATION, old, orientation);
|
||||
}
|
||||
/**
|
||||
* Sets orientation of the component. Possible values are:
|
||||
* <ul>
|
||||
* <li>SwingConstants.HORIZONTAL
|
||||
* <li>SwingConstants.VERTICAL
|
||||
* </ul>
|
||||
*
|
||||
* @param orientation
|
||||
*/
|
||||
public void setOrientation(int orientation) {
|
||||
int old = this.orientation;
|
||||
this.orientation = orientation;
|
||||
firePropertyChange(PROPERTY_ORIENTATION, old, orientation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the position column for the data model.
|
||||
*
|
||||
* @return index of position column
|
||||
* @see #setColorPositionColumn(int)
|
||||
*/
|
||||
public int getColorPositionColumn() {
|
||||
return colorPositionColumn;
|
||||
}
|
||||
/**
|
||||
* Returns the index of the position column for the data model.
|
||||
*
|
||||
* @return index of position column
|
||||
* @see #setColorPositionColumn(int)
|
||||
*/
|
||||
public int getColorPositionColumn() {
|
||||
return colorPositionColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the index of the position column for the data model.
|
||||
*
|
||||
* @param positionColumn
|
||||
* index of position column
|
||||
* @see #getColorPositionColumn()
|
||||
*/
|
||||
public void setColorPositionColumn(int positionColumn) {
|
||||
int old = this.colorPositionColumn;
|
||||
this.colorPositionColumn = positionColumn;
|
||||
firePropertyChange(PROPERTY_COLOR_POSITION_COLUMN, old, positionColumn);
|
||||
}
|
||||
/**
|
||||
* Sets the index of the position column for the data model.
|
||||
*
|
||||
* @param positionColumn
|
||||
* index of position column
|
||||
* @see #getColorPositionColumn()
|
||||
*/
|
||||
public void setColorPositionColumn(int positionColumn) {
|
||||
int old = this.colorPositionColumn;
|
||||
this.colorPositionColumn = positionColumn;
|
||||
firePropertyChange(PROPERTY_COLOR_POSITION_COLUMN, old, positionColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the position column for the alpha model.
|
||||
*
|
||||
* @return index of position column
|
||||
* @see #setAlphaPositionColumn(int)
|
||||
*/
|
||||
public int getAlphaPositionColumn() {
|
||||
return alphaPositionColumn;
|
||||
}
|
||||
/**
|
||||
* Returns the index of the position column for the alpha model.
|
||||
*
|
||||
* @return index of position column
|
||||
* @see #setAlphaPositionColumn(int)
|
||||
*/
|
||||
public int getAlphaPositionColumn() {
|
||||
return alphaPositionColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the index of the position column for the alpha model.
|
||||
*
|
||||
* @param positionColumn
|
||||
* index of position column
|
||||
* @see #getAlphaPositionColumn()
|
||||
*/
|
||||
public void setAlphaPositionColumn(int positionColumn) {
|
||||
int old = this.alphaPositionColumn;
|
||||
this.alphaPositionColumn = positionColumn;
|
||||
firePropertyChange(PROPERTY_ALPHA_POSITION_COLUMN, old, positionColumn);
|
||||
}
|
||||
/**
|
||||
* Sets the index of the position column for the alpha model.
|
||||
*
|
||||
* @param positionColumn
|
||||
* index of position column
|
||||
* @see #getAlphaPositionColumn()
|
||||
*/
|
||||
public void setAlphaPositionColumn(int positionColumn) {
|
||||
int old = this.alphaPositionColumn;
|
||||
this.alphaPositionColumn = positionColumn;
|
||||
firePropertyChange(PROPERTY_ALPHA_POSITION_COLUMN, old, positionColumn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,46 +11,46 @@ import com.michaelbaranov.microba.gradient.GradientBar;
|
||||
import com.michaelbaranov.microba.gradient.ui.basic.BasicGradientUI;
|
||||
|
||||
public class GradientListener implements TableModelListener,
|
||||
PropertyChangeListener {
|
||||
PropertyChangeListener {
|
||||
|
||||
private final BasicGradientUI gradientUI;
|
||||
private final BasicGradientUI gradientUI;
|
||||
|
||||
private GradientBar gradient;
|
||||
private GradientBar gradient;
|
||||
|
||||
public GradientListener(BasicGradientUI gradientUI, GradientBar gradient) {
|
||||
this.gradientUI = gradientUI;
|
||||
this.gradient = gradient;
|
||||
}
|
||||
public GradientListener(BasicGradientUI gradientUI, GradientBar gradient) {
|
||||
this.gradientUI = gradientUI;
|
||||
this.gradient = gradient;
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (GradientBar.PROPERTY_DATA_MODEL.equals(evt.getPropertyName())) {
|
||||
BoundedTableModel oldModel = (BoundedTableModel) evt.getOldValue();
|
||||
BoundedTableModel newModel = (BoundedTableModel) evt.getNewValue();
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (GradientBar.PROPERTY_DATA_MODEL.equals(evt.getPropertyName())) {
|
||||
BoundedTableModel oldModel = (BoundedTableModel) evt.getOldValue();
|
||||
BoundedTableModel newModel = (BoundedTableModel) evt.getNewValue();
|
||||
|
||||
if (oldModel != null)
|
||||
oldModel.removeTableModelListener(this);
|
||||
if (newModel != null)
|
||||
newModel.addTableModelListener(this);
|
||||
if (oldModel != null)
|
||||
oldModel.removeTableModelListener(this);
|
||||
if (newModel != null)
|
||||
newModel.addTableModelListener(this);
|
||||
|
||||
gradient.revalidate();
|
||||
}
|
||||
gradient.revalidate();
|
||||
}
|
||||
|
||||
if (GradientBar.PROPERTY_ORIENTATION.equals(evt.getPropertyName())) {
|
||||
gradient.revalidate();
|
||||
}
|
||||
if (GradientBar.PROPERTY_COLOR_POSITION_COLUMN.equals(evt.getPropertyName())) {
|
||||
gradient.repaint();
|
||||
}
|
||||
if (GradientBar.PROPERTY_COLOR_COLUMN.equals(evt.getPropertyName())) {
|
||||
gradient.repaint();
|
||||
}
|
||||
if ("enabled".equals(evt.getPropertyName())) {
|
||||
gradient.repaint();
|
||||
}
|
||||
}
|
||||
if (GradientBar.PROPERTY_ORIENTATION.equals(evt.getPropertyName())) {
|
||||
gradient.revalidate();
|
||||
}
|
||||
if (GradientBar.PROPERTY_COLOR_POSITION_COLUMN.equals(evt.getPropertyName())) {
|
||||
gradient.repaint();
|
||||
}
|
||||
if (GradientBar.PROPERTY_COLOR_COLUMN.equals(evt.getPropertyName())) {
|
||||
gradient.repaint();
|
||||
}
|
||||
if ("enabled".equals(evt.getPropertyName())) {
|
||||
gradient.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public void tableChanged(TableModelEvent e) {
|
||||
gradient.repaint();
|
||||
public void tableChanged(TableModelEvent e) {
|
||||
gradient.repaint();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,117 +13,117 @@ import com.michaelbaranov.microba.gradient.GradientBar;
|
||||
|
||||
public class GradientUI extends ComponentUI {
|
||||
|
||||
protected static final int PREF_BAR_HEIGHT = 32;
|
||||
protected static final int PREF_BAR_HEIGHT = 32;
|
||||
|
||||
protected static Rectangle viewRect = new Rectangle();
|
||||
protected static Rectangle viewRect = new Rectangle();
|
||||
|
||||
private PreparedColorPoint colorPoints[] = new PreparedColorPoint[0];
|
||||
private PreparedColorPoint colorPoints[] = new PreparedColorPoint[0];
|
||||
|
||||
private PreparedAlphaPoint alphaPoints[] = new PreparedAlphaPoint[0];
|
||||
private PreparedAlphaPoint alphaPoints[] = new PreparedAlphaPoint[0];
|
||||
|
||||
protected void calculateViewRect(GradientBar gradient) {
|
||||
Insets insets = gradient.getInsets();
|
||||
viewRect.x = insets.left;
|
||||
viewRect.y = insets.top;
|
||||
viewRect.width = gradient.getWidth() - (insets.right + viewRect.x);
|
||||
viewRect.height = gradient.getHeight() - (insets.bottom + viewRect.y);
|
||||
protected void calculateViewRect(GradientBar gradient) {
|
||||
Insets insets = gradient.getInsets();
|
||||
viewRect.x = insets.left;
|
||||
viewRect.y = insets.top;
|
||||
viewRect.width = gradient.getWidth() - (insets.right + viewRect.x);
|
||||
viewRect.height = gradient.getHeight() - (insets.bottom + viewRect.y);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected PreparedColorPoint[] prepareColorPoints(BoundedTableModel model,
|
||||
int positionColumn, int colorColumn) {
|
||||
protected PreparedColorPoint[] prepareColorPoints(BoundedTableModel model,
|
||||
int positionColumn, int colorColumn) {
|
||||
|
||||
int numPoints = model.getRowCount();
|
||||
int numPoints = model.getRowCount();
|
||||
|
||||
if (numPoints > colorPoints.length) {
|
||||
colorPoints = new PreparedColorPoint[numPoints * 2];
|
||||
for (int i = 0; i < colorPoints.length; i++)
|
||||
colorPoints[i] = new PreparedColorPoint();
|
||||
}
|
||||
if (numPoints > colorPoints.length) {
|
||||
colorPoints = new PreparedColorPoint[numPoints * 2];
|
||||
for (int i = 0; i < colorPoints.length; i++)
|
||||
colorPoints[i] = new PreparedColorPoint();
|
||||
}
|
||||
|
||||
for (int i = 0; i < numPoints; i++) {
|
||||
PreparedColorPoint p = colorPoints[i];
|
||||
Color c = (Color) model.getValueAt(i, colorColumn);
|
||||
p.position = ((Number) model.getValueAt(i, positionColumn))
|
||||
.intValue();
|
||||
p.r = c.getRed();
|
||||
p.g = c.getGreen();
|
||||
p.b = c.getBlue();
|
||||
}
|
||||
for (int i = 0; i < numPoints; i++) {
|
||||
PreparedColorPoint p = colorPoints[i];
|
||||
Color c = (Color) model.getValueAt(i, colorColumn);
|
||||
p.position = ((Number) model.getValueAt(i, positionColumn))
|
||||
.intValue();
|
||||
p.r = c.getRed();
|
||||
p.g = c.getGreen();
|
||||
p.b = c.getBlue();
|
||||
}
|
||||
|
||||
Arrays.sort(colorPoints, 0, numPoints, PreparedColorPoint.comparator);
|
||||
Arrays.sort(colorPoints, 0, numPoints, PreparedColorPoint.comparator);
|
||||
|
||||
return colorPoints;
|
||||
}
|
||||
return colorPoints;
|
||||
}
|
||||
|
||||
protected PreparedAlphaPoint[] prepareAlphaPoints(BoundedTableModel model,
|
||||
int positionColumn, int alphaColumn) {
|
||||
protected PreparedAlphaPoint[] prepareAlphaPoints(BoundedTableModel model,
|
||||
int positionColumn, int alphaColumn) {
|
||||
|
||||
int numPoints = model.getRowCount();
|
||||
int numPoints = model.getRowCount();
|
||||
|
||||
if (numPoints > alphaPoints.length) {
|
||||
alphaPoints = new PreparedAlphaPoint[numPoints * 2];
|
||||
for (int i = 0; i < alphaPoints.length; i++)
|
||||
alphaPoints[i] = new PreparedAlphaPoint();
|
||||
}
|
||||
if (numPoints > alphaPoints.length) {
|
||||
alphaPoints = new PreparedAlphaPoint[numPoints * 2];
|
||||
for (int i = 0; i < alphaPoints.length; i++)
|
||||
alphaPoints[i] = new PreparedAlphaPoint();
|
||||
}
|
||||
|
||||
for (int i = 0; i < numPoints; i++) {
|
||||
PreparedAlphaPoint p = alphaPoints[i];
|
||||
float f = ((Number) model.getValueAt(i, alphaColumn)).floatValue();
|
||||
p.position = ((Number) model.getValueAt(i, positionColumn))
|
||||
.intValue();
|
||||
p.alpha = f;
|
||||
}
|
||||
for (int i = 0; i < numPoints; i++) {
|
||||
PreparedAlphaPoint p = alphaPoints[i];
|
||||
float f = ((Number) model.getValueAt(i, alphaColumn)).floatValue();
|
||||
p.position = ((Number) model.getValueAt(i, positionColumn))
|
||||
.intValue();
|
||||
p.alpha = f;
|
||||
}
|
||||
|
||||
Arrays.sort(alphaPoints, 0, numPoints, PreparedAlphaPoint.comparator);
|
||||
Arrays.sort(alphaPoints, 0, numPoints, PreparedAlphaPoint.comparator);
|
||||
|
||||
return alphaPoints;
|
||||
}
|
||||
return alphaPoints;
|
||||
}
|
||||
|
||||
protected static class PreparedColorPoint {
|
||||
public static final Comparator comparator = new PtComparator();
|
||||
protected static class PreparedColorPoint {
|
||||
public static final Comparator comparator = new PtComparator();
|
||||
|
||||
public int r, g, b;
|
||||
public int r, g, b;
|
||||
|
||||
public int position;
|
||||
public int position;
|
||||
|
||||
public PreparedColorPoint() {
|
||||
}
|
||||
public PreparedColorPoint() {
|
||||
}
|
||||
|
||||
private static class PtComparator implements Comparator {
|
||||
public int compare(Object o1, Object o2) {
|
||||
PreparedColorPoint cp1 = (PreparedColorPoint) o1;
|
||||
PreparedColorPoint cp2 = (PreparedColorPoint) o2;
|
||||
if (cp1.position < cp2.position)
|
||||
return -1;
|
||||
if (cp1.position > cp2.position)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static class PtComparator implements Comparator {
|
||||
public int compare(Object o1, Object o2) {
|
||||
PreparedColorPoint cp1 = (PreparedColorPoint) o1;
|
||||
PreparedColorPoint cp2 = (PreparedColorPoint) o2;
|
||||
if (cp1.position < cp2.position)
|
||||
return -1;
|
||||
if (cp1.position > cp2.position)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static class PreparedAlphaPoint {
|
||||
public static final Comparator comparator = new PtComparator();
|
||||
protected static class PreparedAlphaPoint {
|
||||
public static final Comparator comparator = new PtComparator();
|
||||
|
||||
public float alpha;
|
||||
public float alpha;
|
||||
|
||||
public int position;
|
||||
public int position;
|
||||
|
||||
public PreparedAlphaPoint() {
|
||||
}
|
||||
public PreparedAlphaPoint() {
|
||||
}
|
||||
|
||||
private static class PtComparator implements Comparator {
|
||||
public int compare(Object o1, Object o2) {
|
||||
PreparedColorPoint cp1 = (PreparedColorPoint) o1;
|
||||
PreparedColorPoint cp2 = (PreparedColorPoint) o2;
|
||||
if (cp1.position < cp2.position)
|
||||
return -1;
|
||||
if (cp1.position > cp2.position)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static class PtComparator implements Comparator {
|
||||
public int compare(Object o1, Object o2) {
|
||||
PreparedColorPoint cp1 = (PreparedColorPoint) o1;
|
||||
PreparedColorPoint cp2 = (PreparedColorPoint) o2;
|
||||
if (cp1.position < cp2.position)
|
||||
return -1;
|
||||
if (cp1.position > cp2.position)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,165 +18,165 @@ import com.michaelbaranov.microba.gradient.ui.GradientUI;
|
||||
|
||||
public class BasicGradientUI extends GradientUI {
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new BasicGradientUI();
|
||||
}
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new BasicGradientUI();
|
||||
}
|
||||
|
||||
public void installUI(JComponent component) {
|
||||
installListeners((GradientBar) component);
|
||||
}
|
||||
public void installUI(JComponent component) {
|
||||
installListeners((GradientBar) component);
|
||||
}
|
||||
|
||||
public void uninstallUI(JComponent component) {
|
||||
uninstallListeners((GradientBar) component);
|
||||
}
|
||||
public void uninstallUI(JComponent component) {
|
||||
uninstallListeners((GradientBar) component);
|
||||
}
|
||||
|
||||
protected void installListeners(GradientBar gradient) {
|
||||
GradientListener listener = createListener(gradient);
|
||||
protected void installListeners(GradientBar gradient) {
|
||||
GradientListener listener = createListener(gradient);
|
||||
|
||||
if (gradient.getDataModel() != null)
|
||||
gradient.getDataModel().addTableModelListener(listener);
|
||||
gradient.addPropertyChangeListener(listener);
|
||||
}
|
||||
if (gradient.getDataModel() != null)
|
||||
gradient.getDataModel().addTableModelListener(listener);
|
||||
gradient.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
protected void uninstallListeners(GradientBar gradient) {
|
||||
GradientListener listener = lookupListsner(gradient);
|
||||
if (listener != null) {
|
||||
if (gradient.getDataModel() != null)
|
||||
gradient.getDataModel().removeTableModelListener(listener);
|
||||
gradient.removePropertyChangeListener(listener);
|
||||
}
|
||||
protected void uninstallListeners(GradientBar gradient) {
|
||||
GradientListener listener = lookupListsner(gradient);
|
||||
if (listener != null) {
|
||||
if (gradient.getDataModel() != null)
|
||||
gradient.getDataModel().removeTableModelListener(listener);
|
||||
gradient.removePropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected GradientListener lookupListsner(GradientBar gradient) {
|
||||
PropertyChangeListener[] listeners = gradient
|
||||
.getPropertyChangeListeners();
|
||||
protected GradientListener lookupListsner(GradientBar gradient) {
|
||||
PropertyChangeListener[] listeners = gradient
|
||||
.getPropertyChangeListeners();
|
||||
|
||||
if (listeners != null) {
|
||||
for (int counter = 0; counter < listeners.length; counter++) {
|
||||
if (listeners[counter] instanceof GradientListener) {
|
||||
return (GradientListener) listeners[counter];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (listeners != null) {
|
||||
for (int counter = 0; counter < listeners.length; counter++) {
|
||||
if (listeners[counter] instanceof GradientListener) {
|
||||
return (GradientListener) listeners[counter];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected GradientListener createListener(GradientBar gradient) {
|
||||
return new GradientListener(this, gradient);
|
||||
}
|
||||
protected GradientListener createListener(GradientBar gradient) {
|
||||
return new GradientListener(this, gradient);
|
||||
}
|
||||
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
GradientBar gradient = (GradientBar) c;
|
||||
GradientBar gradient = (GradientBar) c;
|
||||
|
||||
calculateViewRect(gradient);
|
||||
calculateViewRect(gradient);
|
||||
|
||||
BoundedTableModel colorModel = gradient.getDataModel();
|
||||
BoundedTableModel alphaModel = gradient.getAlphaModel();
|
||||
BoundedTableModel colorModel = gradient.getDataModel();
|
||||
BoundedTableModel alphaModel = gradient.getAlphaModel();
|
||||
|
||||
if (colorModel == null)
|
||||
return;
|
||||
if (colorModel == null)
|
||||
return;
|
||||
|
||||
// TODO: alpha support
|
||||
// TODO: alpha support
|
||||
|
||||
int numColorPoints = colorModel.getRowCount();
|
||||
int numAlphaPoints = alphaModel == null ? 0 : alphaModel.getRowCount();
|
||||
int numColorPoints = colorModel.getRowCount();
|
||||
int numAlphaPoints = alphaModel == null ? 0 : alphaModel.getRowCount();
|
||||
|
||||
int colorPositionColumn = gradient.getColorPositionColumn();
|
||||
int colorColumn = gradient.getColorColumn();
|
||||
int colorPositionColumn = gradient.getColorPositionColumn();
|
||||
int colorColumn = gradient.getColorColumn();
|
||||
|
||||
int alphaPositionColumn = gradient.getAlphaPositionColumn();
|
||||
int alphaColumn = gradient.getAlphaColumn();
|
||||
int alphaPositionColumn = gradient.getAlphaPositionColumn();
|
||||
int alphaColumn = gradient.getAlphaColumn();
|
||||
|
||||
switch (numColorPoints) {
|
||||
case 0:
|
||||
// draw checkers?
|
||||
// g.drawString("no data", viewRect.x, viewRect.y +
|
||||
// viewRect.height);
|
||||
break;
|
||||
case 1:
|
||||
g.setColor((Color) colorModel.getValueAt(0, colorColumn));
|
||||
g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
|
||||
break;
|
||||
default:
|
||||
PreparedColorPoint pts[] = prepareColorPoints(colorModel,
|
||||
colorPositionColumn, colorColumn);
|
||||
// PreparedAlphaPoint apts[] = prepareAlphaPoints(alphaModel,
|
||||
// colorPositionColumn, colorColumn);
|
||||
switch (numColorPoints) {
|
||||
case 0:
|
||||
// draw checkers?
|
||||
// g.drawString("no data", viewRect.x, viewRect.y +
|
||||
// viewRect.height);
|
||||
break;
|
||||
case 1:
|
||||
g.setColor((Color) colorModel.getValueAt(0, colorColumn));
|
||||
g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
|
||||
break;
|
||||
default:
|
||||
PreparedColorPoint pts[] = prepareColorPoints(colorModel,
|
||||
colorPositionColumn, colorColumn);
|
||||
// PreparedAlphaPoint apts[] = prepareAlphaPoints(alphaModel,
|
||||
// colorPositionColumn, colorColumn);
|
||||
|
||||
int range = colorModel.getUpperBound() - colorModel.getLowerBound();
|
||||
boolean isHorizontal = gradient.getOrientation() == SwingConstants.HORIZONTAL;
|
||||
int range = colorModel.getUpperBound() - colorModel.getLowerBound();
|
||||
boolean isHorizontal = gradient.getOrientation() == SwingConstants.HORIZONTAL;
|
||||
|
||||
for (int i = 0; i < numColorPoints - 1; i++) {
|
||||
PreparedColorPoint p0 = pts[i];
|
||||
PreparedColorPoint p1 = pts[i + 1];
|
||||
for (int i = 0; i < numColorPoints - 1; i++) {
|
||||
PreparedColorPoint p0 = pts[i];
|
||||
PreparedColorPoint p1 = pts[i + 1];
|
||||
|
||||
int pos0 = p0.position - colorModel.getLowerBound();
|
||||
int pos1 = p1.position - colorModel.getLowerBound();
|
||||
int pos0 = p0.position - colorModel.getLowerBound();
|
||||
int pos1 = p1.position - colorModel.getLowerBound();
|
||||
|
||||
int pixPos0;
|
||||
int pixPos1;
|
||||
if (isHorizontal) {
|
||||
pixPos0 = viewRect.x + viewRect.width * pos0 / range;
|
||||
pixPos1 = viewRect.x + viewRect.width * pos1 / range;
|
||||
} else {
|
||||
pixPos0 = viewRect.y + viewRect.height * pos0 / range;
|
||||
pixPos1 = viewRect.y + viewRect.height * pos1 / range;
|
||||
}
|
||||
int pixPos0;
|
||||
int pixPos1;
|
||||
if (isHorizontal) {
|
||||
pixPos0 = viewRect.x + viewRect.width * pos0 / range;
|
||||
pixPos1 = viewRect.x + viewRect.width * pos1 / range;
|
||||
} else {
|
||||
pixPos0 = viewRect.y + viewRect.height * pos0 / range;
|
||||
pixPos1 = viewRect.y + viewRect.height * pos1 / range;
|
||||
}
|
||||
|
||||
int pixDist = pixPos1 - pixPos0;
|
||||
int pixDist = pixPos1 - pixPos0;
|
||||
|
||||
for (int t = pixPos0; t < pixPos1; t++) {
|
||||
Color cc = interpolate(p0, p1, pixDist, t - pixPos0);
|
||||
g2.setColor(cc);
|
||||
if (isHorizontal)
|
||||
g2.drawLine(t, viewRect.y, t, viewRect.y
|
||||
+ viewRect.height);
|
||||
else
|
||||
g2.drawLine(viewRect.x, t, viewRect.x + viewRect.width,
|
||||
t);
|
||||
for (int t = pixPos0; t < pixPos1; t++) {
|
||||
Color cc = interpolate(p0, p1, pixDist, t - pixPos0);
|
||||
g2.setColor(cc);
|
||||
if (isHorizontal)
|
||||
g2.drawLine(t, viewRect.y, t, viewRect.y
|
||||
+ viewRect.height);
|
||||
else
|
||||
g2.drawLine(viewRect.x, t, viewRect.x + viewRect.width,
|
||||
t);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Color interpolate(PreparedColorPoint p0, PreparedColorPoint p1,
|
||||
int pixDist, int t) {
|
||||
int r = p0.r + (p1.r - p0.r) * t / pixDist;
|
||||
int g = p0.g + (p1.g - p0.g) * t / pixDist;
|
||||
int b = p0.b + (p1.b - p0.b) * t / pixDist;
|
||||
return new Color(r, g, b);
|
||||
}
|
||||
private Color interpolate(PreparedColorPoint p0, PreparedColorPoint p1,
|
||||
int pixDist, int t) {
|
||||
int r = p0.r + (p1.r - p0.r) * t / pixDist;
|
||||
int g = p0.g + (p1.g - p0.g) * t / pixDist;
|
||||
int b = p0.b + (p1.b - p0.b) * t / pixDist;
|
||||
return new Color(r, g, b);
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize(JComponent c) {
|
||||
return new Dimension(1, 1);
|
||||
}
|
||||
public Dimension getMinimumSize(JComponent c) {
|
||||
return new Dimension(1, 1);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
|
||||
GradientBar gradient = (GradientBar) c;
|
||||
BoundedTableModel dataModel = gradient.getDataModel();
|
||||
Insets ins = gradient.getInsets();
|
||||
GradientBar gradient = (GradientBar) c;
|
||||
BoundedTableModel dataModel = gradient.getDataModel();
|
||||
Insets ins = gradient.getInsets();
|
||||
|
||||
int r;
|
||||
if (dataModel == null)
|
||||
r = 1;
|
||||
else
|
||||
r = dataModel.getUpperBound() - dataModel.getLowerBound();
|
||||
int r;
|
||||
if (dataModel == null)
|
||||
r = 1;
|
||||
else
|
||||
r = dataModel.getUpperBound() - dataModel.getLowerBound();
|
||||
|
||||
if (gradient.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
return new Dimension((r) * 2 + ins.left + ins.right + 1,
|
||||
PREF_BAR_HEIGHT + ins.top + ins.bottom + 1);
|
||||
else
|
||||
return new Dimension(PREF_BAR_HEIGHT + ins.top + ins.bottom + 1,
|
||||
(r) * 2 + ins.left + ins.right + 1);
|
||||
if (gradient.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
return new Dimension((r) * 2 + ins.left + ins.right + 1,
|
||||
PREF_BAR_HEIGHT + ins.top + ins.bottom + 1);
|
||||
else
|
||||
return new Dimension(PREF_BAR_HEIGHT + ins.top + ins.bottom + 1,
|
||||
(r) * 2 + ins.left + ins.right + 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,107 +21,107 @@ import com.michaelbaranov.microba.marker.MarkerMutationModel;
|
||||
*
|
||||
*/
|
||||
public class DefaultGradientEditorModel extends
|
||||
AbstractBoundedTableModelWithSelection implements MarkerMutationModel {
|
||||
AbstractBoundedTableModelWithSelection implements MarkerMutationModel {
|
||||
|
||||
public static final int POSITION_COLUMN = 0;
|
||||
public static final int POSITION_COLUMN = 0;
|
||||
|
||||
public static final int COLOR_COLUMN = 1;
|
||||
public static final int COLOR_COLUMN = 1;
|
||||
|
||||
protected List position = new ArrayList(32);
|
||||
protected List position = new ArrayList(32);
|
||||
|
||||
protected List color = new ArrayList(32);
|
||||
protected List color = new ArrayList(32);
|
||||
|
||||
public DefaultGradientEditorModel() {
|
||||
super();
|
||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
public DefaultGradientEditorModel() {
|
||||
super();
|
||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
|
||||
position.add(new Integer(0));
|
||||
color.add(Color.BLACK);
|
||||
position.add(new Integer(0));
|
||||
color.add(Color.BLACK);
|
||||
|
||||
position.add(new Integer(255));
|
||||
color.add(Color.WHITE);
|
||||
position.add(new Integer(255));
|
||||
color.add(Color.WHITE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void removeMarkerAtIndex(int index) {
|
||||
if (isSelectedIndex(index)) {
|
||||
removeSelectionInterval(index, index);
|
||||
}
|
||||
position.remove(index);
|
||||
color.remove(index);
|
||||
fireTableRowsDeleted(index, index);
|
||||
public void removeMarkerAtIndex(int index) {
|
||||
if (isSelectedIndex(index)) {
|
||||
removeSelectionInterval(index, index);
|
||||
}
|
||||
position.remove(index);
|
||||
color.remove(index);
|
||||
fireTableRowsDeleted(index, index);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public int addMarkAtPosition(int pos) {
|
||||
position.add(new Integer(pos));
|
||||
color.add(new Color((float) Math.random(), (float) Math.random(),
|
||||
(float) Math.random()));
|
||||
int index = position.size() - 1;
|
||||
fireTableRowsInserted(index, index);
|
||||
return index;
|
||||
}
|
||||
public int addMarkAtPosition(int pos) {
|
||||
position.add(new Integer(pos));
|
||||
color.add(new Color((float) Math.random(), (float) Math.random(),
|
||||
(float) Math.random()));
|
||||
int index = position.size() - 1;
|
||||
fireTableRowsInserted(index, index);
|
||||
return index;
|
||||
}
|
||||
|
||||
public int getLowerBound() {
|
||||
return 0;
|
||||
}
|
||||
public int getLowerBound() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getUpperBound() {
|
||||
return 255;
|
||||
}
|
||||
public int getUpperBound() {
|
||||
return 255;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return position.size();
|
||||
}
|
||||
public int getRowCount() {
|
||||
return position.size();
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
}
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case POSITION_COLUMN:
|
||||
return Integer.class;
|
||||
case COLOR_COLUMN:
|
||||
return Color.class;
|
||||
}
|
||||
return super.getColumnClass(columnIndex);
|
||||
}
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case POSITION_COLUMN:
|
||||
return Integer.class;
|
||||
case COLOR_COLUMN:
|
||||
return Color.class;
|
||||
}
|
||||
return super.getColumnClass(columnIndex);
|
||||
}
|
||||
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case POSITION_COLUMN:
|
||||
return position.get(rowIndex);
|
||||
case COLOR_COLUMN:
|
||||
return color.get(rowIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case POSITION_COLUMN:
|
||||
return position.get(rowIndex);
|
||||
case COLOR_COLUMN:
|
||||
return color.get(rowIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case POSITION_COLUMN:
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case POSITION_COLUMN:
|
||||
|
||||
for (int i = 0; i < position.size(); i++)
|
||||
if (rowIndex != i && aValue.equals(position.get(i))) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < position.size(); i++)
|
||||
if (rowIndex != i && aValue.equals(position.get(i))) {
|
||||
return;
|
||||
}
|
||||
|
||||
position.remove(rowIndex);
|
||||
position.add(rowIndex, aValue);
|
||||
fireTableCellUpdated(rowIndex, columnIndex);
|
||||
break;
|
||||
position.remove(rowIndex);
|
||||
position.add(rowIndex, aValue);
|
||||
fireTableCellUpdated(rowIndex, columnIndex);
|
||||
break;
|
||||
|
||||
case COLOR_COLUMN:
|
||||
color.remove(rowIndex);
|
||||
color.add(rowIndex, (Color) aValue);
|
||||
fireTableCellUpdated(rowIndex, columnIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
case COLOR_COLUMN:
|
||||
color.remove(rowIndex);
|
||||
color.add(rowIndex, (Color) aValue);
|
||||
fireTableCellUpdated(rowIndex, columnIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
// protecting first 2 rows (first and last marker) from being moved
|
||||
return !(columnIndex == POSITION_COLUMN && rowIndex < 2);
|
||||
}
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
// protecting first 2 rows (first and last marker) from being moved
|
||||
return !(columnIndex == POSITION_COLUMN && rowIndex < 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,152 +26,152 @@ import com.michaelbaranov.microba.marker.MarkerMutationModel;
|
||||
*/
|
||||
public class GradientEditor extends GradientBar {
|
||||
|
||||
/**
|
||||
* The name of a "colorSelectionModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_COLOR_SELECTION_MODEL = "colorSelectionModel";
|
||||
/**
|
||||
* The name of a "colorSelectionModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_COLOR_SELECTION_MODEL = "colorSelectionModel";
|
||||
|
||||
/**
|
||||
* The name of a "alphaSelectionModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_ALPHA_SELECTION_MODEL = "alphaSelectionModel";
|
||||
/**
|
||||
* The name of a "alphaSelectionModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_ALPHA_SELECTION_MODEL = "alphaSelectionModel";
|
||||
|
||||
/**
|
||||
* The name of a "colorMutationModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_COLOR_MUTATION_MODEL = "colorMutationModel";
|
||||
/**
|
||||
* The name of a "colorMutationModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_COLOR_MUTATION_MODEL = "colorMutationModel";
|
||||
|
||||
/**
|
||||
* The name of a "alphaMutationModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_ALPHA_MUTATION_MODEL = "alphaMutationModel";
|
||||
/**
|
||||
* The name of a "alphaMutationModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_ALPHA_MUTATION_MODEL = "alphaMutationModel";
|
||||
|
||||
private static final String uiClassID = "microba.GradientEditorUI";
|
||||
private static final String uiClassID = "microba.GradientEditorUI";
|
||||
|
||||
private ListSelectionModel colorSelectionModel = null;
|
||||
private ListSelectionModel colorSelectionModel = null;
|
||||
|
||||
private ListSelectionModel alphaSelectionModel = null;
|
||||
private ListSelectionModel alphaSelectionModel = null;
|
||||
|
||||
private MarkerMutationModel colorMutationModel = null;
|
||||
private MarkerMutationModel colorMutationModel = null;
|
||||
|
||||
private MarkerMutationModel alphaMutationModel = null;
|
||||
private MarkerMutationModel alphaMutationModel = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public GradientEditor() {
|
||||
super();
|
||||
DefaultGradientEditorModel defaultGradientEditorModel = new DefaultGradientEditorModel();
|
||||
dataModel = defaultGradientEditorModel;
|
||||
colorSelectionModel = defaultGradientEditorModel;
|
||||
colorMutationModel = defaultGradientEditorModel;
|
||||
setFocusable(true);
|
||||
updateUI();
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public GradientEditor() {
|
||||
super();
|
||||
DefaultGradientEditorModel defaultGradientEditorModel = new DefaultGradientEditorModel();
|
||||
dataModel = defaultGradientEditorModel;
|
||||
colorSelectionModel = defaultGradientEditorModel;
|
||||
colorMutationModel = defaultGradientEditorModel;
|
||||
setFocusable(true);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
public String getUIClassID() {
|
||||
return uiClassID;
|
||||
}
|
||||
public String getUIClassID() {
|
||||
return uiClassID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Regturns the current color mutation model.
|
||||
*
|
||||
* @return current color mutation model
|
||||
* @see #setColorMutationModel(MarkerMutationModel)
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public MarkerMutationModel getColorMutationModel() {
|
||||
return colorMutationModel;
|
||||
}
|
||||
/**
|
||||
* Regturns the current color mutation model.
|
||||
*
|
||||
* @return current color mutation model
|
||||
* @see #setColorMutationModel(MarkerMutationModel)
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public MarkerMutationModel getColorMutationModel() {
|
||||
return colorMutationModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces current color mutation model with given one.
|
||||
*
|
||||
* @param mutationModel
|
||||
* new mutation model. May be <code>null<code>.
|
||||
* @see #getColorMutationModel()
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public void setColorMutationModel(MarkerMutationModel mutationModel) {
|
||||
MarkerMutationModel oldMutationModel = this.colorMutationModel;
|
||||
this.colorMutationModel = mutationModel;
|
||||
firePropertyChange(PROPERTY_COLOR_MUTATION_MODEL, oldMutationModel, mutationModel);
|
||||
}
|
||||
/**
|
||||
* Replaces current color mutation model with given one.
|
||||
*
|
||||
* @param mutationModel
|
||||
* new mutation model. May be <code>null<code>.
|
||||
* @see #getColorMutationModel()
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public void setColorMutationModel(MarkerMutationModel mutationModel) {
|
||||
MarkerMutationModel oldMutationModel = this.colorMutationModel;
|
||||
this.colorMutationModel = mutationModel;
|
||||
firePropertyChange(PROPERTY_COLOR_MUTATION_MODEL, oldMutationModel, mutationModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current color selection model.
|
||||
*
|
||||
* @return current color selection model.
|
||||
* @see #setColorSelectionModel(ListSelectionModel)
|
||||
*/
|
||||
public ListSelectionModel getColorSelectionModel() {
|
||||
return colorSelectionModel;
|
||||
}
|
||||
/**
|
||||
* Returns current color selection model.
|
||||
*
|
||||
* @return current color selection model.
|
||||
* @see #setColorSelectionModel(ListSelectionModel)
|
||||
*/
|
||||
public ListSelectionModel getColorSelectionModel() {
|
||||
return colorSelectionModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces current color selection model with given one. This
|
||||
* implementation uses
|
||||
* <code>{@link ListSelectionModel#getLeadSelectionIndex()}</code> to
|
||||
* determine selected marker.
|
||||
*
|
||||
* @param selectionModel
|
||||
* new selection model. May be <code>null<code>.
|
||||
*
|
||||
* @see #getColorSelectionModel()
|
||||
*/
|
||||
public void setColorSelectionModel(ListSelectionModel selectionModel) {
|
||||
ListSelectionModel oldSelectionModel = this.colorSelectionModel;
|
||||
this.colorSelectionModel = selectionModel;
|
||||
firePropertyChange(PROPERTY_COLOR_SELECTION_MODEL, oldSelectionModel,
|
||||
selectionModel);
|
||||
}
|
||||
/**
|
||||
* Replaces current color selection model with given one. This
|
||||
* implementation uses
|
||||
* <code>{@link ListSelectionModel#getLeadSelectionIndex()}</code> to
|
||||
* determine selected marker.
|
||||
*
|
||||
* @param selectionModel
|
||||
* new selection model. May be <code>null<code>.
|
||||
*
|
||||
* @see #getColorSelectionModel()
|
||||
*/
|
||||
public void setColorSelectionModel(ListSelectionModel selectionModel) {
|
||||
ListSelectionModel oldSelectionModel = this.colorSelectionModel;
|
||||
this.colorSelectionModel = selectionModel;
|
||||
firePropertyChange(PROPERTY_COLOR_SELECTION_MODEL, oldSelectionModel,
|
||||
selectionModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current alpha selection model.
|
||||
*
|
||||
* @return current alpha selection model.
|
||||
* @see #setAlphaSelectionModel(ListSelectionModel)
|
||||
*/
|
||||
public ListSelectionModel getAlphaSelectionModel() {
|
||||
return alphaSelectionModel;
|
||||
}
|
||||
/**
|
||||
* Returns current alpha selection model.
|
||||
*
|
||||
* @return current alpha selection model.
|
||||
* @see #setAlphaSelectionModel(ListSelectionModel)
|
||||
*/
|
||||
public ListSelectionModel getAlphaSelectionModel() {
|
||||
return alphaSelectionModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces current alpha selection model with given one. This
|
||||
* implementation uses
|
||||
* <code>{@link ListSelectionModel#getLeadSelectionIndex()}</code> to
|
||||
* determine selected marker.
|
||||
*
|
||||
* @param selectionModel
|
||||
* new selection model. May be <code>null<code>.
|
||||
*
|
||||
* @see #getAlphaSelectionModel()
|
||||
*/
|
||||
public void setAlphaSelectionModel(ListSelectionModel selectionModel) {
|
||||
this.alphaSelectionModel = selectionModel;
|
||||
}
|
||||
/**
|
||||
* Replaces current alpha selection model with given one. This
|
||||
* implementation uses
|
||||
* <code>{@link ListSelectionModel#getLeadSelectionIndex()}</code> to
|
||||
* determine selected marker.
|
||||
*
|
||||
* @param selectionModel
|
||||
* new selection model. May be <code>null<code>.
|
||||
*
|
||||
* @see #getAlphaSelectionModel()
|
||||
*/
|
||||
public void setAlphaSelectionModel(ListSelectionModel selectionModel) {
|
||||
this.alphaSelectionModel = selectionModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Regturns the current alpha mutation model.
|
||||
*
|
||||
* @return current alpha mutation model
|
||||
* @see #setAlphaMutationModel(MarkerMutationModel)
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public MarkerMutationModel getAlphaMutationModel() {
|
||||
return alphaMutationModel;
|
||||
}
|
||||
/**
|
||||
* Regturns the current alpha mutation model.
|
||||
*
|
||||
* @return current alpha mutation model
|
||||
* @see #setAlphaMutationModel(MarkerMutationModel)
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public MarkerMutationModel getAlphaMutationModel() {
|
||||
return alphaMutationModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces current alpha mutation model with given one.
|
||||
*
|
||||
* @param mutationModel
|
||||
* new mutation model. May be <code>null<code>.
|
||||
* @see #getAlphaMutationModel()
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public void setAlphaMutationModel(MarkerMutationModel mutationModel) {
|
||||
this.alphaMutationModel = mutationModel;
|
||||
}
|
||||
/**
|
||||
* Replaces current alpha mutation model with given one.
|
||||
*
|
||||
* @param mutationModel
|
||||
* new mutation model. May be <code>null<code>.
|
||||
* @see #getAlphaMutationModel()
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public void setAlphaMutationModel(MarkerMutationModel mutationModel) {
|
||||
this.alphaMutationModel = mutationModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,47 +14,47 @@ import com.michaelbaranov.microba.marker.MarkerBar;
|
||||
|
||||
public class GradientEditorLayout implements LayoutManager {
|
||||
|
||||
private MarkerBar bar;
|
||||
private MarkerBar bar;
|
||||
|
||||
private GradientBar gradient;
|
||||
private GradientBar gradient;
|
||||
|
||||
public GradientEditorLayout(MarkerBar bar, GradientBar gradient) {
|
||||
this.bar = bar;
|
||||
this.gradient = gradient;
|
||||
}
|
||||
public GradientEditorLayout(MarkerBar bar, GradientBar gradient) {
|
||||
this.bar = bar;
|
||||
this.gradient = gradient;
|
||||
}
|
||||
|
||||
public void addLayoutComponent(String name, Component comp) {
|
||||
}
|
||||
public void addLayoutComponent(String name, Component comp) {
|
||||
}
|
||||
|
||||
public void removeLayoutComponent(Component comp) {
|
||||
}
|
||||
public void removeLayoutComponent(Component comp) {
|
||||
}
|
||||
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
return parent.getPreferredSize();
|
||||
}
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
return parent.getPreferredSize();
|
||||
}
|
||||
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
return parent.getMinimumSize();
|
||||
}
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
return parent.getMinimumSize();
|
||||
}
|
||||
|
||||
public void layoutContainer(Container parent) {
|
||||
GradientEditor e = (GradientEditor) parent;
|
||||
Insets i = parent.getInsets();
|
||||
int gap = bar.getMarkerSideGap();
|
||||
if (e.getOrientation() == SwingConstants.HORIZONTAL) {
|
||||
bar.setBounds(i.left, i.top, parent.getWidth() - i.left - i.right,
|
||||
bar.getPreferredSize().height);
|
||||
gradient.setBounds(i.left + gap, bar.getBounds().y
|
||||
+ bar.getBounds().height, parent.getWidth() - i.left
|
||||
- i.right - gap - gap, parent.getHeight() - i.top
|
||||
- i.bottom - bar.getHeight());
|
||||
} else {
|
||||
gradient.setBounds(i.left, i.top+gap,
|
||||
gradient.getPreferredSize().width,parent.getHeight() - i.top - i.bottom-gap-gap);
|
||||
bar.setBounds(gradient.getBounds().x+gradient.getBounds().width ,i.top,
|
||||
bar.getPreferredSize().width,gradient.getBounds().height+gap+gap);
|
||||
|
||||
}
|
||||
}
|
||||
public void layoutContainer(Container parent) {
|
||||
GradientEditor e = (GradientEditor) parent;
|
||||
Insets i = parent.getInsets();
|
||||
int gap = bar.getMarkerSideGap();
|
||||
if (e.getOrientation() == SwingConstants.HORIZONTAL) {
|
||||
bar.setBounds(i.left, i.top, parent.getWidth() - i.left - i.right,
|
||||
bar.getPreferredSize().height);
|
||||
gradient.setBounds(i.left + gap, bar.getBounds().y
|
||||
+ bar.getBounds().height, parent.getWidth() - i.left
|
||||
- i.right - gap - gap, parent.getHeight() - i.top
|
||||
- i.bottom - bar.getHeight());
|
||||
} else {
|
||||
gradient.setBounds(i.left, i.top+gap,
|
||||
gradient.getPreferredSize().width,parent.getHeight() - i.top - i.bottom-gap-gap);
|
||||
bar.setBounds(gradient.getBounds().x+gradient.getBounds().width ,i.top,
|
||||
bar.getPreferredSize().width,gradient.getBounds().height+gap+gap);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,21 +7,21 @@ import com.michaelbaranov.microba.gradienteditor.GradientEditor;
|
||||
|
||||
public class GradientEditorListener implements PropertyChangeListener {
|
||||
|
||||
private GradientEditorUI ui;
|
||||
private GradientEditorUI ui;
|
||||
|
||||
private GradientEditor editor;
|
||||
private GradientEditor editor;
|
||||
|
||||
public GradientEditorListener(GradientEditor editor, GradientEditorUI ui) {
|
||||
super();
|
||||
this.editor = editor;
|
||||
this.ui = ui;
|
||||
}
|
||||
public GradientEditorListener(GradientEditor editor, GradientEditorUI ui) {
|
||||
super();
|
||||
this.editor = editor;
|
||||
this.ui = ui;
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (GradientEditor.PROPERTY_DATA_MODEL.equals(evt.getPropertyName())) {
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (GradientEditor.PROPERTY_DATA_MODEL.equals(evt.getPropertyName())) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,153 +20,153 @@ import com.michaelbaranov.microba.marker.MarkerMutationModel;
|
||||
|
||||
public class BasicGradientEditorUI extends GradientEditorUI {
|
||||
|
||||
protected GradientBar gradientBar;
|
||||
protected GradientBar gradientBar;
|
||||
|
||||
protected MarkerBar colorBar;
|
||||
protected MarkerBar colorBar;
|
||||
|
||||
protected MarkerBar alphaBar;
|
||||
protected MarkerBar alphaBar;
|
||||
|
||||
private GradientEditor gradient;
|
||||
private GradientEditor gradient;
|
||||
|
||||
private GradientEditorListener editorListener;
|
||||
private GradientEditorListener editorListener;
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new BasicGradientEditorUI();
|
||||
}
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new BasicGradientEditorUI();
|
||||
}
|
||||
|
||||
public void installUI(JComponent component) {
|
||||
gradient = (GradientEditor) component;
|
||||
editorListener = new GradientEditorListener();
|
||||
createAndConfigureSubcomponents();
|
||||
installSubcomponents();
|
||||
installListeners();
|
||||
gradient.revalidate();
|
||||
}
|
||||
public void installUI(JComponent component) {
|
||||
gradient = (GradientEditor) component;
|
||||
editorListener = new GradientEditorListener();
|
||||
createAndConfigureSubcomponents();
|
||||
installSubcomponents();
|
||||
installListeners();
|
||||
gradient.revalidate();
|
||||
}
|
||||
|
||||
public void uninstallUI(JComponent component) {
|
||||
// JGradient gradient = (JGradient) component;
|
||||
uninstallSubcomponents();
|
||||
uninstallListeners();
|
||||
}
|
||||
public void uninstallUI(JComponent component) {
|
||||
// JGradient gradient = (JGradient) component;
|
||||
uninstallSubcomponents();
|
||||
uninstallListeners();
|
||||
}
|
||||
|
||||
protected void installSubcomponents() {
|
||||
gradient.setLayout(new GradientEditorLayout(colorBar, gradientBar));
|
||||
gradient.add(colorBar);
|
||||
gradient.add(gradientBar);
|
||||
}
|
||||
protected void installSubcomponents() {
|
||||
gradient.setLayout(new GradientEditorLayout(colorBar, gradientBar));
|
||||
gradient.add(colorBar);
|
||||
gradient.add(gradientBar);
|
||||
}
|
||||
|
||||
protected void uninstallSubcomponents() {
|
||||
gradient.setLayout(new FlowLayout());
|
||||
gradient.remove(colorBar);
|
||||
gradient.remove(gradientBar);
|
||||
}
|
||||
protected void uninstallSubcomponents() {
|
||||
gradient.setLayout(new FlowLayout());
|
||||
gradient.remove(colorBar);
|
||||
gradient.remove(gradientBar);
|
||||
}
|
||||
|
||||
private void installListeners() {
|
||||
gradient.addPropertyChangeListener(editorListener);
|
||||
}
|
||||
private void installListeners() {
|
||||
gradient.addPropertyChangeListener(editorListener);
|
||||
}
|
||||
|
||||
private void uninstallListeners() {
|
||||
gradient.removePropertyChangeListener(editorListener);
|
||||
}
|
||||
private void uninstallListeners() {
|
||||
gradient.removePropertyChangeListener(editorListener);
|
||||
}
|
||||
|
||||
private void createAndConfigureSubcomponents() {
|
||||
gradientBar = new GradientBar(gradient.getDataModel());
|
||||
gradientBar.setOrientation(gradient.getOrientation());
|
||||
gradientBar.setColorPositionColumn(gradient.getColorPositionColumn());
|
||||
gradientBar.setColorColumn(gradient.getColorColumn());
|
||||
private void createAndConfigureSubcomponents() {
|
||||
gradientBar = new GradientBar(gradient.getDataModel());
|
||||
gradientBar.setOrientation(gradient.getOrientation());
|
||||
gradientBar.setColorPositionColumn(gradient.getColorPositionColumn());
|
||||
gradientBar.setColorColumn(gradient.getColorColumn());
|
||||
|
||||
colorBar = new MarkerBar(gradient.getDataModel(), gradient
|
||||
.getColorSelectionModel());
|
||||
colorBar.setOrientation(gradient.getOrientation());
|
||||
colorBar.setMutationModel(gradient.getColorMutationModel());
|
||||
colorBar.setPositionColumn(gradient.getColorPositionColumn());
|
||||
colorBar.setColorColumn(gradient.getColorColumn());
|
||||
colorBar = new MarkerBar(gradient.getDataModel(), gradient
|
||||
.getColorSelectionModel());
|
||||
colorBar.setOrientation(gradient.getOrientation());
|
||||
colorBar.setMutationModel(gradient.getColorMutationModel());
|
||||
colorBar.setPositionColumn(gradient.getColorPositionColumn());
|
||||
colorBar.setColorColumn(gradient.getColorColumn());
|
||||
|
||||
alphaBar = new MarkerBar(gradient.getDataModel(), gradient
|
||||
.getColorSelectionModel());
|
||||
alphaBar.setOrientation(gradient.getOrientation());
|
||||
alphaBar.setMutationModel(gradient.getColorMutationModel());
|
||||
alphaBar.setPositionColumn(gradient.getColorPositionColumn());
|
||||
alphaBar.setColorColumn(gradient.getColorColumn());
|
||||
}
|
||||
alphaBar = new MarkerBar(gradient.getDataModel(), gradient
|
||||
.getColorSelectionModel());
|
||||
alphaBar.setOrientation(gradient.getOrientation());
|
||||
alphaBar.setMutationModel(gradient.getColorMutationModel());
|
||||
alphaBar.setPositionColumn(gradient.getColorPositionColumn());
|
||||
alphaBar.setColorColumn(gradient.getColorColumn());
|
||||
}
|
||||
|
||||
class GradientEditorListener implements PropertyChangeListener {
|
||||
class GradientEditorListener implements PropertyChangeListener {
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (GradientEditor.PROPERTY_DATA_MODEL
|
||||
.equals(evt.getPropertyName())) {
|
||||
gradientBar.setDataModel((BoundedTableModel) evt.getNewValue());
|
||||
colorBar.setDataModel((BoundedTableModel) evt.getNewValue());
|
||||
}
|
||||
if (GradientEditor.PROPERTY_COLOR_SELECTION_MODEL.equals(evt
|
||||
.getPropertyName())) {
|
||||
colorBar.setSelectionModel((ListSelectionModel) evt
|
||||
.getNewValue());
|
||||
}
|
||||
if (GradientEditor.PROPERTY_COLOR_MUTATION_MODEL.equals(evt
|
||||
.getPropertyName())) {
|
||||
colorBar.setMutationModel((MarkerMutationModel) evt
|
||||
.getNewValue());
|
||||
}
|
||||
if (GradientEditor.PROPERTY_COLOR_POSITION_COLUMN.equals(evt
|
||||
.getPropertyName())) {
|
||||
colorBar.setPositionColumn(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
gradientBar
|
||||
.setColorPositionColumn(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
}
|
||||
if (GradientEditor.PROPERTY_COLOR_COLUMN.equals(evt
|
||||
.getPropertyName())) {
|
||||
gradientBar.setColorColumn(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
colorBar.setColorColumn(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (GradientEditor.PROPERTY_DATA_MODEL
|
||||
.equals(evt.getPropertyName())) {
|
||||
gradientBar.setDataModel((BoundedTableModel) evt.getNewValue());
|
||||
colorBar.setDataModel((BoundedTableModel) evt.getNewValue());
|
||||
}
|
||||
if (GradientEditor.PROPERTY_COLOR_SELECTION_MODEL.equals(evt
|
||||
.getPropertyName())) {
|
||||
colorBar.setSelectionModel((ListSelectionModel) evt
|
||||
.getNewValue());
|
||||
}
|
||||
if (GradientEditor.PROPERTY_COLOR_MUTATION_MODEL.equals(evt
|
||||
.getPropertyName())) {
|
||||
colorBar.setMutationModel((MarkerMutationModel) evt
|
||||
.getNewValue());
|
||||
}
|
||||
if (GradientEditor.PROPERTY_COLOR_POSITION_COLUMN.equals(evt
|
||||
.getPropertyName())) {
|
||||
colorBar.setPositionColumn(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
gradientBar
|
||||
.setColorPositionColumn(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
}
|
||||
if (GradientEditor.PROPERTY_COLOR_COLUMN.equals(evt
|
||||
.getPropertyName())) {
|
||||
gradientBar.setColorColumn(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
colorBar.setColorColumn(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
|
||||
}
|
||||
if (GradientEditor.PROPERTY_ORIENTATION.equals(evt
|
||||
.getPropertyName())) {
|
||||
colorBar.setOrientation(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
gradientBar.setOrientation(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
}
|
||||
if ("enabled".equals(evt.getPropertyName())) {
|
||||
colorBar.setEnabled(((Boolean) evt.getNewValue())
|
||||
.booleanValue());
|
||||
gradientBar.setEnabled(((Boolean) evt.getNewValue())
|
||||
.booleanValue());
|
||||
}
|
||||
}
|
||||
if (GradientEditor.PROPERTY_ORIENTATION.equals(evt
|
||||
.getPropertyName())) {
|
||||
colorBar.setOrientation(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
gradientBar.setOrientation(((Integer) evt.getNewValue())
|
||||
.intValue());
|
||||
}
|
||||
if ("enabled".equals(evt.getPropertyName())) {
|
||||
colorBar.setEnabled(((Boolean) evt.getNewValue())
|
||||
.booleanValue());
|
||||
gradientBar.setEnabled(((Boolean) evt.getNewValue())
|
||||
.booleanValue());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize(JComponent c) {
|
||||
GradientBar gradient = (GradientBar) c;
|
||||
public Dimension getMinimumSize(JComponent c) {
|
||||
GradientBar gradient = (GradientBar) c;
|
||||
|
||||
Dimension minimumSize = gradientBar.getMinimumSize();
|
||||
Dimension minimumSize2 = colorBar.getMinimumSize();
|
||||
if (gradient.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
return new Dimension(Math
|
||||
.max(minimumSize.width, minimumSize2.width),
|
||||
minimumSize.height + minimumSize2.height);
|
||||
else
|
||||
return new Dimension(minimumSize.width + minimumSize2.width, Math
|
||||
.max(minimumSize.height, minimumSize2.height));
|
||||
Dimension minimumSize = gradientBar.getMinimumSize();
|
||||
Dimension minimumSize2 = colorBar.getMinimumSize();
|
||||
if (gradient.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
return new Dimension(Math
|
||||
.max(minimumSize.width, minimumSize2.width),
|
||||
minimumSize.height + minimumSize2.height);
|
||||
else
|
||||
return new Dimension(minimumSize.width + minimumSize2.width, Math
|
||||
.max(minimumSize.height, minimumSize2.height));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
Dimension preferredSize = gradientBar.getPreferredSize();
|
||||
Dimension preferredSize2 = colorBar.getPreferredSize();
|
||||
if (gradient.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
return new Dimension(Math.max(preferredSize.width,
|
||||
preferredSize2.width), preferredSize.height
|
||||
+ preferredSize2.height);
|
||||
else
|
||||
return new Dimension(preferredSize.width + preferredSize2.width,
|
||||
Math.max(preferredSize.height, preferredSize2.height));
|
||||
}
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
Dimension preferredSize = gradientBar.getPreferredSize();
|
||||
Dimension preferredSize2 = colorBar.getPreferredSize();
|
||||
if (gradient.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
return new Dimension(Math.max(preferredSize.width,
|
||||
preferredSize2.width), preferredSize.height
|
||||
+ preferredSize2.height);
|
||||
else
|
||||
return new Dimension(preferredSize.width + preferredSize2.width,
|
||||
Math.max(preferredSize.height, preferredSize2.height));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,351 +38,351 @@ import org.jgraph.graph.GraphLayoutCache;
|
||||
*/
|
||||
public class Birdview extends JPanel {
|
||||
|
||||
/**
|
||||
* Color constant
|
||||
*/
|
||||
public static final Color PAN_RECT_COLOR = Color.black;
|
||||
|
||||
/**
|
||||
* Color constant
|
||||
*/
|
||||
public static final Color BACKGROUND_COLOR = UIManager.getColor("Panel.background");
|
||||
|
||||
/**
|
||||
* a {@link JGraph} component used as main display
|
||||
*/
|
||||
private JGraph displayGraph;
|
||||
|
||||
/**
|
||||
* a {@link JScrollPane} to track
|
||||
*/
|
||||
private JScrollPane peerScroller;
|
||||
|
||||
/**
|
||||
* a {@link JGraph} to tracl
|
||||
*/
|
||||
private JGraph peerGraph;
|
||||
|
||||
/**
|
||||
* a rect, subrect of the component area, that matches the tracked view
|
||||
*/
|
||||
private Rectangle2D paintRect;
|
||||
|
||||
/**
|
||||
* a rect, a subrect of the component area, that matches the tracked
|
||||
* viewport
|
||||
*/
|
||||
private Rectangle2D panRect;
|
||||
|
||||
/**
|
||||
* the scale applied to {@link #displayGraph} to fit into {@link #paintRect}
|
||||
*/
|
||||
private double scale = 1.0;
|
||||
|
||||
/**
|
||||
* A listener
|
||||
*/
|
||||
private ScrollerListener scrollerListener = new ScrollerListener();
|
||||
|
||||
/**
|
||||
* A listener
|
||||
*/
|
||||
private SelfMouseListener selfMouseListener = new SelfMouseListener();
|
||||
|
||||
/**
|
||||
* A listener
|
||||
*/
|
||||
private GraphPropertyChangeListener graphPropertyChangeListener = new GraphPropertyChangeListener();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param doc
|
||||
* document to track. May be <code>null</code>
|
||||
*/
|
||||
public Birdview() {
|
||||
|
||||
displayGraph = new JGraph();
|
||||
displayGraph.setEnabled(false);
|
||||
displayGraph.setAntiAliased(true);
|
||||
displayGraph.addMouseListener(selfMouseListener);
|
||||
displayGraph.addMouseMotionListener(selfMouseListener);
|
||||
|
||||
this.setLayout(null);
|
||||
this.addComponentListener(new SelfResizeListener());
|
||||
this.add(displayGraph);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes this component track the provided graph and scroller. Set
|
||||
* parameters to <code>null</code> to unbind thie component.
|
||||
*
|
||||
* @param graph
|
||||
* the graph component. May be <code>null</code>
|
||||
* @param scroller
|
||||
* the croller, usually the one that holds the graph. May be
|
||||
* <code>null</code>
|
||||
*/
|
||||
public void setTrackingFor(JGraph graph, JScrollPane scroller) {
|
||||
if (this.peerGraph != null) {
|
||||
this.peerGraph.getModel().removeGraphModelListener(scrollerListener);
|
||||
this.peerGraph.removePropertyChangeListener(graphPropertyChangeListener);
|
||||
}
|
||||
|
||||
this.peerGraph = graph;
|
||||
|
||||
if (this.peerGraph != null) {
|
||||
this.peerGraph.getModel().addGraphModelListener(scrollerListener);
|
||||
this.peerGraph.addPropertyChangeListener(graphPropertyChangeListener);
|
||||
|
||||
this.displayGraph.setGraphLayoutCache(peerGraph.getGraphLayoutCache());
|
||||
|
||||
} else {
|
||||
this.displayGraph.setGraphLayoutCache(new GraphLayoutCache());
|
||||
}
|
||||
|
||||
//
|
||||
if (this.peerScroller != null) {
|
||||
this.peerScroller.getHorizontalScrollBar().removeAdjustmentListener(
|
||||
scrollerListener);
|
||||
this.peerScroller.getVerticalScrollBar().removeAdjustmentListener(
|
||||
scrollerListener);
|
||||
}
|
||||
|
||||
this.peerScroller = scroller;
|
||||
|
||||
if (this.peerScroller != null) {
|
||||
this.peerScroller.getHorizontalScrollBar().addAdjustmentListener(
|
||||
scrollerListener);
|
||||
this.peerScroller.getVerticalScrollBar().addAdjustmentListener(
|
||||
scrollerListener);
|
||||
}
|
||||
|
||||
update();
|
||||
repaint();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates {@link #paintRect}, {@link #panRect}, {@link #scale} based
|
||||
* on observations of peerScroller.
|
||||
*
|
||||
*/
|
||||
private void update() {
|
||||
if (peerScroller != null) {
|
||||
Dimension viewSize = peerScroller.getViewport().getViewSize();
|
||||
double viewAspect = viewSize.getHeight() / viewSize.getWidth();
|
||||
|
||||
Dimension panelSize = this.getSize();
|
||||
double panelAspect = panelSize.getHeight() / panelSize.getWidth();
|
||||
|
||||
if (panelAspect < viewAspect) {
|
||||
// panel is wider, height is primary
|
||||
double desiredPanelWidth = panelSize.getHeight() / viewAspect;
|
||||
double blankWidth = panelSize.getWidth() - desiredPanelWidth;
|
||||
double gap = blankWidth / 2;
|
||||
paintRect = new Rectangle2D.Double(gap, 0, desiredPanelWidth,
|
||||
panelSize.height);
|
||||
scale = panelSize.getHeight() / viewSize.getHeight();
|
||||
scale *= peerGraph.getScale();
|
||||
} else {
|
||||
// panel is heigher, width is primary
|
||||
double desiredPanelHeight = panelSize.getWidth() * viewAspect;
|
||||
double blankHeight = panelSize.getHeight() - desiredPanelHeight;
|
||||
double gap = blankHeight / 2;
|
||||
paintRect = new Rectangle2D.Double(0, gap, panelSize.getWidth(),
|
||||
desiredPanelHeight);
|
||||
scale = panelSize.getWidth() / viewSize.getWidth();
|
||||
scale *= peerGraph.getScale();
|
||||
}
|
||||
|
||||
Rectangle viewRect = peerScroller.getViewport().getViewRect();
|
||||
double shiftX = viewRect.getX() / viewSize.getWidth();
|
||||
double shiftY = viewRect.getY() / viewSize.getHeight();
|
||||
|
||||
double sizeX = viewRect.getWidth() / viewSize.getWidth();
|
||||
double sizeY = viewRect.getHeight() / viewSize.getHeight();
|
||||
|
||||
panRect = new Rectangle2D.Double(paintRect.getX() + paintRect.getWidth()
|
||||
* shiftX, paintRect.getY() + paintRect.getHeight() * shiftY,
|
||||
paintRect.getWidth() * sizeX, paintRect.getHeight() * sizeY);
|
||||
|
||||
} else {
|
||||
panRect = null;
|
||||
paintRect = null;
|
||||
scale = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Addjusts {@link #panRect} to be postitionsed with the centter at a given
|
||||
* point if possible. This methods ensures that {@link #panRect} fits
|
||||
* entirely in {@link #paintRect}.
|
||||
*
|
||||
* @param point
|
||||
* the desired panRect center
|
||||
*/
|
||||
private void panRectTo(Point point) {
|
||||
|
||||
Dimension viewSize = peerScroller.getViewport().getViewSize();
|
||||
Rectangle viewRect = peerScroller.getViewport().getViewRect();
|
||||
|
||||
double panHalfWidth = panRect.getWidth() / 2;
|
||||
double panHalfHeight = panRect.getHeight() / 2;
|
||||
|
||||
Point2D panOrigin = new Point2D.Double(point.x - panHalfWidth, point.y
|
||||
- panHalfHeight);
|
||||
double xk = panOrigin.getX() / paintRect.getWidth();
|
||||
double yk = panOrigin.getY() / paintRect.getHeight();
|
||||
|
||||
Point viewPos = new Point((int) (viewSize.getWidth() * xk), (int) (viewSize
|
||||
.getHeight() * yk));
|
||||
|
||||
// make sure we do not pan past the bounds:
|
||||
if (viewPos.x < 0)
|
||||
viewPos.x = 0;
|
||||
if (viewPos.y < 0)
|
||||
viewPos.y = 0;
|
||||
|
||||
int wd = (viewPos.x + viewRect.width) - viewSize.width;
|
||||
int hd = (viewPos.y + viewRect.height) - viewSize.height;
|
||||
|
||||
if (wd > 0)
|
||||
viewPos.x -= wd;
|
||||
if (hd > 0)
|
||||
viewPos.y -= hd;
|
||||
|
||||
// pan it
|
||||
peerScroller.getViewport().setViewPosition(viewPos);
|
||||
|
||||
update();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
// fill background
|
||||
g2.setColor(BACKGROUND_COLOR);
|
||||
g2.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
|
||||
if (peerGraph != null) {
|
||||
// paint the graph display
|
||||
displayGraph.setBounds(paintRect.getBounds());
|
||||
displayGraph.setScale(scale);
|
||||
displayGraph.setBackground(peerGraph.getBackground());
|
||||
paintChildren(g);
|
||||
}
|
||||
|
||||
if (panRect != null) {
|
||||
// draw pan rect
|
||||
g2.setColor(PAN_RECT_COLOR);
|
||||
g2.draw(panRect.getBounds());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A listener to watch for scrollbar movement.
|
||||
*
|
||||
* @author Michael Baranov
|
||||
*
|
||||
*/
|
||||
private class ScrollerListener implements AdjustmentListener, GraphModelListener {
|
||||
|
||||
public void adjustmentValueChanged(AdjustmentEvent e) {
|
||||
update();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void graphChanged(GraphModelEvent e) {
|
||||
update();
|
||||
repaint();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A listener to watch for sizing of the component itself.
|
||||
*
|
||||
* @author Michael Baranov
|
||||
*
|
||||
*/
|
||||
private class SelfResizeListener implements ComponentListener {
|
||||
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
}
|
||||
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
}
|
||||
|
||||
public void componentResized(ComponentEvent e) {
|
||||
update();
|
||||
repaint();
|
||||
}
|
||||
/**
|
||||
* Color constant
|
||||
*/
|
||||
public static final Color PAN_RECT_COLOR = Color.black;
|
||||
|
||||
/**
|
||||
* Color constant
|
||||
*/
|
||||
public static final Color BACKGROUND_COLOR = UIManager.getColor("Panel.background");
|
||||
|
||||
/**
|
||||
* a {@link JGraph} component used as main display
|
||||
*/
|
||||
private JGraph displayGraph;
|
||||
|
||||
/**
|
||||
* a {@link JScrollPane} to track
|
||||
*/
|
||||
private JScrollPane peerScroller;
|
||||
|
||||
/**
|
||||
* a {@link JGraph} to tracl
|
||||
*/
|
||||
private JGraph peerGraph;
|
||||
|
||||
/**
|
||||
* a rect, subrect of the component area, that matches the tracked view
|
||||
*/
|
||||
private Rectangle2D paintRect;
|
||||
|
||||
/**
|
||||
* a rect, a subrect of the component area, that matches the tracked
|
||||
* viewport
|
||||
*/
|
||||
private Rectangle2D panRect;
|
||||
|
||||
/**
|
||||
* the scale applied to {@link #displayGraph} to fit into {@link #paintRect}
|
||||
*/
|
||||
private double scale = 1.0;
|
||||
|
||||
/**
|
||||
* A listener
|
||||
*/
|
||||
private ScrollerListener scrollerListener = new ScrollerListener();
|
||||
|
||||
/**
|
||||
* A listener
|
||||
*/
|
||||
private SelfMouseListener selfMouseListener = new SelfMouseListener();
|
||||
|
||||
/**
|
||||
* A listener
|
||||
*/
|
||||
private GraphPropertyChangeListener graphPropertyChangeListener = new GraphPropertyChangeListener();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param doc
|
||||
* document to track. May be <code>null</code>
|
||||
*/
|
||||
public Birdview() {
|
||||
|
||||
displayGraph = new JGraph();
|
||||
displayGraph.setEnabled(false);
|
||||
displayGraph.setAntiAliased(true);
|
||||
displayGraph.addMouseListener(selfMouseListener);
|
||||
displayGraph.addMouseMotionListener(selfMouseListener);
|
||||
|
||||
this.setLayout(null);
|
||||
this.addComponentListener(new SelfResizeListener());
|
||||
this.add(displayGraph);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes this component track the provided graph and scroller. Set
|
||||
* parameters to <code>null</code> to unbind thie component.
|
||||
*
|
||||
* @param graph
|
||||
* the graph component. May be <code>null</code>
|
||||
* @param scroller
|
||||
* the croller, usually the one that holds the graph. May be
|
||||
* <code>null</code>
|
||||
*/
|
||||
public void setTrackingFor(JGraph graph, JScrollPane scroller) {
|
||||
if (this.peerGraph != null) {
|
||||
this.peerGraph.getModel().removeGraphModelListener(scrollerListener);
|
||||
this.peerGraph.removePropertyChangeListener(graphPropertyChangeListener);
|
||||
}
|
||||
|
||||
this.peerGraph = graph;
|
||||
|
||||
if (this.peerGraph != null) {
|
||||
this.peerGraph.getModel().addGraphModelListener(scrollerListener);
|
||||
this.peerGraph.addPropertyChangeListener(graphPropertyChangeListener);
|
||||
|
||||
this.displayGraph.setGraphLayoutCache(peerGraph.getGraphLayoutCache());
|
||||
|
||||
} else {
|
||||
this.displayGraph.setGraphLayoutCache(new GraphLayoutCache());
|
||||
}
|
||||
|
||||
//
|
||||
if (this.peerScroller != null) {
|
||||
this.peerScroller.getHorizontalScrollBar().removeAdjustmentListener(
|
||||
scrollerListener);
|
||||
this.peerScroller.getVerticalScrollBar().removeAdjustmentListener(
|
||||
scrollerListener);
|
||||
}
|
||||
|
||||
this.peerScroller = scroller;
|
||||
|
||||
if (this.peerScroller != null) {
|
||||
this.peerScroller.getHorizontalScrollBar().addAdjustmentListener(
|
||||
scrollerListener);
|
||||
this.peerScroller.getVerticalScrollBar().addAdjustmentListener(
|
||||
scrollerListener);
|
||||
}
|
||||
|
||||
update();
|
||||
repaint();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates {@link #paintRect}, {@link #panRect}, {@link #scale} based
|
||||
* on observations of peerScroller.
|
||||
*
|
||||
*/
|
||||
private void update() {
|
||||
if (peerScroller != null) {
|
||||
Dimension viewSize = peerScroller.getViewport().getViewSize();
|
||||
double viewAspect = viewSize.getHeight() / viewSize.getWidth();
|
||||
|
||||
Dimension panelSize = this.getSize();
|
||||
double panelAspect = panelSize.getHeight() / panelSize.getWidth();
|
||||
|
||||
if (panelAspect < viewAspect) {
|
||||
// panel is wider, height is primary
|
||||
double desiredPanelWidth = panelSize.getHeight() / viewAspect;
|
||||
double blankWidth = panelSize.getWidth() - desiredPanelWidth;
|
||||
double gap = blankWidth / 2;
|
||||
paintRect = new Rectangle2D.Double(gap, 0, desiredPanelWidth,
|
||||
panelSize.height);
|
||||
scale = panelSize.getHeight() / viewSize.getHeight();
|
||||
scale *= peerGraph.getScale();
|
||||
} else {
|
||||
// panel is heigher, width is primary
|
||||
double desiredPanelHeight = panelSize.getWidth() * viewAspect;
|
||||
double blankHeight = panelSize.getHeight() - desiredPanelHeight;
|
||||
double gap = blankHeight / 2;
|
||||
paintRect = new Rectangle2D.Double(0, gap, panelSize.getWidth(),
|
||||
desiredPanelHeight);
|
||||
scale = panelSize.getWidth() / viewSize.getWidth();
|
||||
scale *= peerGraph.getScale();
|
||||
}
|
||||
|
||||
Rectangle viewRect = peerScroller.getViewport().getViewRect();
|
||||
double shiftX = viewRect.getX() / viewSize.getWidth();
|
||||
double shiftY = viewRect.getY() / viewSize.getHeight();
|
||||
|
||||
double sizeX = viewRect.getWidth() / viewSize.getWidth();
|
||||
double sizeY = viewRect.getHeight() / viewSize.getHeight();
|
||||
|
||||
panRect = new Rectangle2D.Double(paintRect.getX() + paintRect.getWidth()
|
||||
* shiftX, paintRect.getY() + paintRect.getHeight() * shiftY,
|
||||
paintRect.getWidth() * sizeX, paintRect.getHeight() * sizeY);
|
||||
|
||||
} else {
|
||||
panRect = null;
|
||||
paintRect = null;
|
||||
scale = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Addjusts {@link #panRect} to be postitionsed with the centter at a given
|
||||
* point if possible. This methods ensures that {@link #panRect} fits
|
||||
* entirely in {@link #paintRect}.
|
||||
*
|
||||
* @param point
|
||||
* the desired panRect center
|
||||
*/
|
||||
private void panRectTo(Point point) {
|
||||
|
||||
Dimension viewSize = peerScroller.getViewport().getViewSize();
|
||||
Rectangle viewRect = peerScroller.getViewport().getViewRect();
|
||||
|
||||
double panHalfWidth = panRect.getWidth() / 2;
|
||||
double panHalfHeight = panRect.getHeight() / 2;
|
||||
|
||||
Point2D panOrigin = new Point2D.Double(point.x - panHalfWidth, point.y
|
||||
- panHalfHeight);
|
||||
double xk = panOrigin.getX() / paintRect.getWidth();
|
||||
double yk = panOrigin.getY() / paintRect.getHeight();
|
||||
|
||||
Point viewPos = new Point((int) (viewSize.getWidth() * xk), (int) (viewSize
|
||||
.getHeight() * yk));
|
||||
|
||||
// make sure we do not pan past the bounds:
|
||||
if (viewPos.x < 0)
|
||||
viewPos.x = 0;
|
||||
if (viewPos.y < 0)
|
||||
viewPos.y = 0;
|
||||
|
||||
int wd = (viewPos.x + viewRect.width) - viewSize.width;
|
||||
int hd = (viewPos.y + viewRect.height) - viewSize.height;
|
||||
|
||||
if (wd > 0)
|
||||
viewPos.x -= wd;
|
||||
if (hd > 0)
|
||||
viewPos.y -= hd;
|
||||
|
||||
// pan it
|
||||
peerScroller.getViewport().setViewPosition(viewPos);
|
||||
|
||||
update();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
// fill background
|
||||
g2.setColor(BACKGROUND_COLOR);
|
||||
g2.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
|
||||
if (peerGraph != null) {
|
||||
// paint the graph display
|
||||
displayGraph.setBounds(paintRect.getBounds());
|
||||
displayGraph.setScale(scale);
|
||||
displayGraph.setBackground(peerGraph.getBackground());
|
||||
paintChildren(g);
|
||||
}
|
||||
|
||||
if (panRect != null) {
|
||||
// draw pan rect
|
||||
g2.setColor(PAN_RECT_COLOR);
|
||||
g2.draw(panRect.getBounds());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A listener to watch for scrollbar movement.
|
||||
*
|
||||
* @author Michael Baranov
|
||||
*
|
||||
*/
|
||||
private class ScrollerListener implements AdjustmentListener, GraphModelListener {
|
||||
|
||||
public void adjustmentValueChanged(AdjustmentEvent e) {
|
||||
update();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void graphChanged(GraphModelEvent e) {
|
||||
update();
|
||||
repaint();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A listener to watch for sizing of the component itself.
|
||||
*
|
||||
* @author Michael Baranov
|
||||
*
|
||||
*/
|
||||
private class SelfResizeListener implements ComponentListener {
|
||||
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
}
|
||||
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
}
|
||||
|
||||
public void componentResized(ComponentEvent e) {
|
||||
update();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void componentShown(ComponentEvent e) {
|
||||
update();
|
||||
repaint();
|
||||
}
|
||||
public void componentShown(ComponentEvent e) {
|
||||
update();
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A listener to watch for mouse for the component itself.
|
||||
*
|
||||
* @author Michael Baranov
|
||||
*
|
||||
*/
|
||||
private class SelfMouseListener implements MouseListener, MouseMotionListener {
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A listener to watch for mouse for the component itself.
|
||||
*
|
||||
* @author Michael Baranov
|
||||
*
|
||||
*/
|
||||
private class SelfMouseListener implements MouseListener, MouseMotionListener {
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (paintRect != null)
|
||||
panRectTo(e.getPoint());
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (paintRect != null)
|
||||
panRectTo(e.getPoint());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
if (paintRect != null)
|
||||
panRectTo(e.getPoint());
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
if (paintRect != null)
|
||||
panRectTo(e.getPoint());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
}
|
||||
|
||||
}
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A listener to watch for graph property change, most important "scale".
|
||||
*
|
||||
* @author Michael Baranov
|
||||
*
|
||||
*/
|
||||
private class GraphPropertyChangeListener implements PropertyChangeListener {
|
||||
/**
|
||||
* A listener to watch for graph property change, most important "scale".
|
||||
*
|
||||
* @author Michael Baranov
|
||||
*
|
||||
*/
|
||||
private class GraphPropertyChangeListener implements PropertyChangeListener {
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if ("scale".equals(evt.getPropertyName())) {
|
||||
update();
|
||||
repaint();
|
||||
}
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if ("scale".equals(evt.getPropertyName())) {
|
||||
update();
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,209 +19,209 @@ import com.michaelbaranov.microba.common.AbstractBoundedTableModelWithSelection;
|
||||
* @see com.michaelbaranov.microba.marker.MarkerBar
|
||||
*/
|
||||
public class DefaultMarkerModel extends AbstractBoundedTableModelWithSelection
|
||||
implements MarkerMutationModel {
|
||||
implements MarkerMutationModel {
|
||||
|
||||
private List data = new ArrayList(32);
|
||||
private List data = new ArrayList(32);
|
||||
|
||||
private int lowerBound = 0;
|
||||
private int lowerBound = 0;
|
||||
|
||||
private int upperBound = 100;
|
||||
private int upperBound = 100;
|
||||
|
||||
/**
|
||||
* Constructs a <code>DefaultMarkerModel</code>.
|
||||
*
|
||||
*/
|
||||
public DefaultMarkerModel() {
|
||||
super();
|
||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
}
|
||||
/**
|
||||
* Constructs a <code>DefaultMarkerModel</code>.
|
||||
*
|
||||
*/
|
||||
public DefaultMarkerModel() {
|
||||
super();
|
||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the count of markers. Actually returns the cound of rows in the
|
||||
* <code>TableModel</code>.
|
||||
*
|
||||
* @return current marker count.
|
||||
*/
|
||||
public int getRowCount() {
|
||||
return data.size();
|
||||
}
|
||||
/**
|
||||
* Returns the count of markers. Actually returns the cound of rows in the
|
||||
* <code>TableModel</code>.
|
||||
*
|
||||
* @return current marker count.
|
||||
*/
|
||||
public int getRowCount() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numbar of columns in the <code>TableModel</code>.This
|
||||
* implementation always returns 1.
|
||||
*
|
||||
* @return always 1.
|
||||
*/
|
||||
public int getColumnCount() {
|
||||
return 1;
|
||||
}
|
||||
/**
|
||||
* Returns the numbar of columns in the <code>TableModel</code>.This
|
||||
* implementation always returns 1.
|
||||
*
|
||||
* @return always 1.
|
||||
*/
|
||||
public int getColumnCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position of a marker, specified by index.
|
||||
*
|
||||
* @param rowIndex
|
||||
* marker index.
|
||||
* @param columnIndex
|
||||
* should be 0.
|
||||
*
|
||||
* @return an Integer position of the marker.
|
||||
* @see #setValueAt(Object, int, int)
|
||||
*/
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
checkIndexes(rowIndex, columnIndex);
|
||||
return data.get(rowIndex);
|
||||
}
|
||||
/**
|
||||
* Returns the position of a marker, specified by index.
|
||||
*
|
||||
* @param rowIndex
|
||||
* marker index.
|
||||
* @param columnIndex
|
||||
* should be 0.
|
||||
*
|
||||
* @return an Integer position of the marker.
|
||||
* @see #setValueAt(Object, int, int)
|
||||
*/
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
checkIndexes(rowIndex, columnIndex);
|
||||
return data.get(rowIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns a new position to a marker, specified by index (moves the
|
||||
* marker).
|
||||
* <p>
|
||||
* This implementation does not check if the specified marker position lies
|
||||
* beyond current upper and lower bounds.
|
||||
*
|
||||
* @param aValue
|
||||
* an Integer new position.
|
||||
* @param rowIndex
|
||||
* marker index.
|
||||
* @param columnIndex
|
||||
* should be 0.
|
||||
* @see #getValueAt(int, int)
|
||||
*/
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||
/**
|
||||
* Assigns a new position to a marker, specified by index (moves the
|
||||
* marker).
|
||||
* <p>
|
||||
* This implementation does not check if the specified marker position lies
|
||||
* beyond current upper and lower bounds.
|
||||
*
|
||||
* @param aValue
|
||||
* an Integer new position.
|
||||
* @param rowIndex
|
||||
* marker index.
|
||||
* @param columnIndex
|
||||
* should be 0.
|
||||
* @see #getValueAt(int, int)
|
||||
*/
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||
|
||||
checkIndexes(rowIndex, columnIndex);
|
||||
checkIndexes(rowIndex, columnIndex);
|
||||
|
||||
Integer newValue = (Integer) aValue;
|
||||
Integer oldValue = (Integer) getValueAt(rowIndex, columnIndex);
|
||||
Integer newValue = (Integer) aValue;
|
||||
Integer oldValue = (Integer) getValueAt(rowIndex, columnIndex);
|
||||
|
||||
if (!newValue.equals(oldValue)) {
|
||||
data.remove(rowIndex);
|
||||
data.add(rowIndex, newValue);
|
||||
fireTableCellUpdated(rowIndex, columnIndex);
|
||||
}
|
||||
}
|
||||
if (!newValue.equals(oldValue)) {
|
||||
data.remove(rowIndex);
|
||||
data.add(rowIndex, newValue);
|
||||
fireTableCellUpdated(rowIndex, columnIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation returns <code>Integer.class</code> for
|
||||
* columnIndex=0.
|
||||
*
|
||||
* @param columnIndex
|
||||
* should be 0.
|
||||
*
|
||||
* @return column data class.
|
||||
*/
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
return Integer.class;
|
||||
}
|
||||
/**
|
||||
* This implementation returns <code>Integer.class</code> for
|
||||
* columnIndex=0.
|
||||
*
|
||||
* @param columnIndex
|
||||
* should be 0.
|
||||
*
|
||||
* @return column data class.
|
||||
*/
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation returns <code>"Position"</code> for columnIndex=0.
|
||||
*
|
||||
* @param columnIndex
|
||||
* should be 0.
|
||||
* @return column name.
|
||||
*/
|
||||
public String getColumnName(int columnIndex) {
|
||||
return "Position";
|
||||
}
|
||||
/**
|
||||
* This implementation returns <code>"Position"</code> for columnIndex=0.
|
||||
*
|
||||
* @param columnIndex
|
||||
* should be 0.
|
||||
* @return column name.
|
||||
*/
|
||||
public String getColumnName(int columnIndex) {
|
||||
return "Position";
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation always returns <code>true</code>, indicating that
|
||||
* all markers are movable. Override to change behaviour.
|
||||
*
|
||||
* @return always <code>true</code>.
|
||||
*/
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* This implementation always returns <code>true</code>, indicating that
|
||||
* all markers are movable. Override to change behaviour.
|
||||
*
|
||||
* @return always <code>true</code>.
|
||||
*/
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a marker, specified by index. Actually removes a row from the
|
||||
* <code>TableModel</code>.
|
||||
*
|
||||
* @param index
|
||||
* marker index.
|
||||
* @see #addMarkAtPosition(int)
|
||||
*/
|
||||
public void removeMarkerAtIndex(int index) {
|
||||
if (isSelectedIndex(index)) {
|
||||
removeSelectionInterval(index, index);
|
||||
}
|
||||
data.remove(index);
|
||||
fireTableRowsDeleted(index, index);
|
||||
}
|
||||
/**
|
||||
* Removes a marker, specified by index. Actually removes a row from the
|
||||
* <code>TableModel</code>.
|
||||
*
|
||||
* @param index
|
||||
* marker index.
|
||||
* @see #addMarkAtPosition(int)
|
||||
*/
|
||||
public void removeMarkerAtIndex(int index) {
|
||||
if (isSelectedIndex(index)) {
|
||||
removeSelectionInterval(index, index);
|
||||
}
|
||||
data.remove(index);
|
||||
fireTableRowsDeleted(index, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a marker with specified position. Actually appends a row to
|
||||
* <code>TableModel</code> with specified position value. Returns the
|
||||
* index of the added mark.
|
||||
* <p>
|
||||
* This implementation does not check if the specified marker position lies
|
||||
* beyond current upper and lower bounds.
|
||||
*
|
||||
* @return index of added mark.
|
||||
* @see #removeMarkerAtIndex(int)
|
||||
*/
|
||||
public int addMarkAtPosition(int position) {
|
||||
data.add(new Integer(position));
|
||||
int row = data.size() - 1;
|
||||
fireTableRowsInserted(row, row);
|
||||
/**
|
||||
* Adds a marker with specified position. Actually appends a row to
|
||||
* <code>TableModel</code> with specified position value. Returns the
|
||||
* index of the added mark.
|
||||
* <p>
|
||||
* This implementation does not check if the specified marker position lies
|
||||
* beyond current upper and lower bounds.
|
||||
*
|
||||
* @return index of added mark.
|
||||
* @see #removeMarkerAtIndex(int)
|
||||
*/
|
||||
public int addMarkAtPosition(int position) {
|
||||
data.add(new Integer(position));
|
||||
int row = data.size() - 1;
|
||||
fireTableRowsInserted(row, row);
|
||||
|
||||
setSelectionInterval(row, row);
|
||||
return row;
|
||||
}
|
||||
setSelectionInterval(row, row);
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @see #setLowerBound(int)
|
||||
*/
|
||||
public int getLowerBound() {
|
||||
return lowerBound;
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @see #setLowerBound(int)
|
||||
*/
|
||||
public int getLowerBound() {
|
||||
return lowerBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @see #setUpperBound(int)
|
||||
*/
|
||||
public int getUpperBound() {
|
||||
return upperBound;
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @see #setUpperBound(int)
|
||||
*/
|
||||
public int getUpperBound() {
|
||||
return upperBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current lower bound.
|
||||
*
|
||||
* @param lowerBound
|
||||
* new lower bound value.
|
||||
* @see #setLowerBound(int)
|
||||
*/
|
||||
public void setLowerBound(int lowerBound) {
|
||||
if (lowerBound >= upperBound)
|
||||
throw new IllegalArgumentException("lowerBound >= upperBound");
|
||||
/**
|
||||
* Sets current lower bound.
|
||||
*
|
||||
* @param lowerBound
|
||||
* new lower bound value.
|
||||
* @see #setLowerBound(int)
|
||||
*/
|
||||
public void setLowerBound(int lowerBound) {
|
||||
if (lowerBound >= upperBound)
|
||||
throw new IllegalArgumentException("lowerBound >= upperBound");
|
||||
|
||||
int old = this.lowerBound;
|
||||
this.lowerBound = lowerBound;
|
||||
firePropertyChange(PROPERTY_LOWER_BOUND, old, lowerBound);
|
||||
}
|
||||
int old = this.lowerBound;
|
||||
this.lowerBound = lowerBound;
|
||||
firePropertyChange(PROPERTY_LOWER_BOUND, old, lowerBound);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current upper bound.
|
||||
*
|
||||
* @param upperBound
|
||||
* new upper bound value.
|
||||
* @see #getUpperBound()
|
||||
*/
|
||||
public void setUpperBound(int upperBound) {
|
||||
int old = this.upperBound;
|
||||
this.upperBound = upperBound;
|
||||
firePropertyChange(PROPERTY_UPPER_BOUND, old, upperBound);
|
||||
}
|
||||
/**
|
||||
* Sets current upper bound.
|
||||
*
|
||||
* @param upperBound
|
||||
* new upper bound value.
|
||||
* @see #getUpperBound()
|
||||
*/
|
||||
public void setUpperBound(int upperBound) {
|
||||
int old = this.upperBound;
|
||||
this.upperBound = upperBound;
|
||||
firePropertyChange(PROPERTY_UPPER_BOUND, old, upperBound);
|
||||
}
|
||||
|
||||
private void checkIndexes(int rowIndex, int columnIndex) {
|
||||
if (columnIndex != 0)
|
||||
throw new IndexOutOfBoundsException("columnIndex: " + columnIndex);
|
||||
private void checkIndexes(int rowIndex, int columnIndex) {
|
||||
if (columnIndex != 0)
|
||||
throw new IndexOutOfBoundsException("columnIndex: " + columnIndex);
|
||||
|
||||
if (rowIndex < 0 || rowIndex >= data.size())
|
||||
throw new IndexOutOfBoundsException("rowIndex: " + rowIndex);
|
||||
}
|
||||
if (rowIndex < 0 || rowIndex >= data.size())
|
||||
throw new IndexOutOfBoundsException("rowIndex: " + rowIndex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,330 +49,330 @@ import com.michaelbaranov.microba.marker.ui.MarkerBarUI;
|
||||
*/
|
||||
public class MarkerBar extends MicrobaComponent {
|
||||
|
||||
/**
|
||||
* The name of a "dataModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_DATA_MODEL = "dataModel";
|
||||
/**
|
||||
* The name of a "dataModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_DATA_MODEL = "dataModel";
|
||||
|
||||
/**
|
||||
* The name of a "selectionModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_SELECTION_MODEL = "selectionModel";
|
||||
/**
|
||||
* The name of a "selectionModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_SELECTION_MODEL = "selectionModel";
|
||||
|
||||
/**
|
||||
* The name of a "mutationModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_MUTATION_MODEL = "mutationModel";
|
||||
/**
|
||||
* The name of a "mutationModel" property.
|
||||
*/
|
||||
public static final String PROPERTY_MUTATION_MODEL = "mutationModel";
|
||||
|
||||
/**
|
||||
* The name of a "orientation" property.
|
||||
*/
|
||||
public static final String PROPERTY_ORIENTATION = "orientation";
|
||||
/**
|
||||
* The name of a "orientation" property.
|
||||
*/
|
||||
public static final String PROPERTY_ORIENTATION = "orientation";
|
||||
|
||||
/**
|
||||
* The name of a "positionColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_POSITION_COLUMN = "positionColumn";
|
||||
/**
|
||||
* The name of a "positionColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_POSITION_COLUMN = "positionColumn";
|
||||
|
||||
/**
|
||||
* The name of a "colorColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_COLOR_COLUMN = "colorColumn";
|
||||
/**
|
||||
* The name of a "colorColumn" property.
|
||||
*/
|
||||
public static final String PROPERTY_COLOR_COLUMN = "colorColumn";
|
||||
|
||||
/**
|
||||
* The name of a "fliped" property.
|
||||
*/
|
||||
public static final String PROPERTY_FLIP = "fliped";
|
||||
/**
|
||||
* The name of a "fliped" property.
|
||||
*/
|
||||
public static final String PROPERTY_FLIP = "fliped";
|
||||
|
||||
private static final String uiClassID = "microba.MarkerBarUI";
|
||||
private static final String uiClassID = "microba.MarkerBarUI";
|
||||
|
||||
private BoundedTableModel dataModel = null;
|
||||
private BoundedTableModel dataModel = null;
|
||||
|
||||
private ListSelectionModel selectionModel = null;
|
||||
private ListSelectionModel selectionModel = null;
|
||||
|
||||
private MarkerMutationModel mutationModel = null;
|
||||
private MarkerMutationModel mutationModel = null;
|
||||
|
||||
private int positionColumn = 0;
|
||||
private int positionColumn = 0;
|
||||
|
||||
private int colorColumn = -1;
|
||||
private int colorColumn = -1;
|
||||
|
||||
private int orientation = SwingConstants.HORIZONTAL;
|
||||
private int orientation = SwingConstants.HORIZONTAL;
|
||||
|
||||
private boolean fliped = false;
|
||||
private boolean fliped = false;
|
||||
|
||||
/**
|
||||
* Constructs a <code>MarkerBar</code> with all models set to a single
|
||||
* <code>DefaultMarkerModel.</code>
|
||||
*
|
||||
* @see DefaultMarkerModel
|
||||
*/
|
||||
public MarkerBar() {
|
||||
super();
|
||||
DefaultMarkerModel markerModel = new DefaultMarkerModel();
|
||||
dataModel = markerModel;
|
||||
selectionModel = markerModel;
|
||||
mutationModel = markerModel;
|
||||
setFocusable(true);
|
||||
updateUI();
|
||||
}
|
||||
/**
|
||||
* Constructs a <code>MarkerBar</code> with all models set to a single
|
||||
* <code>DefaultMarkerModel.</code>
|
||||
*
|
||||
* @see DefaultMarkerModel
|
||||
*/
|
||||
public MarkerBar() {
|
||||
super();
|
||||
DefaultMarkerModel markerModel = new DefaultMarkerModel();
|
||||
dataModel = markerModel;
|
||||
selectionModel = markerModel;
|
||||
mutationModel = markerModel;
|
||||
setFocusable(true);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MarkerBar</code> with given orientation. All models
|
||||
* set to a single <code>DefaultMarkerModel</code>.
|
||||
*
|
||||
* @param orientation
|
||||
* initial orientation. Possible values:
|
||||
* <code>SwingConstants.HORIZONTAL</code> or
|
||||
* <code>SwingConstants.VERTICAL</code>
|
||||
* @see DefaultMarkerModel
|
||||
*/
|
||||
public MarkerBar(int orientation) {
|
||||
super();
|
||||
DefaultMarkerModel markerModel = new DefaultMarkerModel();
|
||||
dataModel = markerModel;
|
||||
selectionModel = markerModel;
|
||||
mutationModel = markerModel;
|
||||
this.orientation = orientation;
|
||||
setFocusable(true);
|
||||
updateUI();
|
||||
}
|
||||
/**
|
||||
* Constructs a <code>MarkerBar</code> with given orientation. All models
|
||||
* set to a single <code>DefaultMarkerModel</code>.
|
||||
*
|
||||
* @param orientation
|
||||
* initial orientation. Possible values:
|
||||
* <code>SwingConstants.HORIZONTAL</code> or
|
||||
* <code>SwingConstants.VERTICAL</code>
|
||||
* @see DefaultMarkerModel
|
||||
*/
|
||||
public MarkerBar(int orientation) {
|
||||
super();
|
||||
DefaultMarkerModel markerModel = new DefaultMarkerModel();
|
||||
dataModel = markerModel;
|
||||
selectionModel = markerModel;
|
||||
mutationModel = markerModel;
|
||||
this.orientation = orientation;
|
||||
setFocusable(true);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MarkerBar</code> with given data model, a
|
||||
* <code>DefaultListSelectionModel<code> as selection model and no mutation model.
|
||||
*
|
||||
* @param dataModel
|
||||
* initial data model. May be <code>null<code>
|
||||
*
|
||||
* @see BoundedTableModel
|
||||
*/
|
||||
public MarkerBar(BoundedTableModel dataModel) {
|
||||
super();
|
||||
this.dataModel = dataModel;
|
||||
selectionModel = new DefaultListSelectionModel();
|
||||
mutationModel = null;
|
||||
setFocusable(true);
|
||||
updateUI();
|
||||
}
|
||||
/**
|
||||
* Constructs a <code>MarkerBar</code> with given data model, a
|
||||
* <code>DefaultListSelectionModel<code> as selection model and no mutation model.
|
||||
*
|
||||
* @param dataModel
|
||||
* initial data model. May be <code>null<code>
|
||||
*
|
||||
* @see BoundedTableModel
|
||||
*/
|
||||
public MarkerBar(BoundedTableModel dataModel) {
|
||||
super();
|
||||
this.dataModel = dataModel;
|
||||
selectionModel = new DefaultListSelectionModel();
|
||||
mutationModel = null;
|
||||
setFocusable(true);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MarkerBar</code> with given data model and selection
|
||||
* model. No mutation model.
|
||||
*
|
||||
* @param dataModel
|
||||
* initial data model. May be <code>null<code>;
|
||||
* @param selectionModel initial selection model.
|
||||
* @see BoundedTableModel
|
||||
*/
|
||||
public MarkerBar(BoundedTableModel dataModel, ListSelectionModel selectionModel) {
|
||||
super();
|
||||
this.dataModel = dataModel;
|
||||
this.selectionModel = selectionModel;
|
||||
mutationModel = null;
|
||||
setFocusable(true);
|
||||
updateUI();
|
||||
}
|
||||
/**
|
||||
* Constructs a <code>MarkerBar</code> with given data model and selection
|
||||
* model. No mutation model.
|
||||
*
|
||||
* @param dataModel
|
||||
* initial data model. May be <code>null<code>;
|
||||
* @param selectionModel initial selection model.
|
||||
* @see BoundedTableModel
|
||||
*/
|
||||
public MarkerBar(BoundedTableModel dataModel, ListSelectionModel selectionModel) {
|
||||
super();
|
||||
this.dataModel = dataModel;
|
||||
this.selectionModel = selectionModel;
|
||||
mutationModel = null;
|
||||
setFocusable(true);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Look&Feel UI delegate key (classID). This implementation returns:
|
||||
* <code>"MarkerBarUI"<code>.
|
||||
*/
|
||||
public String getUIClassID() {
|
||||
return uiClassID;
|
||||
}
|
||||
/**
|
||||
* Look&Feel UI delegate key (classID). This implementation returns:
|
||||
* <code>"MarkerBarUI"<code>.
|
||||
*/
|
||||
public String getUIClassID() {
|
||||
return uiClassID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current data model.
|
||||
*
|
||||
* @return current BoundedTableModel.
|
||||
* @see #setDataModel(BoundedTableModel)
|
||||
* @see BoundedTableModel
|
||||
*/
|
||||
public BoundedTableModel getDataModel() {
|
||||
return dataModel;
|
||||
}
|
||||
/**
|
||||
* Returns current data model.
|
||||
*
|
||||
* @return current BoundedTableModel.
|
||||
* @see #setDataModel(BoundedTableModel)
|
||||
* @see BoundedTableModel
|
||||
*/
|
||||
public BoundedTableModel getDataModel() {
|
||||
return dataModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces current data model with specified one. This implementation uses
|
||||
* current position column index to query marker positions.
|
||||
*
|
||||
* @param model
|
||||
* new data model.
|
||||
* @see #getDataModel()
|
||||
* @see #getPositionColumn()
|
||||
* @see BoundedTableModel
|
||||
*/
|
||||
public void setDataModel(BoundedTableModel model) {
|
||||
BoundedTableModel oldModel = this.dataModel;
|
||||
this.dataModel = model;
|
||||
firePropertyChange(PROPERTY_DATA_MODEL, oldModel, model);
|
||||
}
|
||||
/**
|
||||
* Replaces current data model with specified one. This implementation uses
|
||||
* current position column index to query marker positions.
|
||||
*
|
||||
* @param model
|
||||
* new data model.
|
||||
* @see #getDataModel()
|
||||
* @see #getPositionColumn()
|
||||
* @see BoundedTableModel
|
||||
*/
|
||||
public void setDataModel(BoundedTableModel model) {
|
||||
BoundedTableModel oldModel = this.dataModel;
|
||||
this.dataModel = model;
|
||||
firePropertyChange(PROPERTY_DATA_MODEL, oldModel, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current component orientation.
|
||||
*
|
||||
* @return current component orientation.
|
||||
* @see #setOrientation(int)
|
||||
*/
|
||||
public int getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
/**
|
||||
* Returns current component orientation.
|
||||
*
|
||||
* @return current component orientation.
|
||||
* @see #setOrientation(int)
|
||||
*/
|
||||
public int getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-orientates the component.
|
||||
*
|
||||
* @param orientation
|
||||
* new orientation value. Possible values:
|
||||
* <code>{@link SwingConstants#HORIZONTAL}</code> or
|
||||
* <code>{@link SwingConstants#VERTICAL}</code>
|
||||
* @see #getOrientation()
|
||||
*/
|
||||
public void setOrientation(int orientation) {
|
||||
int oldOrientation = this.orientation;
|
||||
this.orientation = orientation;
|
||||
firePropertyChange(PROPERTY_ORIENTATION, oldOrientation, orientation);
|
||||
}
|
||||
/**
|
||||
* Re-orientates the component.
|
||||
*
|
||||
* @param orientation
|
||||
* new orientation value. Possible values:
|
||||
* <code>{@link SwingConstants#HORIZONTAL}</code> or
|
||||
* <code>{@link SwingConstants#VERTICAL}</code>
|
||||
* @see #getOrientation()
|
||||
*/
|
||||
public void setOrientation(int orientation) {
|
||||
int oldOrientation = this.orientation;
|
||||
this.orientation = orientation;
|
||||
firePropertyChange(PROPERTY_ORIENTATION, oldOrientation, orientation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current mutation model.
|
||||
*
|
||||
* @return current MutationModel.
|
||||
* @see #setMutationModel(MarkerMutationModel)
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public MarkerMutationModel getMutationModel() {
|
||||
return mutationModel;
|
||||
}
|
||||
/**
|
||||
* Returns current mutation model.
|
||||
*
|
||||
* @return current MutationModel.
|
||||
* @see #setMutationModel(MarkerMutationModel)
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public MarkerMutationModel getMutationModel() {
|
||||
return mutationModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces current mutation model with given one.
|
||||
*
|
||||
* @param mutationModel
|
||||
* new mutation model. May be <code>null<code>.
|
||||
* @see #getMutationModel()
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public void setMutationModel(MarkerMutationModel mutationModel) {
|
||||
MarkerMutationModel oldMutationModel = this.mutationModel;
|
||||
this.mutationModel = mutationModel;
|
||||
firePropertyChange(PROPERTY_MUTATION_MODEL, oldMutationModel, mutationModel);
|
||||
}
|
||||
/**
|
||||
* Replaces current mutation model with given one.
|
||||
*
|
||||
* @param mutationModel
|
||||
* new mutation model. May be <code>null<code>.
|
||||
* @see #getMutationModel()
|
||||
* @see MarkerMutationModel
|
||||
*/
|
||||
public void setMutationModel(MarkerMutationModel mutationModel) {
|
||||
MarkerMutationModel oldMutationModel = this.mutationModel;
|
||||
this.mutationModel = mutationModel;
|
||||
firePropertyChange(PROPERTY_MUTATION_MODEL, oldMutationModel, mutationModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current selection model.
|
||||
*
|
||||
* @return current ListSelectionModel.
|
||||
* @see #setSelectionModel(ListSelectionModel)
|
||||
*/
|
||||
public ListSelectionModel getSelectionModel() {
|
||||
return selectionModel;
|
||||
}
|
||||
/**
|
||||
* Returns current selection model.
|
||||
*
|
||||
* @return current ListSelectionModel.
|
||||
* @see #setSelectionModel(ListSelectionModel)
|
||||
*/
|
||||
public ListSelectionModel getSelectionModel() {
|
||||
return selectionModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces current selection model with given one. This implementation uses
|
||||
* <code>{@link ListSelectionModel#getLeadSelectionIndex()}</code> to
|
||||
* determine selected marker.
|
||||
*
|
||||
* @param selectionModel
|
||||
* new selection model. May be <code>null<code>.
|
||||
*
|
||||
* @see #getSelectionModel()
|
||||
*/
|
||||
public void setSelectionModel(ListSelectionModel selectionModel) {
|
||||
ListSelectionModel oldSelectionModel = this.selectionModel;
|
||||
this.selectionModel = selectionModel;
|
||||
firePropertyChange(PROPERTY_SELECTION_MODEL, oldSelectionModel, selectionModel);
|
||||
}
|
||||
/**
|
||||
* Replaces current selection model with given one. This implementation uses
|
||||
* <code>{@link ListSelectionModel#getLeadSelectionIndex()}</code> to
|
||||
* determine selected marker.
|
||||
*
|
||||
* @param selectionModel
|
||||
* new selection model. May be <code>null<code>.
|
||||
*
|
||||
* @see #getSelectionModel()
|
||||
*/
|
||||
public void setSelectionModel(ListSelectionModel selectionModel) {
|
||||
ListSelectionModel oldSelectionModel = this.selectionModel;
|
||||
this.selectionModel = selectionModel;
|
||||
firePropertyChange(PROPERTY_SELECTION_MODEL, oldSelectionModel, selectionModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an index of currently used table column to query marker position.
|
||||
*
|
||||
* @return current position column index.
|
||||
* @see #setPositionColumn(int)
|
||||
*/
|
||||
public int getPositionColumn() {
|
||||
return positionColumn;
|
||||
}
|
||||
/**
|
||||
* Returns an index of currently used table column to query marker position.
|
||||
*
|
||||
* @return current position column index.
|
||||
* @see #setPositionColumn(int)
|
||||
*/
|
||||
public int getPositionColumn() {
|
||||
return positionColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the index of the data model table column used to query marker
|
||||
* position.
|
||||
*
|
||||
* @param positionColumn
|
||||
* new position column index.
|
||||
* @see #getPositionColumn()
|
||||
*/
|
||||
public void setPositionColumn(int positionColumn) {
|
||||
int oldDataColumn = this.positionColumn;
|
||||
this.positionColumn = positionColumn;
|
||||
firePropertyChange(PROPERTY_POSITION_COLUMN, oldDataColumn, positionColumn);
|
||||
}
|
||||
/**
|
||||
* Sets the index of the data model table column used to query marker
|
||||
* position.
|
||||
*
|
||||
* @param positionColumn
|
||||
* new position column index.
|
||||
* @see #getPositionColumn()
|
||||
*/
|
||||
public void setPositionColumn(int positionColumn) {
|
||||
int oldDataColumn = this.positionColumn;
|
||||
this.positionColumn = positionColumn;
|
||||
firePropertyChange(PROPERTY_POSITION_COLUMN, oldDataColumn, positionColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an index of currently used table column to query marker color.
|
||||
* Defaults to -1, which means not to query data model for color.
|
||||
*
|
||||
* @return current color column index.
|
||||
* @see #setColorColumn(int)
|
||||
*/
|
||||
public int getColorColumn() {
|
||||
return colorColumn;
|
||||
}
|
||||
/**
|
||||
* Returns an index of currently used table column to query marker color.
|
||||
* Defaults to -1, which means not to query data model for color.
|
||||
*
|
||||
* @return current color column index.
|
||||
* @see #setColorColumn(int)
|
||||
*/
|
||||
public int getColorColumn() {
|
||||
return colorColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the index of the data model table column used to query marker color.
|
||||
* Set to -1 in order not to query data model for color data.
|
||||
*
|
||||
* @param colorColumn
|
||||
* new color column index.
|
||||
* @see #getColorColumn()
|
||||
*/
|
||||
public void setColorColumn(int colorColumn) {
|
||||
int old = this.colorColumn;
|
||||
this.colorColumn = colorColumn;
|
||||
firePropertyChange(PROPERTY_COLOR_COLUMN, old, colorColumn);
|
||||
}
|
||||
/**
|
||||
* Sets the index of the data model table column used to query marker color.
|
||||
* Set to -1 in order not to query data model for color data.
|
||||
*
|
||||
* @param colorColumn
|
||||
* new color column index.
|
||||
* @see #getColorColumn()
|
||||
*/
|
||||
public void setColorColumn(int colorColumn) {
|
||||
int old = this.colorColumn;
|
||||
this.colorColumn = colorColumn;
|
||||
firePropertyChange(PROPERTY_COLOR_COLUMN, old, colorColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a distance in pixeld between the edge of the component (left &
|
||||
* right edge for horizontal orientation, top & bottom edge for vertical)
|
||||
* and a marker beak point in outermost position. The value is actually
|
||||
* queried from current UI delegate.
|
||||
*
|
||||
* @return Gap value.
|
||||
* @see MarkerBarUI
|
||||
*/
|
||||
public int getMarkerSideGap() {
|
||||
return ((MarkerBarUI) getUI()).getMarkerSideGap();
|
||||
}
|
||||
/**
|
||||
* Returns a distance in pixeld between the edge of the component (left &
|
||||
* right edge for horizontal orientation, top & bottom edge for vertical)
|
||||
* and a marker beak point in outermost position. The value is actually
|
||||
* queried from current UI delegate.
|
||||
*
|
||||
* @return Gap value.
|
||||
* @see MarkerBarUI
|
||||
*/
|
||||
public int getMarkerSideGap() {
|
||||
return ((MarkerBarUI) getUI()).getMarkerSideGap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current flip flag value.
|
||||
* <p>
|
||||
* The flip flag defines where marker bicks are pointed:<br>
|
||||
* <code>true</code>: down for horizontal orientation, left for vertical.<br>
|
||||
* <code>false</code>: up for horizontal orientation, right for vertical.
|
||||
*
|
||||
* @return current flip value.
|
||||
*/
|
||||
public boolean isFliped() {
|
||||
return fliped;
|
||||
}
|
||||
/**
|
||||
* Returns current flip flag value.
|
||||
* <p>
|
||||
* The flip flag defines where marker bicks are pointed:<br>
|
||||
* <code>true</code>: down for horizontal orientation, left for vertical.<br>
|
||||
* <code>false</code>: up for horizontal orientation, right for vertical.
|
||||
*
|
||||
* @return current flip value.
|
||||
*/
|
||||
public boolean isFliped() {
|
||||
return fliped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flip flag value.
|
||||
* <p>
|
||||
* The flip flag defines where marker bicks are pointed:<br>
|
||||
* <code>true</code>: down for horizontal orientation, left for vertical.<br>
|
||||
* <code>false</code>: up for horizontal orientation, right for vertical.
|
||||
*
|
||||
* @param flip
|
||||
* new flip flag value.
|
||||
*/
|
||||
public void setFliped(boolean flip) {
|
||||
boolean old = this.fliped;
|
||||
this.fliped = flip;
|
||||
firePropertyChange(PROPERTY_FLIP, old, flip);
|
||||
}
|
||||
/**
|
||||
* Set flip flag value.
|
||||
* <p>
|
||||
* The flip flag defines where marker bicks are pointed:<br>
|
||||
* <code>true</code>: down for horizontal orientation, left for vertical.<br>
|
||||
* <code>false</code>: up for horizontal orientation, right for vertical.
|
||||
*
|
||||
* @param flip
|
||||
* new flip flag value.
|
||||
*/
|
||||
public void setFliped(boolean flip) {
|
||||
boolean old = this.fliped;
|
||||
this.fliped = flip;
|
||||
firePropertyChange(PROPERTY_FLIP, old, flip);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,22 +14,22 @@ package com.michaelbaranov.microba.marker;
|
||||
*/
|
||||
public interface MarkerMutationModel {
|
||||
|
||||
/**
|
||||
* Called when the user requests a mark to be removed from
|
||||
* <code>JMarkerBar</code>.
|
||||
*
|
||||
* @param index
|
||||
* index of the mark to be removed.
|
||||
*/
|
||||
void removeMarkerAtIndex(int index);
|
||||
/**
|
||||
* Called when the user requests a mark to be removed from
|
||||
* <code>JMarkerBar</code>.
|
||||
*
|
||||
* @param index
|
||||
* index of the mark to be removed.
|
||||
*/
|
||||
void removeMarkerAtIndex(int index);
|
||||
|
||||
/**
|
||||
* Called when the user requests a mark to be inserted into
|
||||
* <code>JMarkerBar</code>.
|
||||
*
|
||||
* @param position
|
||||
* position at which to insert the mark.
|
||||
* @return index of newly added mark.
|
||||
*/
|
||||
int addMarkAtPosition(int position);
|
||||
/**
|
||||
* Called when the user requests a mark to be inserted into
|
||||
* <code>JMarkerBar</code>.
|
||||
*
|
||||
* @param position
|
||||
* position at which to insert the mark.
|
||||
* @return index of newly added mark.
|
||||
*/
|
||||
int addMarkAtPosition(int position);
|
||||
}
|
||||
|
||||
@@ -30,278 +30,278 @@ import com.michaelbaranov.microba.marker.MarkerMutationModel;
|
||||
import com.michaelbaranov.microba.marker.ui.basic.BasicMarkerBarUI;
|
||||
|
||||
public class MarkerBarListener implements TableModelListener, MouseListener,
|
||||
MouseMotionListener, FocusListener, PropertyChangeListener,
|
||||
ComponentListener, ListSelectionListener {
|
||||
|
||||
private static final String VK_DELETE_KEY = "##VK_DELETE##";
|
||||
|
||||
private static final KeyStroke DELETE_KEYSTROKE = KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_DELETE, 0);
|
||||
|
||||
private final BasicMarkerBarUI barUI;
|
||||
|
||||
private MarkerBar bar;
|
||||
|
||||
private int holdingIndex = -1;
|
||||
|
||||
private int holdingShift;
|
||||
|
||||
public MarkerBarListener(BasicMarkerBarUI barUI, MarkerBar markerBar) {
|
||||
this.barUI = barUI;
|
||||
this.bar = markerBar;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
MouseMotionListener, FocusListener, PropertyChangeListener,
|
||||
ComponentListener, ListSelectionListener {
|
||||
|
||||
private static final String VK_DELETE_KEY = "##VK_DELETE##";
|
||||
|
||||
private static final KeyStroke DELETE_KEYSTROKE = KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_DELETE, 0);
|
||||
|
||||
private final BasicMarkerBarUI barUI;
|
||||
|
||||
private MarkerBar bar;
|
||||
|
||||
private int holdingIndex = -1;
|
||||
|
||||
private int holdingShift;
|
||||
|
||||
public MarkerBarListener(BasicMarkerBarUI barUI, MarkerBar markerBar) {
|
||||
this.barUI = barUI;
|
||||
this.bar = markerBar;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
|
||||
if (!bar.isEnabled())
|
||||
return;
|
||||
|
||||
this.barUI.calculateViewRectAndBaseline(bar);
|
||||
|
||||
bar.requestFocusInWindow();
|
||||
|
||||
BoundedTableModel dataModel = bar.getDataModel();
|
||||
ListSelectionModel selectionModel = bar.getSelectionModel();
|
||||
int dataColumn = bar.getPositionColumn();
|
||||
|
||||
if (SwingUtilities.isLeftMouseButton(e) && selectionModel != null
|
||||
&& dataModel != null) {
|
||||
handleLMBDown(e, dataModel, selectionModel, dataColumn);
|
||||
}
|
||||
if (SwingUtilities.isRightMouseButton(e) && dataModel != null) {
|
||||
handleRMBDown(e, dataModel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handleRMBDown(MouseEvent e, BoundedTableModel dataModel) {
|
||||
int logicalOffset;
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
logicalOffset = this.barUI.componentOffsetToLogicalOffset(e.getX(),
|
||||
dataModel);
|
||||
else
|
||||
logicalOffset = this.barUI.componentOffsetToLogicalOffset(e.getY(),
|
||||
dataModel);
|
||||
int logicalPos = dataModel.getLowerBound() + logicalOffset;
|
||||
if (!bar.isEnabled())
|
||||
return;
|
||||
|
||||
this.barUI.calculateViewRectAndBaseline(bar);
|
||||
|
||||
bar.requestFocusInWindow();
|
||||
|
||||
BoundedTableModel dataModel = bar.getDataModel();
|
||||
ListSelectionModel selectionModel = bar.getSelectionModel();
|
||||
int dataColumn = bar.getPositionColumn();
|
||||
|
||||
if (SwingUtilities.isLeftMouseButton(e) && selectionModel != null
|
||||
&& dataModel != null) {
|
||||
handleLMBDown(e, dataModel, selectionModel, dataColumn);
|
||||
}
|
||||
if (SwingUtilities.isRightMouseButton(e) && dataModel != null) {
|
||||
handleRMBDown(e, dataModel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handleRMBDown(MouseEvent e, BoundedTableModel dataModel) {
|
||||
int logicalOffset;
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
logicalOffset = this.barUI.componentOffsetToLogicalOffset(e.getX(),
|
||||
dataModel);
|
||||
else
|
||||
logicalOffset = this.barUI.componentOffsetToLogicalOffset(e.getY(),
|
||||
dataModel);
|
||||
int logicalPos = dataModel.getLowerBound() + logicalOffset;
|
||||
|
||||
if (logicalPos >= dataModel.getLowerBound()
|
||||
&& logicalPos <= dataModel.getUpperBound()) {
|
||||
if (logicalPos >= dataModel.getLowerBound()
|
||||
&& logicalPos <= dataModel.getUpperBound()) {
|
||||
|
||||
MarkerMutationModel mutationModel = bar.getMutationModel();
|
||||
if (mutationModel != null)
|
||||
mutationModel.addMarkAtPosition(logicalPos);
|
||||
MarkerMutationModel mutationModel = bar.getMutationModel();
|
||||
if (mutationModel != null)
|
||||
mutationModel.addMarkAtPosition(logicalPos);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleLMBDown(MouseEvent e, BoundedTableModel dataModel,
|
||||
ListSelectionModel selectionModel, int dataColumn) {
|
||||
private void handleLMBDown(MouseEvent e, BoundedTableModel dataModel,
|
||||
ListSelectionModel selectionModel, int dataColumn) {
|
||||
|
||||
int numAreas = dataModel.getRowCount();
|
||||
Polygon areas[] = this.barUI.calculateMarkerAreas(bar);
|
||||
int numAreas = dataModel.getRowCount();
|
||||
Polygon areas[] = this.barUI.calculateMarkerAreas(bar);
|
||||
|
||||
// try already selected
|
||||
for (int i = 0; i < numAreas; i++) {
|
||||
Polygon p = areas[i];
|
||||
if (p.contains(e.getPoint()) && selectionModel.isSelectedIndex(i)
|
||||
&& dataModel.isCellEditable(i, dataColumn)) {
|
||||
holdingIndex = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// try editable
|
||||
for (int i = 0; i < numAreas; i++) {
|
||||
Polygon p = areas[i];
|
||||
if (p.contains(e.getPoint())
|
||||
&& dataModel.isCellEditable(i, dataColumn)) {
|
||||
selectionModel.setSelectionInterval(i, i);
|
||||
holdingIndex = i;
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
holdingShift = e.getX() - p.xpoints[0];
|
||||
else
|
||||
holdingShift = e.getY() - p.ypoints[0];
|
||||
return;
|
||||
}
|
||||
}
|
||||
// try other
|
||||
for (int i = 0; i < numAreas; i++) {
|
||||
Polygon p = areas[i];
|
||||
if (p.contains(e.getPoint())) {
|
||||
selectionModel.setSelectionInterval(i, i);
|
||||
holdingIndex = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
selectionModel.clearSelection();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
holdingIndex = -1;
|
||||
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
|
||||
if (!bar.isEnabled())
|
||||
return;
|
||||
|
||||
BoundedTableModel dataModel = bar.getDataModel();
|
||||
if (holdingIndex >= 0 && dataModel != null) {
|
||||
int componentOffset;
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
componentOffset = e.getX() - holdingShift;
|
||||
else
|
||||
componentOffset = e.getY() - holdingShift;
|
||||
|
||||
int logicalOffset = this.barUI.componentOffsetToLogicalOffset(
|
||||
componentOffset, dataModel);
|
||||
int logicalPos = dataModel.getLowerBound() + logicalOffset;
|
||||
|
||||
if (logicalPos < dataModel.getLowerBound())
|
||||
logicalPos = dataModel.getLowerBound();
|
||||
if (logicalPos > dataModel.getUpperBound())
|
||||
logicalPos = dataModel.getUpperBound();
|
||||
|
||||
dataModel.setValueAt(new Integer(logicalPos), holdingIndex, bar
|
||||
.getPositionColumn());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void focusGained(FocusEvent e) {
|
||||
bar.repaint();
|
||||
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
bar.repaint();
|
||||
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
|
||||
if (evt.getSource() instanceof MarkerBar) {
|
||||
|
||||
if (MarkerBar.PROPERTY_DATA_MODEL.equals(evt.getPropertyName())) {
|
||||
BoundedTableModel oldModel = (BoundedTableModel) evt
|
||||
.getOldValue();
|
||||
BoundedTableModel newModel = (BoundedTableModel) evt
|
||||
.getNewValue();
|
||||
|
||||
if (oldModel != null)
|
||||
oldModel.removeTableModelListener(this);
|
||||
if (newModel != null)
|
||||
newModel.addTableModelListener(this);
|
||||
|
||||
holdingIndex = -1;
|
||||
bar.revalidate();
|
||||
}
|
||||
if (MarkerBar.PROPERTY_SELECTION_MODEL.equals(evt
|
||||
.getPropertyName())) {
|
||||
ListSelectionModel oldModel = (ListSelectionModel) evt
|
||||
.getOldValue();
|
||||
ListSelectionModel newModel = (ListSelectionModel) evt
|
||||
.getNewValue();
|
||||
|
||||
if (oldModel != null)
|
||||
oldModel.removeListSelectionListener(this);
|
||||
if (newModel != null)
|
||||
newModel.addListSelectionListener(this);
|
||||
// try already selected
|
||||
for (int i = 0; i < numAreas; i++) {
|
||||
Polygon p = areas[i];
|
||||
if (p.contains(e.getPoint()) && selectionModel.isSelectedIndex(i)
|
||||
&& dataModel.isCellEditable(i, dataColumn)) {
|
||||
holdingIndex = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// try editable
|
||||
for (int i = 0; i < numAreas; i++) {
|
||||
Polygon p = areas[i];
|
||||
if (p.contains(e.getPoint())
|
||||
&& dataModel.isCellEditable(i, dataColumn)) {
|
||||
selectionModel.setSelectionInterval(i, i);
|
||||
holdingIndex = i;
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
holdingShift = e.getX() - p.xpoints[0];
|
||||
else
|
||||
holdingShift = e.getY() - p.ypoints[0];
|
||||
return;
|
||||
}
|
||||
}
|
||||
// try other
|
||||
for (int i = 0; i < numAreas; i++) {
|
||||
Polygon p = areas[i];
|
||||
if (p.contains(e.getPoint())) {
|
||||
selectionModel.setSelectionInterval(i, i);
|
||||
holdingIndex = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
selectionModel.clearSelection();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
holdingIndex = -1;
|
||||
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
|
||||
if (!bar.isEnabled())
|
||||
return;
|
||||
|
||||
BoundedTableModel dataModel = bar.getDataModel();
|
||||
if (holdingIndex >= 0 && dataModel != null) {
|
||||
int componentOffset;
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
componentOffset = e.getX() - holdingShift;
|
||||
else
|
||||
componentOffset = e.getY() - holdingShift;
|
||||
|
||||
int logicalOffset = this.barUI.componentOffsetToLogicalOffset(
|
||||
componentOffset, dataModel);
|
||||
int logicalPos = dataModel.getLowerBound() + logicalOffset;
|
||||
|
||||
if (logicalPos < dataModel.getLowerBound())
|
||||
logicalPos = dataModel.getLowerBound();
|
||||
if (logicalPos > dataModel.getUpperBound())
|
||||
logicalPos = dataModel.getUpperBound();
|
||||
|
||||
dataModel.setValueAt(new Integer(logicalPos), holdingIndex, bar
|
||||
.getPositionColumn());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void focusGained(FocusEvent e) {
|
||||
bar.repaint();
|
||||
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
bar.repaint();
|
||||
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
|
||||
if (evt.getSource() instanceof MarkerBar) {
|
||||
|
||||
if (MarkerBar.PROPERTY_DATA_MODEL.equals(evt.getPropertyName())) {
|
||||
BoundedTableModel oldModel = (BoundedTableModel) evt
|
||||
.getOldValue();
|
||||
BoundedTableModel newModel = (BoundedTableModel) evt
|
||||
.getNewValue();
|
||||
|
||||
if (oldModel != null)
|
||||
oldModel.removeTableModelListener(this);
|
||||
if (newModel != null)
|
||||
newModel.addTableModelListener(this);
|
||||
|
||||
holdingIndex = -1;
|
||||
bar.revalidate();
|
||||
}
|
||||
if (MarkerBar.PROPERTY_SELECTION_MODEL.equals(evt
|
||||
.getPropertyName())) {
|
||||
ListSelectionModel oldModel = (ListSelectionModel) evt
|
||||
.getOldValue();
|
||||
ListSelectionModel newModel = (ListSelectionModel) evt
|
||||
.getNewValue();
|
||||
|
||||
if (oldModel != null)
|
||||
oldModel.removeListSelectionListener(this);
|
||||
if (newModel != null)
|
||||
newModel.addListSelectionListener(this);
|
||||
|
||||
holdingIndex = -1;
|
||||
bar.repaint();
|
||||
}
|
||||
if (MarkerBar.PROPERTY_MUTATION_MODEL
|
||||
.equals(evt.getPropertyName())) {
|
||||
// do not care
|
||||
}
|
||||
if (MarkerBar.PROPERTY_ORIENTATION.equals(evt.getPropertyName())) {
|
||||
holdingIndex = -1;
|
||||
bar.revalidate();
|
||||
}
|
||||
if (MarkerBar.PROPERTY_POSITION_COLUMN.equals(evt
|
||||
.getPropertyName())) {
|
||||
holdingIndex = -1;
|
||||
bar.repaint();
|
||||
}
|
||||
if ("enabled".equals(evt.getPropertyName())) {
|
||||
holdingIndex = -1;
|
||||
bar.repaint();
|
||||
}
|
||||
}
|
||||
if (evt.getSource() instanceof BoundedTableModel) {
|
||||
bar.revalidate();
|
||||
}
|
||||
holdingIndex = -1;
|
||||
bar.repaint();
|
||||
}
|
||||
if (MarkerBar.PROPERTY_MUTATION_MODEL
|
||||
.equals(evt.getPropertyName())) {
|
||||
// do not care
|
||||
}
|
||||
if (MarkerBar.PROPERTY_ORIENTATION.equals(evt.getPropertyName())) {
|
||||
holdingIndex = -1;
|
||||
bar.revalidate();
|
||||
}
|
||||
if (MarkerBar.PROPERTY_POSITION_COLUMN.equals(evt
|
||||
.getPropertyName())) {
|
||||
holdingIndex = -1;
|
||||
bar.repaint();
|
||||
}
|
||||
if ("enabled".equals(evt.getPropertyName())) {
|
||||
holdingIndex = -1;
|
||||
bar.repaint();
|
||||
}
|
||||
}
|
||||
if (evt.getSource() instanceof BoundedTableModel) {
|
||||
bar.revalidate();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void installKeyboardActions(JComponent c) {
|
||||
public void installKeyboardActions(JComponent c) {
|
||||
|
||||
c.getInputMap().put(DELETE_KEYSTROKE, VK_DELETE_KEY);
|
||||
c.getActionMap().put(VK_DELETE_KEY, new AbstractAction() {
|
||||
c.getInputMap().put(DELETE_KEYSTROKE, VK_DELETE_KEY);
|
||||
c.getActionMap().put(VK_DELETE_KEY, new AbstractAction() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
BoundedTableModel dataModel = bar.getDataModel();
|
||||
ListSelectionModel selectionModel = bar.getSelectionModel();
|
||||
MarkerMutationModel mutationModel = bar.getMutationModel();
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
BoundedTableModel dataModel = bar.getDataModel();
|
||||
ListSelectionModel selectionModel = bar.getSelectionModel();
|
||||
MarkerMutationModel mutationModel = bar.getMutationModel();
|
||||
|
||||
if (selectionModel != null && dataModel != null
|
||||
&& mutationModel != null
|
||||
&& !selectionModel.isSelectionEmpty()) {
|
||||
int selected = selectionModel.getLeadSelectionIndex();
|
||||
if (dataModel.isCellEditable(selected, bar
|
||||
.getPositionColumn())) {
|
||||
mutationModel.removeMarkerAtIndex(selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (selectionModel != null && dataModel != null
|
||||
&& mutationModel != null
|
||||
&& !selectionModel.isSelectionEmpty()) {
|
||||
int selected = selectionModel.getLeadSelectionIndex();
|
||||
if (dataModel.isCellEditable(selected, bar
|
||||
.getPositionColumn())) {
|
||||
mutationModel.removeMarkerAtIndex(selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void uninstallKeyboardActions(JComponent c) {
|
||||
c.getActionMap().remove(VK_DELETE_KEY);
|
||||
c.getInputMap().remove(DELETE_KEYSTROKE);
|
||||
}
|
||||
public void uninstallKeyboardActions(JComponent c) {
|
||||
c.getActionMap().remove(VK_DELETE_KEY);
|
||||
c.getInputMap().remove(DELETE_KEYSTROKE);
|
||||
}
|
||||
|
||||
public void componentResized(ComponentEvent e) {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void componentShown(ComponentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void tableChanged(TableModelEvent e) {
|
||||
bar.repaint();
|
||||
|
||||
}
|
||||
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
bar.repaint();
|
||||
|
||||
}
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void componentShown(ComponentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void tableChanged(TableModelEvent e) {
|
||||
bar.repaint();
|
||||
|
||||
}
|
||||
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
bar.repaint();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,184 +12,184 @@ import com.michaelbaranov.microba.marker.MarkerBar;
|
||||
|
||||
public class MarkerBarUI extends ComponentUI {
|
||||
|
||||
protected int MARKER_BODY_WIDTH = 12;
|
||||
protected int MARKER_BODY_WIDTH = 12;
|
||||
|
||||
protected int MARKER_BODY_HEIGHT = 12;
|
||||
protected int MARKER_BODY_HEIGHT = 12;
|
||||
|
||||
protected int MARKER_BICK_HEIGHT = 6;
|
||||
protected int MARKER_BICK_HEIGHT = 6;
|
||||
|
||||
protected int baselineLeft;
|
||||
protected int baselineLeft;
|
||||
|
||||
protected int baselineTop;
|
||||
protected int baselineTop;
|
||||
|
||||
protected int baselineLength;
|
||||
protected int baselineLength;
|
||||
|
||||
protected Rectangle viewRect = new Rectangle();
|
||||
protected Rectangle viewRect = new Rectangle();
|
||||
|
||||
protected Polygon[] polys = new Polygon[0];
|
||||
protected Polygon[] polys = new Polygon[0];
|
||||
|
||||
protected Polygon[] calculateMarkerAreas(MarkerBar bar) {
|
||||
protected Polygon[] calculateMarkerAreas(MarkerBar bar) {
|
||||
|
||||
BoundedTableModel model = bar.getDataModel();
|
||||
BoundedTableModel model = bar.getDataModel();
|
||||
|
||||
int count = model.getRowCount();
|
||||
int count = model.getRowCount();
|
||||
|
||||
if (polys.length < count) {
|
||||
// grow shared polygon array
|
||||
polys = new Polygon[count * 2];
|
||||
for (int i = 0; i < polys.length; i++) {
|
||||
int xx[] = new int[5];
|
||||
int yy[] = new int[5];
|
||||
Polygon p = new Polygon(xx, yy, 5);
|
||||
polys[i] = p;
|
||||
}
|
||||
}
|
||||
if (polys.length < count) {
|
||||
// grow shared polygon array
|
||||
polys = new Polygon[count * 2];
|
||||
for (int i = 0; i < polys.length; i++) {
|
||||
int xx[] = new int[5];
|
||||
int yy[] = new int[5];
|
||||
Polygon p = new Polygon(xx, yy, 5);
|
||||
polys[i] = p;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
int intValueAt = ((Integer) model.getValueAt(i, bar
|
||||
.getPositionColumn())).intValue();
|
||||
for (int i = 0; i < count; i++) {
|
||||
int intValueAt = ((Integer) model.getValueAt(i, bar
|
||||
.getPositionColumn())).intValue();
|
||||
|
||||
int logicalOffset = intValueAt - model.getLowerBound();
|
||||
int logicalOffset = intValueAt - model.getLowerBound();
|
||||
|
||||
int baselineOffset = logicalOffsetToBaselineOffset(logicalOffset,
|
||||
model);
|
||||
int xx[] = polys[i].xpoints;
|
||||
int yy[] = polys[i].ypoints;
|
||||
int baselineOffset = logicalOffsetToBaselineOffset(logicalOffset,
|
||||
model);
|
||||
int xx[] = polys[i].xpoints;
|
||||
int yy[] = polys[i].ypoints;
|
||||
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL) {
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL) {
|
||||
|
||||
int x = baselineLeft + baselineOffset;
|
||||
if (bar.isFliped()) {
|
||||
xx[0] = x;
|
||||
yy[0] = baselineTop;
|
||||
int x = baselineLeft + baselineOffset;
|
||||
if (bar.isFliped()) {
|
||||
xx[0] = x;
|
||||
yy[0] = baselineTop;
|
||||
|
||||
xx[1] = x + MARKER_BODY_WIDTH / 2;
|
||||
yy[1] = baselineTop + MARKER_BICK_HEIGHT;
|
||||
xx[1] = x + MARKER_BODY_WIDTH / 2;
|
||||
yy[1] = baselineTop + MARKER_BICK_HEIGHT;
|
||||
|
||||
xx[2] = x + MARKER_BODY_WIDTH / 2;
|
||||
yy[2] = baselineTop + MARKER_BICK_HEIGHT
|
||||
+ MARKER_BODY_HEIGHT;
|
||||
xx[2] = x + MARKER_BODY_WIDTH / 2;
|
||||
yy[2] = baselineTop + MARKER_BICK_HEIGHT
|
||||
+ MARKER_BODY_HEIGHT;
|
||||
|
||||
xx[3] = x - MARKER_BODY_WIDTH / 2;
|
||||
yy[3] = baselineTop + MARKER_BICK_HEIGHT
|
||||
+ MARKER_BODY_HEIGHT;
|
||||
xx[3] = x - MARKER_BODY_WIDTH / 2;
|
||||
yy[3] = baselineTop + MARKER_BICK_HEIGHT
|
||||
+ MARKER_BODY_HEIGHT;
|
||||
|
||||
xx[4] = x - MARKER_BODY_WIDTH / 2;
|
||||
yy[4] = baselineTop + MARKER_BICK_HEIGHT;
|
||||
xx[4] = x - MARKER_BODY_WIDTH / 2;
|
||||
yy[4] = baselineTop + MARKER_BICK_HEIGHT;
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
xx[0] = x;
|
||||
yy[0] = baselineTop;
|
||||
xx[0] = x;
|
||||
yy[0] = baselineTop;
|
||||
|
||||
xx[1] = x + MARKER_BODY_WIDTH / 2;
|
||||
yy[1] = baselineTop - MARKER_BICK_HEIGHT;
|
||||
xx[1] = x + MARKER_BODY_WIDTH / 2;
|
||||
yy[1] = baselineTop - MARKER_BICK_HEIGHT;
|
||||
|
||||
xx[2] = x + MARKER_BODY_WIDTH / 2;
|
||||
yy[2] = baselineTop - MARKER_BICK_HEIGHT
|
||||
- MARKER_BODY_HEIGHT;
|
||||
xx[2] = x + MARKER_BODY_WIDTH / 2;
|
||||
yy[2] = baselineTop - MARKER_BICK_HEIGHT
|
||||
- MARKER_BODY_HEIGHT;
|
||||
|
||||
xx[3] = x - MARKER_BODY_WIDTH / 2;
|
||||
yy[3] = baselineTop - MARKER_BICK_HEIGHT
|
||||
- MARKER_BODY_HEIGHT;
|
||||
xx[3] = x - MARKER_BODY_WIDTH / 2;
|
||||
yy[3] = baselineTop - MARKER_BICK_HEIGHT
|
||||
- MARKER_BODY_HEIGHT;
|
||||
|
||||
xx[4] = x - MARKER_BODY_WIDTH / 2;
|
||||
yy[4] = baselineTop - MARKER_BICK_HEIGHT;
|
||||
}
|
||||
xx[4] = x - MARKER_BODY_WIDTH / 2;
|
||||
yy[4] = baselineTop - MARKER_BICK_HEIGHT;
|
||||
}
|
||||
|
||||
} else {
|
||||
int y = baselineLeft + baselineOffset;
|
||||
} else {
|
||||
int y = baselineLeft + baselineOffset;
|
||||
|
||||
if (bar.isFliped()) {
|
||||
xx[0] = baselineTop;
|
||||
yy[0] = y;
|
||||
if (bar.isFliped()) {
|
||||
xx[0] = baselineTop;
|
||||
yy[0] = y;
|
||||
|
||||
yy[1] = y + MARKER_BODY_WIDTH / 2;
|
||||
xx[1] = baselineTop - MARKER_BICK_HEIGHT;
|
||||
yy[1] = y + MARKER_BODY_WIDTH / 2;
|
||||
xx[1] = baselineTop - MARKER_BICK_HEIGHT;
|
||||
|
||||
yy[2] = y + MARKER_BODY_WIDTH / 2;
|
||||
xx[2] = baselineTop - MARKER_BICK_HEIGHT
|
||||
- MARKER_BODY_HEIGHT;
|
||||
yy[2] = y + MARKER_BODY_WIDTH / 2;
|
||||
xx[2] = baselineTop - MARKER_BICK_HEIGHT
|
||||
- MARKER_BODY_HEIGHT;
|
||||
|
||||
yy[3] = y - MARKER_BODY_WIDTH / 2;
|
||||
xx[3] = baselineTop - MARKER_BICK_HEIGHT
|
||||
- MARKER_BODY_HEIGHT;
|
||||
yy[3] = y - MARKER_BODY_WIDTH / 2;
|
||||
xx[3] = baselineTop - MARKER_BICK_HEIGHT
|
||||
- MARKER_BODY_HEIGHT;
|
||||
|
||||
yy[4] = y - MARKER_BODY_WIDTH / 2;
|
||||
xx[4] = baselineTop - MARKER_BICK_HEIGHT;
|
||||
} else {
|
||||
yy[4] = y - MARKER_BODY_WIDTH / 2;
|
||||
xx[4] = baselineTop - MARKER_BICK_HEIGHT;
|
||||
} else {
|
||||
|
||||
xx[0] = baselineTop;
|
||||
yy[0] = y;
|
||||
xx[0] = baselineTop;
|
||||
yy[0] = y;
|
||||
|
||||
yy[1] = y + MARKER_BODY_WIDTH / 2;
|
||||
xx[1] = baselineTop + MARKER_BICK_HEIGHT;
|
||||
yy[1] = y + MARKER_BODY_WIDTH / 2;
|
||||
xx[1] = baselineTop + MARKER_BICK_HEIGHT;
|
||||
|
||||
yy[2] = y + MARKER_BODY_WIDTH / 2;
|
||||
xx[2] = baselineTop + MARKER_BICK_HEIGHT
|
||||
+ MARKER_BODY_HEIGHT;
|
||||
yy[2] = y + MARKER_BODY_WIDTH / 2;
|
||||
xx[2] = baselineTop + MARKER_BICK_HEIGHT
|
||||
+ MARKER_BODY_HEIGHT;
|
||||
|
||||
yy[3] = y - MARKER_BODY_WIDTH / 2;
|
||||
xx[3] = baselineTop + MARKER_BICK_HEIGHT
|
||||
+ MARKER_BODY_HEIGHT;
|
||||
yy[3] = y - MARKER_BODY_WIDTH / 2;
|
||||
xx[3] = baselineTop + MARKER_BICK_HEIGHT
|
||||
+ MARKER_BODY_HEIGHT;
|
||||
|
||||
yy[4] = y - MARKER_BODY_WIDTH / 2;
|
||||
xx[4] = baselineTop + MARKER_BICK_HEIGHT;
|
||||
}
|
||||
yy[4] = y - MARKER_BODY_WIDTH / 2;
|
||||
xx[4] = baselineTop + MARKER_BICK_HEIGHT;
|
||||
}
|
||||
|
||||
}
|
||||
polys[i].invalidate();
|
||||
}
|
||||
polys[i].invalidate();
|
||||
|
||||
}
|
||||
return polys;
|
||||
}
|
||||
}
|
||||
return polys;
|
||||
}
|
||||
|
||||
protected int logicalOffsetToBaselineOffset(int logicalOffset,
|
||||
BoundedTableModel model) {
|
||||
int positionRange = model.getUpperBound() - model.getLowerBound();
|
||||
return logicalOffset * baselineLength / positionRange;
|
||||
}
|
||||
protected int logicalOffsetToBaselineOffset(int logicalOffset,
|
||||
BoundedTableModel model) {
|
||||
int positionRange = model.getUpperBound() - model.getLowerBound();
|
||||
return logicalOffset * baselineLength / positionRange;
|
||||
}
|
||||
|
||||
protected int baselineOffsetToLogicalOffset(int baselineOffset,
|
||||
BoundedTableModel model) {
|
||||
int positionRange = model.getUpperBound() - model.getLowerBound();
|
||||
return baselineOffset * positionRange / baselineLength;
|
||||
}
|
||||
protected int baselineOffsetToLogicalOffset(int baselineOffset,
|
||||
BoundedTableModel model) {
|
||||
int positionRange = model.getUpperBound() - model.getLowerBound();
|
||||
return baselineOffset * positionRange / baselineLength;
|
||||
}
|
||||
|
||||
protected int componentOffsetToLogicalOffset(int componentOffsetLeft,
|
||||
BoundedTableModel dataModel) {
|
||||
return baselineOffsetToLogicalOffset(
|
||||
componentOffsetLeft - baselineLeft, dataModel);
|
||||
}
|
||||
protected int componentOffsetToLogicalOffset(int componentOffsetLeft,
|
||||
BoundedTableModel dataModel) {
|
||||
return baselineOffsetToLogicalOffset(
|
||||
componentOffsetLeft - baselineLeft, dataModel);
|
||||
}
|
||||
|
||||
protected void calculateViewRectAndBaseline(MarkerBar bar) {
|
||||
Insets insets = bar.getInsets();
|
||||
viewRect.x = insets.left;
|
||||
viewRect.y = insets.top;
|
||||
viewRect.width = bar.getWidth() - (insets.right + viewRect.x);
|
||||
viewRect.height = bar.getHeight() - (insets.bottom + viewRect.y);
|
||||
protected void calculateViewRectAndBaseline(MarkerBar bar) {
|
||||
Insets insets = bar.getInsets();
|
||||
viewRect.x = insets.left;
|
||||
viewRect.y = insets.top;
|
||||
viewRect.width = bar.getWidth() - (insets.right + viewRect.x);
|
||||
viewRect.height = bar.getHeight() - (insets.bottom + viewRect.y);
|
||||
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL) {
|
||||
baselineLeft = viewRect.x + MARKER_BODY_WIDTH / 2;
|
||||
baselineLength = viewRect.width - MARKER_BODY_WIDTH - 1;
|
||||
if (bar.isFliped()) {
|
||||
baselineTop = viewRect.y;
|
||||
} else {
|
||||
baselineTop = viewRect.y + viewRect.height - 1;
|
||||
}
|
||||
} else {
|
||||
baselineLeft = viewRect.y + MARKER_BODY_WIDTH / 2;
|
||||
baselineLength = viewRect.height - MARKER_BODY_WIDTH - 1;
|
||||
if (bar.isFliped()) {
|
||||
baselineTop = viewRect.x + viewRect.width - 1;
|
||||
} else {
|
||||
baselineTop = viewRect.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL) {
|
||||
baselineLeft = viewRect.x + MARKER_BODY_WIDTH / 2;
|
||||
baselineLength = viewRect.width - MARKER_BODY_WIDTH - 1;
|
||||
if (bar.isFliped()) {
|
||||
baselineTop = viewRect.y;
|
||||
} else {
|
||||
baselineTop = viewRect.y + viewRect.height - 1;
|
||||
}
|
||||
} else {
|
||||
baselineLeft = viewRect.y + MARKER_BODY_WIDTH / 2;
|
||||
baselineLength = viewRect.height - MARKER_BODY_WIDTH - 1;
|
||||
if (bar.isFliped()) {
|
||||
baselineTop = viewRect.x + viewRect.width - 1;
|
||||
} else {
|
||||
baselineTop = viewRect.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getMarkerSideGap() {
|
||||
return MARKER_BODY_WIDTH / 2;
|
||||
}
|
||||
public int getMarkerSideGap() {
|
||||
return MARKER_BODY_WIDTH / 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,253 +23,253 @@ import com.michaelbaranov.microba.marker.ui.MarkerBarUI;
|
||||
|
||||
public class BasicMarkerBarUI extends MarkerBarUI {
|
||||
|
||||
private Color selectionColor;
|
||||
private Color selectionColor;
|
||||
|
||||
private Color shadowColor;
|
||||
private Color shadowColor;
|
||||
|
||||
private Color focusColor;
|
||||
private Color focusColor;
|
||||
|
||||
private Color disabledColor;
|
||||
private Color disabledColor;
|
||||
|
||||
private Color normalColor;
|
||||
private Color normalColor;
|
||||
|
||||
private Color textColor;
|
||||
private Color textColor;
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new BasicMarkerBarUI();
|
||||
}
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new BasicMarkerBarUI();
|
||||
}
|
||||
|
||||
public void installUI(JComponent component) {
|
||||
installListeners((MarkerBar) component);
|
||||
installKeyboardActions((MarkerBar) component);
|
||||
installDefaults((MarkerBar) component);
|
||||
}
|
||||
public void installUI(JComponent component) {
|
||||
installListeners((MarkerBar) component);
|
||||
installKeyboardActions((MarkerBar) component);
|
||||
installDefaults((MarkerBar) component);
|
||||
}
|
||||
|
||||
public void uninstallUI(JComponent component) {
|
||||
uninstallListeners((MarkerBar) component);
|
||||
uninstallKeyboardActions((MarkerBar) component);
|
||||
}
|
||||
public void uninstallUI(JComponent component) {
|
||||
uninstallListeners((MarkerBar) component);
|
||||
uninstallKeyboardActions((MarkerBar) component);
|
||||
}
|
||||
|
||||
protected void installDefaults(MarkerBar bar) {
|
||||
LookAndFeel.installBorder(bar, "Slider.border");
|
||||
LookAndFeel.installColors(bar, "Slider.background", "Slider.foreground");
|
||||
protected void installDefaults(MarkerBar bar) {
|
||||
LookAndFeel.installBorder(bar, "Slider.border");
|
||||
LookAndFeel.installColors(bar, "Slider.background", "Slider.foreground");
|
||||
|
||||
// selectedmark
|
||||
selectionColor = UIManager.getColor("ComboBox.selectionBackground");
|
||||
// fixed mark
|
||||
disabledColor = UIManager.getColor("ComboBox.disabledBackground");
|
||||
normalColor = UIManager.getColor("ComboBox.background");
|
||||
// focus rect
|
||||
focusColor = UIManager.getColor("Slider.focus");
|
||||
// text & outline color
|
||||
textColor = UIManager.getColor("textText");
|
||||
// selectedmark
|
||||
selectionColor = UIManager.getColor("ComboBox.selectionBackground");
|
||||
// fixed mark
|
||||
disabledColor = UIManager.getColor("ComboBox.disabledBackground");
|
||||
normalColor = UIManager.getColor("ComboBox.background");
|
||||
// focus rect
|
||||
focusColor = UIManager.getColor("Slider.focus");
|
||||
// text & outline color
|
||||
textColor = UIManager.getColor("textText");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void installKeyboardActions(MarkerBar bar) {
|
||||
MarkerBarListener listener = lookupListsner(bar);
|
||||
if (listener != null)
|
||||
listener.installKeyboardActions(bar);
|
||||
protected void installKeyboardActions(MarkerBar bar) {
|
||||
MarkerBarListener listener = lookupListsner(bar);
|
||||
if (listener != null)
|
||||
listener.installKeyboardActions(bar);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void uninstallKeyboardActions(MarkerBar bar) {
|
||||
MarkerBarListener listener = lookupListsner(bar);
|
||||
if (listener != null)
|
||||
listener.uninstallKeyboardActions(bar);
|
||||
protected void uninstallKeyboardActions(MarkerBar bar) {
|
||||
MarkerBarListener listener = lookupListsner(bar);
|
||||
if (listener != null)
|
||||
listener.uninstallKeyboardActions(bar);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void installListeners(MarkerBar markerBar) {
|
||||
MarkerBarListener listener = createListener(markerBar);
|
||||
protected void installListeners(MarkerBar markerBar) {
|
||||
MarkerBarListener listener = createListener(markerBar);
|
||||
|
||||
if (markerBar.getDataModel() != null)
|
||||
markerBar.getDataModel().addTableModelListener(listener);
|
||||
if (markerBar.getSelectionModel() != null)
|
||||
markerBar.getSelectionModel().addListSelectionListener(listener);
|
||||
markerBar.addMouseListener(listener);
|
||||
markerBar.addMouseMotionListener(listener);
|
||||
markerBar.addFocusListener(listener);
|
||||
markerBar.addPropertyChangeListener(listener);
|
||||
markerBar.addComponentListener(listener);
|
||||
}
|
||||
if (markerBar.getDataModel() != null)
|
||||
markerBar.getDataModel().addTableModelListener(listener);
|
||||
if (markerBar.getSelectionModel() != null)
|
||||
markerBar.getSelectionModel().addListSelectionListener(listener);
|
||||
markerBar.addMouseListener(listener);
|
||||
markerBar.addMouseMotionListener(listener);
|
||||
markerBar.addFocusListener(listener);
|
||||
markerBar.addPropertyChangeListener(listener);
|
||||
markerBar.addComponentListener(listener);
|
||||
}
|
||||
|
||||
protected void uninstallListeners(MarkerBar markerBar) {
|
||||
MarkerBarListener listener = lookupListsner(markerBar);
|
||||
if (listener != null) {
|
||||
if (markerBar.getDataModel() != null)
|
||||
markerBar.getDataModel().removeTableModelListener(listener);
|
||||
if (markerBar.getSelectionModel() != null)
|
||||
markerBar.getSelectionModel().removeListSelectionListener(listener);
|
||||
markerBar.removeMouseListener(listener);
|
||||
markerBar.removeMouseMotionListener(listener);
|
||||
markerBar.removeFocusListener(listener);
|
||||
markerBar.removePropertyChangeListener(listener);
|
||||
markerBar.addComponentListener(listener);
|
||||
}
|
||||
protected void uninstallListeners(MarkerBar markerBar) {
|
||||
MarkerBarListener listener = lookupListsner(markerBar);
|
||||
if (listener != null) {
|
||||
if (markerBar.getDataModel() != null)
|
||||
markerBar.getDataModel().removeTableModelListener(listener);
|
||||
if (markerBar.getSelectionModel() != null)
|
||||
markerBar.getSelectionModel().removeListSelectionListener(listener);
|
||||
markerBar.removeMouseListener(listener);
|
||||
markerBar.removeMouseMotionListener(listener);
|
||||
markerBar.removeFocusListener(listener);
|
||||
markerBar.removePropertyChangeListener(listener);
|
||||
markerBar.addComponentListener(listener);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected MarkerBarListener lookupListsner(MarkerBar markerBar) {
|
||||
MouseMotionListener[] listeners = markerBar.getMouseMotionListeners();
|
||||
protected MarkerBarListener lookupListsner(MarkerBar markerBar) {
|
||||
MouseMotionListener[] listeners = markerBar.getMouseMotionListeners();
|
||||
|
||||
if (listeners != null) {
|
||||
for (int counter = 0; counter < listeners.length; counter++) {
|
||||
if (listeners[counter] instanceof MarkerBarListener) {
|
||||
return (MarkerBarListener) listeners[counter];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (listeners != null) {
|
||||
for (int counter = 0; counter < listeners.length; counter++) {
|
||||
if (listeners[counter] instanceof MarkerBarListener) {
|
||||
return (MarkerBarListener) listeners[counter];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected MarkerBarListener createListener(MarkerBar markerBar) {
|
||||
return new MarkerBarListener(this, markerBar);
|
||||
}
|
||||
protected MarkerBarListener createListener(MarkerBar markerBar) {
|
||||
return new MarkerBarListener(this, markerBar);
|
||||
}
|
||||
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
|
||||
MarkerBar bar = (MarkerBar) c;
|
||||
MarkerBar bar = (MarkerBar) c;
|
||||
|
||||
calculateViewRectAndBaseline(bar);
|
||||
calculateViewRectAndBaseline(bar);
|
||||
|
||||
if (bar.isFocusOwner())
|
||||
drawFocusRect(g, viewRect);
|
||||
if (bar.isFocusOwner())
|
||||
drawFocusRect(g, viewRect);
|
||||
|
||||
BoundedTableModel dataModel = bar.getDataModel();
|
||||
if (dataModel == null)
|
||||
return;
|
||||
BoundedTableModel dataModel = bar.getDataModel();
|
||||
if (dataModel == null)
|
||||
return;
|
||||
|
||||
int numAreas = dataModel.getRowCount();
|
||||
Polygon areas[] = calculateMarkerAreas(bar);
|
||||
int numAreas = dataModel.getRowCount();
|
||||
Polygon areas[] = calculateMarkerAreas(bar);
|
||||
|
||||
ListSelectionModel selectionModel = bar.getSelectionModel();
|
||||
ListSelectionModel selectionModel = bar.getSelectionModel();
|
||||
|
||||
for (int i = 0; i < numAreas; i++) {
|
||||
boolean isMovable = dataModel.isCellEditable(i, bar.getPositionColumn());
|
||||
boolean isLeadSelect = (selectionModel == null || selectionModel
|
||||
.isSelectionEmpty()) ? false
|
||||
: selectionModel.getLeadSelectionIndex() == i;
|
||||
if (!isLeadSelect)
|
||||
drawMarker(g, areas[i], false, (Color) dataModel.getValueAt(i, bar
|
||||
.getColorColumn()));
|
||||
}
|
||||
for (int i = 0; i < numAreas; i++) {
|
||||
boolean isMovable = dataModel.isCellEditable(i, bar.getPositionColumn());
|
||||
boolean isLeadSelect = (selectionModel == null || selectionModel
|
||||
.isSelectionEmpty()) ? false
|
||||
: selectionModel.getLeadSelectionIndex() == i;
|
||||
if (!isLeadSelect)
|
||||
drawMarker(g, areas[i], false, (Color) dataModel.getValueAt(i, bar
|
||||
.getColorColumn()));
|
||||
}
|
||||
|
||||
if (selectionModel != null && !selectionModel.isSelectionEmpty()) {
|
||||
int selectedIndex = selectionModel.getLeadSelectionIndex();
|
||||
boolean isMovable = dataModel.isCellEditable(selectedIndex, bar
|
||||
.getPositionColumn());
|
||||
if (selectionModel != null && !selectionModel.isSelectionEmpty()) {
|
||||
int selectedIndex = selectionModel.getLeadSelectionIndex();
|
||||
boolean isMovable = dataModel.isCellEditable(selectedIndex, bar
|
||||
.getPositionColumn());
|
||||
|
||||
if (selectedIndex < numAreas) {
|
||||
drawMarker(g, areas[selectedIndex], /* bar.isFocusOwner() */
|
||||
true, (Color) dataModel.getValueAt(selectedIndex, bar.getColorColumn()));
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"Selection model inconsistent with data model: " + "element at "
|
||||
+ selectedIndex + " selected, but does not exist.");
|
||||
}
|
||||
}
|
||||
if (selectedIndex < numAreas) {
|
||||
drawMarker(g, areas[selectedIndex], /* bar.isFocusOwner() */
|
||||
true, (Color) dataModel.getValueAt(selectedIndex, bar.getColorColumn()));
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"Selection model inconsistent with data model: " + "element at "
|
||||
+ selectedIndex + " selected, but does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawFocusRect(Graphics g, Rectangle viewRect) {
|
||||
g.setColor(getFocusColor());
|
||||
protected void drawFocusRect(Graphics g, Rectangle viewRect) {
|
||||
g.setColor(getFocusColor());
|
||||
|
||||
BasicGraphicsUtils.drawDashedRect(g, viewRect.x, viewRect.y, viewRect.width,
|
||||
viewRect.height);
|
||||
}
|
||||
BasicGraphicsUtils.drawDashedRect(g, viewRect.x, viewRect.y, viewRect.width,
|
||||
viewRect.height);
|
||||
}
|
||||
|
||||
protected void drawMarker(Graphics g, Polygon p, boolean isSelected, Color color) {
|
||||
protected void drawMarker(Graphics g, Polygon p, boolean isSelected, Color color) {
|
||||
|
||||
Color innerColor = color != null ? color : getNormalColor();
|
||||
// Color selColor = getSelectionColor();
|
||||
Color selColor = isSelected ? getTextColor() : innerColor;
|
||||
Color innerColor = color != null ? color : getNormalColor();
|
||||
// Color selColor = getSelectionColor();
|
||||
Color selColor = isSelected ? getTextColor() : innerColor;
|
||||
|
||||
// body
|
||||
g.setColor(innerColor);
|
||||
g.fillPolygon(p);
|
||||
// body
|
||||
g.setColor(innerColor);
|
||||
g.fillPolygon(p);
|
||||
|
||||
// bick
|
||||
// bick
|
||||
|
||||
if (isSelected) {
|
||||
int xx[] = new int[3];
|
||||
int yy[] = new int[3];
|
||||
if (isSelected) {
|
||||
int xx[] = new int[3];
|
||||
int yy[] = new int[3];
|
||||
|
||||
xx[0] = p.xpoints[0];
|
||||
xx[1] = p.xpoints[1];
|
||||
xx[2] = p.xpoints[p.npoints - 1];
|
||||
yy[0] = p.ypoints[0];
|
||||
yy[1] = p.ypoints[1];
|
||||
yy[2] = p.ypoints[p.npoints - 1];
|
||||
xx[0] = p.xpoints[0];
|
||||
xx[1] = p.xpoints[1];
|
||||
xx[2] = p.xpoints[p.npoints - 1];
|
||||
yy[0] = p.ypoints[0];
|
||||
yy[1] = p.ypoints[1];
|
||||
yy[2] = p.ypoints[p.npoints - 1];
|
||||
|
||||
Polygon bickP = new Polygon(xx, yy, 3);
|
||||
g.setColor(selColor);
|
||||
g.fillPolygon(bickP);
|
||||
g.drawPolygon(bickP);
|
||||
}
|
||||
Polygon bickP = new Polygon(xx, yy, 3);
|
||||
g.setColor(selColor);
|
||||
g.fillPolygon(bickP);
|
||||
g.drawPolygon(bickP);
|
||||
}
|
||||
|
||||
// outline
|
||||
g.setColor(getTextColor());
|
||||
g.drawPolygon(p);
|
||||
// outline
|
||||
g.setColor(getTextColor());
|
||||
g.drawPolygon(p);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize(JComponent c) {
|
||||
MarkerBar bar = (MarkerBar) c;
|
||||
Insets ins = bar.getInsets();
|
||||
public Dimension getMinimumSize(JComponent c) {
|
||||
MarkerBar bar = (MarkerBar) c;
|
||||
Insets ins = bar.getInsets();
|
||||
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
return new Dimension(MARKER_BODY_WIDTH + ins.left + ins.right + 1,
|
||||
MARKER_BODY_HEIGHT + ins.top + ins.bottom + 1);
|
||||
else
|
||||
return new Dimension(MARKER_BODY_HEIGHT + ins.top + ins.bottom + 1,
|
||||
MARKER_BODY_WIDTH + ins.left + ins.right + 1);
|
||||
}
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
return new Dimension(MARKER_BODY_WIDTH + ins.left + ins.right + 1,
|
||||
MARKER_BODY_HEIGHT + ins.top + ins.bottom + 1);
|
||||
else
|
||||
return new Dimension(MARKER_BODY_HEIGHT + ins.top + ins.bottom + 1,
|
||||
MARKER_BODY_WIDTH + ins.left + ins.right + 1);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
|
||||
MarkerBar bar = (MarkerBar) c;
|
||||
BoundedTableModel dataModel = bar.getDataModel();
|
||||
Insets ins = bar.getInsets();
|
||||
MarkerBar bar = (MarkerBar) c;
|
||||
BoundedTableModel dataModel = bar.getDataModel();
|
||||
Insets ins = bar.getInsets();
|
||||
|
||||
int r;
|
||||
if (dataModel == null)
|
||||
r = 1;
|
||||
else
|
||||
r = dataModel.getUpperBound() - dataModel.getLowerBound();
|
||||
int r;
|
||||
if (dataModel == null)
|
||||
r = 1;
|
||||
else
|
||||
r = dataModel.getUpperBound() - dataModel.getLowerBound();
|
||||
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
return new Dimension((r) * 2 + MARKER_BODY_WIDTH + ins.left + ins.right + 1,
|
||||
MARKER_BODY_HEIGHT + MARKER_BICK_HEIGHT + ins.top + ins.bottom + 1);
|
||||
else
|
||||
return new Dimension(MARKER_BODY_HEIGHT + MARKER_BICK_HEIGHT + ins.top
|
||||
+ ins.bottom + 1, (r) * 2 + MARKER_BODY_WIDTH + ins.left + ins.right
|
||||
+ 1);
|
||||
if (bar.getOrientation() == SwingConstants.HORIZONTAL)
|
||||
return new Dimension((r) * 2 + MARKER_BODY_WIDTH + ins.left + ins.right + 1,
|
||||
MARKER_BODY_HEIGHT + MARKER_BICK_HEIGHT + ins.top + ins.bottom + 1);
|
||||
else
|
||||
return new Dimension(MARKER_BODY_HEIGHT + MARKER_BICK_HEIGHT + ins.top
|
||||
+ ins.bottom + 1, (r) * 2 + MARKER_BODY_WIDTH + ins.left + ins.right
|
||||
+ 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Color getFocusColor() {
|
||||
return focusColor;
|
||||
}
|
||||
public Color getFocusColor() {
|
||||
return focusColor;
|
||||
}
|
||||
|
||||
public Color getShadowColor() {
|
||||
return shadowColor;
|
||||
}
|
||||
public Color getShadowColor() {
|
||||
return shadowColor;
|
||||
}
|
||||
|
||||
public Color getNormalColor() {
|
||||
return normalColor;
|
||||
}
|
||||
public Color getNormalColor() {
|
||||
return normalColor;
|
||||
}
|
||||
|
||||
public Color getSelectionColor() {
|
||||
return selectionColor;
|
||||
}
|
||||
public Color getSelectionColor() {
|
||||
return selectionColor;
|
||||
}
|
||||
|
||||
public Color getDisabledColor() {
|
||||
return disabledColor;
|
||||
}
|
||||
public Color getDisabledColor() {
|
||||
return disabledColor;
|
||||
}
|
||||
|
||||
public Color getTextColor() {
|
||||
return textColor;
|
||||
}
|
||||
public Color getTextColor() {
|
||||
return textColor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ import com.michaelbaranov.microba.marker.ui.basic.BasicMarkerBarUI;
|
||||
|
||||
public class MetalMarkerBarUI extends BasicMarkerBarUI {
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MetalMarkerBarUI();
|
||||
}
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MetalMarkerBarUI();
|
||||
}
|
||||
|
||||
protected void drawFocusRect(Graphics g, Rectangle viewRect) {
|
||||
g.setColor(getFocusColor());
|
||||
protected void drawFocusRect(Graphics g, Rectangle viewRect) {
|
||||
g.setColor(getFocusColor());
|
||||
|
||||
g.drawRect(viewRect.x, viewRect.y, viewRect.width - 1, viewRect.height - 1);
|
||||
}
|
||||
g.drawRect(viewRect.x, viewRect.y, viewRect.width - 1, viewRect.height - 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ import com.michaelbaranov.microba.marker.ui.basic.BasicMarkerBarUI;
|
||||
|
||||
public class MotifMarkerBarUI extends BasicMarkerBarUI {
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MotifMarkerBarUI();
|
||||
}
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MotifMarkerBarUI();
|
||||
}
|
||||
|
||||
protected void drawFocusRect(Graphics g, Rectangle viewRect) {
|
||||
// focus painting is handled by the border
|
||||
}
|
||||
protected void drawFocusRect(Graphics g, Rectangle viewRect) {
|
||||
// focus painting is handled by the border
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,39 +13,39 @@ import com.michaelbaranov.microba.marker.ui.basic.BasicMarkerBarUI;
|
||||
|
||||
public class WindowsMarkerBarUI extends BasicMarkerBarUI {
|
||||
|
||||
private int dashedRectGapX;
|
||||
private int dashedRectGapX;
|
||||
|
||||
private int dashedRectGapY;
|
||||
private int dashedRectGapY;
|
||||
|
||||
private int dashedRectGapWidth;
|
||||
private int dashedRectGapWidth;
|
||||
|
||||
private int dashedRectGapHeight;
|
||||
private int dashedRectGapHeight;
|
||||
|
||||
private boolean defaults_initialized;
|
||||
private boolean defaults_initialized;
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new WindowsMarkerBarUI();
|
||||
}
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new WindowsMarkerBarUI();
|
||||
}
|
||||
|
||||
protected void drawFocusRect(Graphics g, Rectangle viewRect) {
|
||||
g.setColor(getFocusColor());
|
||||
protected void drawFocusRect(Graphics g, Rectangle viewRect) {
|
||||
g.setColor(getFocusColor());
|
||||
|
||||
g.setColor(getFocusColor());
|
||||
// BasicGraphicsUtils.drawDashedRect(g, dashedRectGapX, dashedRectGapY,
|
||||
// viewRect.width - dashedRectGapWidth, viewRect.height
|
||||
// - dashedRectGapHeight);
|
||||
BasicGraphicsUtils.drawDashedRect(g, viewRect.x, viewRect.y, viewRect.width - 1,
|
||||
viewRect.height - 1);
|
||||
}
|
||||
g.setColor(getFocusColor());
|
||||
// BasicGraphicsUtils.drawDashedRect(g, dashedRectGapX, dashedRectGapY,
|
||||
// viewRect.width - dashedRectGapWidth, viewRect.height
|
||||
// - dashedRectGapHeight);
|
||||
BasicGraphicsUtils.drawDashedRect(g, viewRect.x, viewRect.y, viewRect.width - 1,
|
||||
viewRect.height - 1);
|
||||
}
|
||||
|
||||
protected void installDefaults(MarkerBar b) {
|
||||
super.installDefaults(b);
|
||||
// if(!defaults_initialized) {
|
||||
dashedRectGapX = UIManager.getInt("Button.dashedRectGapX");
|
||||
dashedRectGapY = UIManager.getInt("Button.dashedRectGapY");
|
||||
dashedRectGapWidth = UIManager.getInt("Button.dashedRectGapWidth");
|
||||
dashedRectGapHeight = UIManager.getInt("Button.dashedRectGapHeight");
|
||||
// focusColor = UIManager.getColor(pp + "focus");
|
||||
defaults_initialized = true;
|
||||
}
|
||||
protected void installDefaults(MarkerBar b) {
|
||||
super.installDefaults(b);
|
||||
// if(!defaults_initialized) {
|
||||
dashedRectGapX = UIManager.getInt("Button.dashedRectGapX");
|
||||
dashedRectGapY = UIManager.getInt("Button.dashedRectGapY");
|
||||
dashedRectGapWidth = UIManager.getInt("Button.dashedRectGapWidth");
|
||||
dashedRectGapHeight = UIManager.getInt("Button.dashedRectGapHeight");
|
||||
// focusColor = UIManager.getColor(pp + "focus");
|
||||
defaults_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user