⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optionspagebuilder.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        else {            optionPanel.add(optionComponent, BorderLayout.WEST);        }        JPanel result = new JPanel(new BorderLayout());        result.add(optionPanel, BorderLayout.NORTH);        return result;    }        private Component createOptionLabel(GPOption option) {        JLabel nextLabel = new JLabel(myi18n.getOptionLabel(option));        nextLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 3));        return nextLabel;    }    private Component createOptionComponent(GPOption option) {        final Component result;        if (option instanceof EnumerationOption) {            result = createEnumerationComponent((EnumerationOption) option);        } else if (option instanceof BooleanOption) {            result = createBooleanComponent((BooleanOption) option);        }        else if (option instanceof ColorOption) {            result = createColorComponent((ColorOption)option);        }        else if (option instanceof DateOption) {            result = createDateComponent((DateOption)option);        }        else if (option instanceof GPOptionGroup) {            result = createButtonComponent((GPOptionGroup)option);        }        else if (option instanceof StringOption) {            result = createStringComponent((StringOption)option);        }        else {            result = new JLabel("Unknown option class=" + option.getClass());        }        if (!option.isWritable()) {            result.setEnabled(false);        }        option.addPropertyChangeListener(new PropertyChangeListener() {            public void propertyChange(PropertyChangeEvent evt) {                if (GPOption.PROPERTY_IS_WRITABLE.equals(evt.getPropertyName())) {                    result.setEnabled((Boolean)evt.getNewValue());                }            }        });        return result;    }    private Color getValidFieldColor() {        return UIManager.getColor("TextField.background");    }    private Component createStringComponent(final StringOption option) {        final JTextField result = new JTextField(option.getValue());        final DocumentListener listener = new DocumentListener() {        	private void saveValue() {            	try {            		option.setValue(result.getText());            		result.setBackground(getValidFieldColor());            	}            	catch(ValidationException ex) {            		result.setBackground(INVALID_FIELD_COLOR);            	}        		        	}            public void insertUpdate(DocumentEvent e) {            	saveValue();            }            public void removeUpdate(DocumentEvent e) {            	saveValue();            }            public void changedUpdate(DocumentEvent e) {            	saveValue();            }        };        result.getDocument().addDocumentListener(listener);        option.addChangeValueListener(new ChangeValueListener() {			public void changeValue(ChangeValueEvent event) {				result.getDocument().removeDocumentListener(listener);                if (!result.getText().equals(event.getNewValue())) {                    result.setText(option.getValue());                }				result.getDocument().addDocumentListener(listener);			}        });        return result;    }    private Component createButtonComponent(GPOptionGroup optionGroup) {        Action action = new AbstractAction(myi18n.getAdvancedActionTitle()) {            public void actionPerformed(ActionEvent e) {                System.err                        .println("[OptionsPageBuilder] createButtonComponent: ");            }                    };        JButton result = new JButton(action);        return result;    }    private Component createBooleanComponent(BooleanOption option) {        JCheckBox result = new JCheckBox(new BooleanOptionAction(option));        result.setText("");        result.setHorizontalAlignment(JCheckBox.LEFT);        result.setHorizontalTextPosition(SwingConstants.TRAILING);        result.setSelected(option.isChecked());        ComponentOrientation componentOrientation = GanttLanguage.getInstance().getComponentOrientation();        result.setComponentOrientation(componentOrientation);        return result;    }    private JComboBox createEnumerationComponent(EnumerationOption option) {        ComboBoxModel model = new EnumerationOptionComboBoxModel(option);        JComboBox result = new JComboBox(model);        return result;    }    private Component createColorComponent(final ColorOption option) {        final JButton colorButton = new JButton();        Action action = new AbstractAction(myi18n.getColorButtonText(option)) {            public void actionPerformed(ActionEvent e) {                ActionListener onOkPressing = new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        Color color = ourColorChooser.getColor();                        colorButton.setBackground(color);                        option.setValue(color);                    }                };                ActionListener onCancelPressing = new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        // nothing to do for "Cancel"                    }                };                JDialog dialog = JColorChooser.createDialog(myParentComponent,                        myi18n.getColorChooserTitle(option), true,                        ourColorChooser, onOkPressing, onCancelPressing);                ourColorChooser.setColor(colorButton.getBackground());                dialog.setVisible(true);            };        };        colorButton.setAction(action);        colorButton.setBackground(option.getValue());        return colorButton;    }        private Component createDateComponent(final DateOption option) {        final JXDatePicker result = new JXDatePicker();        result.setDate(option.getValue());        /*        result.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                try {                    option.setValue(((JXDatePicker)e.getSource()).getDate());                    result.getEditor().setBackground(getValidFieldColor());                }                catch(ValidationException ex) {                    result.getEditor().setBackground(INVALID_FIELD_COLOR);                }            }        });        */        result.getEditor().addPropertyChangeListener("value", new PropertyChangeListener() {			public void propertyChange(PropertyChangeEvent evt) {                try {                    option.setValue(result.getDate());                    result.getEditor().setBackground(getValidFieldColor());                }                catch(ValidationException ex) {                    result.getEditor().setBackground(INVALID_FIELD_COLOR);                }			}        	        });        if (option instanceof ChangeValueDispatcher) {            ((ChangeValueDispatcher)option).addChangeValueListener(new ChangeValueListener() {                public void changeValue(ChangeValueEvent event) {                    assert event.getNewValue() instanceof Date;                    result.setDate((Date) event.getNewValue());                }            });        }                return result;    }            private static JColorChooser ourColorChooser = new JColorChooser();        static {        ImageIcon calendarImage = new ImageIcon(OptionsPageBuilder.class.getResource(        "/icons/calendar_16.gif"));                Icon nextMonth = new ImageIcon(OptionsPageBuilder.class                .getResource("/icons/nextmonth.gif"));        Icon prevMonth = new ImageIcon(OptionsPageBuilder.class                .getResource("/icons/prevmonth.gif"));        UIManager.put("JXDatePicker.arrowDown.image", calendarImage);        UIManager.put("JXMonthView.monthUp.image", prevMonth);        UIManager.put("JXMonthView.monthDown.image", nextMonth);        UIManager.put("JXMonthView.monthCurrent.image", calendarImage);            }}

⌨️ 快捷键说明

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