Example usage for javax.swing JComboBox isEnabled

List of usage examples for javax.swing JComboBox isEnabled

Introduction

In this page you can find the example usage for javax.swing JComboBox isEnabled.

Prototype

public boolean isEnabled() 

Source Link

Document

Determines whether this component is enabled.

Usage

From source file:main.UIController.java

/******** FROM GREGORIAN **********/

public void updateDayComboGregorian() {
    UI window = this.getUi();

    JTextField year = window.getYear();
    JComboBox month = window.getMonth();
    JComboBox day = window.getDay();
    JButton convert = window.getToImladris();
    JTextPane result = window.getResImladris();
    String value = year.getText();
    if (!value.isEmpty()) {
        try {//from   w ww  . jav a 2s .c o  m
            int yearNum = Integer.parseInt(value);
            if (yearNum > 0 && yearNum <= GregorianInfo.MAX_SUPPORTED_YEAR) {
                int monthNum = month.getSelectedIndex() + 1;
                int daySel = 0;
                if (day.isEnabled()) {
                    daySel = day.getSelectedIndex() + 1;
                }
                ArrayList<Integer> days = GregorianInfo.getInstance().getDaysArray(yearNum, monthNum);
                day.setModel(new DefaultComboBoxModel(days.toArray()));
                if (daySel > 0 && daySel <= days.size()) {
                    day.setSelectedIndex(daySel - 1);
                }
                day.setEnabled(true);
                convert.setEnabled(true);
                result.setText("");
            } else {
                day.setEnabled(false);
                convert.setEnabled(false);
                day.setModel(new DefaultComboBoxModel());
                result.setText("");
            }
        } catch (NumberFormatException e) {
            day.setEnabled(false);
            convert.setEnabled(false);
            day.setModel(new DefaultComboBoxModel());
            result.setText("");
        }
    } else {
        day.setEnabled(false);
        convert.setEnabled(false);
        day.setModel(new DefaultComboBoxModel());
        result.setText("");
    }
}

From source file:main.UIController.java

@SuppressWarnings("deprecation")
public void convertToImladris() {
    UI window = this.getUi();

    String errorEmptyYear = "Please insert a year.";
    String errorYearNotNumeric = "Please insert the year as a numeric value.";
    String errorYearNotValid = "Please insert a valid year (from 1 to "
            + Integer.toString(GregorianInfo.MAX_SUPPORTED_YEAR) + ").";
    String errorDayNotRead = "Sorry, the day could not be read.";

    JTextField year = window.getYear();
    JComboBox month = window.getMonth();
    JComboBox day = window.getDay();
    JCheckBox afterSunset = window.getAfterSunset();
    JTextPane result = window.getResImladris();
    String value = year.getText();
    if (!value.isEmpty()) {
        try {//from   www  . j a v a2s  .c  o  m
            int yearNum = Integer.parseInt(value);
            if (yearNum > 0 && yearNum <= GregorianInfo.MAX_SUPPORTED_YEAR) {
                int monthNum = month.getSelectedIndex() + 1;
                int dayNum = 0;
                if (day.isEnabled()) {
                    dayNum = day.getSelectedIndex() + 1;
                    ImladrisCalendar cal;
                    if (afterSunset.isSelected()) {
                        GregorianCalendar gcal = new GregorianCalendar(yearNum, monthNum, dayNum);
                        Time time = this.calculateSunsetForActualLocation(gcal, true);
                        cal = new ImladrisCalendar(time, yearNum, monthNum, dayNum, time.getHours(),
                                time.getMinutes(), time.getSeconds());
                    } else {
                        cal = new ImladrisCalendar(yearNum, monthNum, dayNum);
                    }
                    result.setText(cal.toString());
                } else {
                    result.setText(errorDayNotRead);
                }
            } else {
                result.setText(errorYearNotValid);
            }
        } catch (NumberFormatException e) {
            result.setText(errorYearNotNumeric);
        }
    } else {
        result.setText(errorEmptyYear);
    }
}

From source file:main.UIController.java

/************* TO GREGORIAN *************/

public void updateDayComboImladris() {
    UI window = this.getUi();

    JComboBox yen = window.getYen();
    JTextField loa = window.getLoa();
    JComboBox period = window.getPeriod();
    JComboBox day = window.getDayOfLoa();
    JButton convert = window.getToGregorian();
    JTextPane result = window.getResGregorian();
    int yenNum = yen.getSelectedIndex() + 1;
    String value = loa.getText();
    if (!value.isEmpty()) {
        try {//  w w w.ja v a  2s .  c o  m
            int loaNum = Integer.parseInt(value);
            if (loaNum > 0 && loaNum <= 144) {
                int periodNum = period.getSelectedIndex() + 1;
                if (periodNum == ImladrisCalendar.YESTARE || periodNum == ImladrisCalendar.METTARE) {
                    day.setEnabled(false);
                    day.setModel(new DefaultComboBoxModel());
                    convert.setEnabled(true);
                    result.setText("");
                } else {
                    int daySel = 0;
                    if (day.isEnabled()) {
                        daySel = day.getSelectedIndex() + 1;
                    }
                    ArrayList<Integer> days = ImladrisInfo.getInstance().getDaysArray(yenNum, loaNum,
                            periodNum);
                    day.setModel(new DefaultComboBoxModel(days.toArray()));
                    if (daySel > 0 && daySel <= days.size()) {
                        day.setSelectedIndex(daySel - 1);
                    }
                    day.setEnabled(true);
                    convert.setEnabled(true);
                    result.setText("");
                }
            } else {
                day.setEnabled(false);
                convert.setEnabled(false);
                day.setModel(new DefaultComboBoxModel());
                result.setText("");
            }
        } catch (NumberFormatException e) {
            day.setEnabled(false);
            convert.setEnabled(false);
            day.setModel(new DefaultComboBoxModel());
            result.setText("");
        }
    } else {
        day.setEnabled(false);
        convert.setEnabled(false);
        day.setModel(new DefaultComboBoxModel());
        result.setText("");
    }
}

From source file:main.UIController.java

public void convertToGregorian() {
    UI window = this.getUi();

    String errorNoLoa = "Please insert a loa.";
    String errorLoaNotNumeric = "Please insert the loa as a numeric value.";
    String errorYearNotValid = "Please insert a valid loa (from 1 to 144).";
    String errorDayNotRead = "Sorry, the day could not be read.";

    JComboBox yen = window.getYen();
    JTextField loa = window.getLoa();
    JComboBox period = window.getPeriod();
    JComboBox day = window.getDayOfLoa();
    JCheckBox beforeMidnight = window.getBeforeMidnight();
    JTextPane result = window.getResGregorian();
    int yenNum = yen.getSelectedIndex() + 1;
    String value = loa.getText();
    if (!value.isEmpty()) {
        try {//from   www  . j  a v  a  2  s .  c o  m
            int loaNum = Integer.parseInt(value);
            if (loaNum > 0 && loaNum <= 144) {
                int periodNum = period.getSelectedIndex() + 1;
                ImladrisCalendar cal = new ImladrisCalendar();
                boolean success = false;
                if (periodNum == ImladrisCalendar.YESTARE || periodNum == ImladrisCalendar.METTARE) {
                    success = true;
                    cal = new ImladrisCalendar(cal.intToRoman(yenNum), loaNum, periodNum);
                } else {
                    int dayNum = 0;
                    if (day.isEnabled()) {
                        success = true;
                        dayNum = day.getSelectedIndex() + 1;
                        cal = new ImladrisCalendar(cal.intToRoman(yenNum), loaNum, periodNum, dayNum);
                    } else {
                        result.setText(errorDayNotRead);
                    }
                }
                if (success) {
                    GregorianCalendar gcal = cal.getGregorian();
                    if (beforeMidnight.isSelected()) {
                        gcal.add(GregorianCalendar.DAY_OF_YEAR, -1);
                    }
                    String gstr = this.gregorianToString(gcal);
                    result.setText(gstr);
                }
            } else {
                result.setText(errorYearNotValid);
            }
        } catch (NumberFormatException e) {
            result.setText(errorLoaNotNumeric);
        }
    } else {
        result.setText(errorNoLoa);
    }
}