Example usage for javax.swing JComboBox getSelectedIndex

List of usage examples for javax.swing JComboBox getSelectedIndex

Introduction

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

Prototype

@Transient
public int getSelectedIndex() 

Source Link

Document

Returns the first item in the list that matches the given item.

Usage

From source file:com.biosis.biosislite.vistas.Configuracion.java

private void guardar(Properties fichero, String urlFichero, JComboBox combo, JTextField txtConexion,
        JTextField txtUsuario, JTextField txtPassword, boolean selected) {
    int tipoBD = combo.getSelectedIndex() + 1;

    //        String driver = ParametrosUtil.obtenerDriver(tipoBD);
    String url = txtConexion.getText();
    String usuario = txtUsuario.getText();
    String password = txtPassword.getText();

    //        combo.setSelectedIndex(tipoBD - 1);
    txtConexion.setText(url);//from w ww  . jav a2  s  .  c  om
    txtUsuario.setText(usuario);
    txtPassword.setText(password);

    fichero.setProperty("url", url);
    fichero.setProperty("usuario", usuario);
    fichero.setProperty("password", Encriptador.encrypt(password));
    fichero.setProperty("tipo", tipoBD + "");

    if (selected) {
        fichero.setProperty("action", "create");
    } else {
        fichero.setProperty("action", "none");
    }

    PropertiesUtil.guardarProperties(fichero, urlFichero);
}

From source file:com.sshtools.j2ssh.authentication.UserGridCredential.java

private static GSSCredential chooseCert(int proxyType, int lifetimeHours, SshConnectionProperties props)
        throws IOException, IllegalArgumentException, IllegalStateException {
    String dProfile = PreferencesStore.get(SshTerminalPanel.PREF_BROWSER_PROFILE, null);
    String dDN = PreferencesStore.get(SshTerminalPanel.PREF_BROWSER_DN, null);
    if (props instanceof SshToolsConnectionProfile) {
        SshToolsConnectionProfile profile = (SshToolsConnectionProfile) props;
        dProfile = profile.getApplicationProperty(SshTerminalPanel.PREF_BROWSER_PROFILE, dProfile);
        dDN = profile.getApplicationProperty(SshTerminalPanel.PREF_BROWSER_DN, dDN);
    }/*from   www .ja  va2  s.co  m*/

    String profile = Browser.getCurrentBrowser();
    if (profile == null) {
        String profiles[] = Browser.getBrowserList();
        if (profiles == null)
            return null;
        if (profiles.length == 0) {
            JOptionPane.showMessageDialog(props.getWindow(), "No browsers found", "GSI-SSHTerm Authentication",
                    JOptionPane.ERROR_MESSAGE);
            return null;
        }
        if (profiles.length == 1) {
            Browser.setBrowser(profiles[0]); //user chooses profile.
        } else {
            boolean chosen = false;
            if (dProfile != null) {
                for (String p : profiles) {
                    if (p.equals(dProfile)) {
                        chosen = true;
                        Browser.setBrowser(p);
                    }
                }
            }
            if (!chosen) {
                JComboBox combo = new JComboBox(profiles);
                int ret = JOptionPane.showOptionDialog(props.getWindow(), "Please choose browser to use:",
                        "Grid Authentication", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                        new Object[] { combo, "OK" }, null);
                if (ret == JOptionPane.CLOSED_OPTION)
                    new IOException("Canceled by user.");
                Browser.setBrowser(profiles[combo.getSelectedIndex()]); //user chooses profile.
            }
        }
        profile = Browser.getCurrentBrowser();
    }
    String dnlist[] = null;
    try {
        dnlist = Browser.getDNlist(new PasswordPrompt(props));
    } catch (IOException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
        log.debug("Could not access keystore in profile: " + profile + " : " + e);
    } catch (KeyStoreException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
        log.debug("Could not access keystore in profile: " + profile + " : " + e);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
        log.debug("Could not access keystore in profile: " + profile + " : " + e);
    } catch (CertificateException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
        log.debug("Could not access keystore in profile: " + profile + " : " + e);
    } catch (InvalidAlgorithmParameterException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
        log.debug("Could not access keystore in profile: " + profile + " : " + e);
    } catch (javax.security.auth.login.FailedLoginException e) {
        JOptionPane.showMessageDialog(props.getWindow(), e.getMessage(), "Incorrect Password",
                JOptionPane.ERROR_MESSAGE);
        return null;
    } catch (GeneralSecurityException e) {
        if (e.getMessage().indexOf("version>=1.5") >= 0) {
            JOptionPane.showMessageDialog(props.getWindow(), e.getMessage(), "GSI-SSHTerm Authentication",
                    JOptionPane.ERROR_MESSAGE);
        } else {
            e.printStackTrace();
            errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
            log.debug("Could not access keystore in profile: " + profile + " : " + e);
        }
    }
    if (dnlist == null)
        return null;
    int index = -1;
    if (dnlist.length == 0) {
        JOptionPane.showMessageDialog(props.getWindow(), "No Certificates found", "GSI-SSHTerm Authentication",
                JOptionPane.ERROR_MESSAGE);
        return null;
    }
    if (dnlist.length == 1) {
        index = 0;
    } else {
        if (dDN != null) {
            for (int i = 0; i < dnlist.length; i++) {
                if (dnlist[i].equals(dDN)) {
                    index = i;
                }
            }
        }
        if (index == -1) {
            JComboBox dnCombo = new JComboBox(dnlist);

            int ret = JOptionPane.showOptionDialog(props.getWindow(), "Please choose certificate to use:",
                    "GSI-SSHTerm Authentication", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    new Object[] { dnCombo, "OK" }, null);
            if (ret == JOptionPane.CLOSED_OPTION)
                new IOException("Canceled by user.");
            index = dnCombo.getSelectedIndex();
        }
    }
    try {
        GSSCredential gssproxy = Browser.getGridProxy(dnlist[index], proxyType, lifetimeHours);

        if (SAVE_BROWSER_PROXY) {
            GlobusCredential proxy = ((GlobusGSSCredentialImpl) gssproxy).getGlobusCredential();
            ProxyHelper.saveProxy(proxy, props);
        }
        return gssproxy;
    } catch (GeneralSecurityException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not load certificate from profile: " + profile, e);
        log.debug("Could not load certificate from browser: " + e);
    } catch (GlobusCredentialException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not load certificate from profile: " + profile, e);
        log.debug("Could not load certificate from browser: " + e);
    } catch (GSSException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not load certificate from profile: " + profile, e);
        log.debug("Could not load certificate from browser: " + e);
    }
    return null;
}

From source file:bridge.toolkit.ControllerJFrame.java

private void SelectionDropDownActionPerformed(java.awt.event.ActionEvent evt) {
    javax.swing.JComboBox cb = (javax.swing.JComboBox) (evt.getSource());
    int val = cb.getSelectedIndex();
    switch (val) {
    case 0://from  w  w  w.j a v  a  2 s  .co m
        outputType = "-scormflash";
        break;
    case 1:
        outputType = "-scormhtml";
        break;
    case 2:
        outputType = "-mobile";
        break;
    case 3:
        outputType = "-mobilecourse";
        break;
    case 4:
        outputType = "-pdfinstructor";
        break;
    case 5:
        outputType = "-pdfstudent";
        break;
    }
}

From source file:biomine.bmvis2.pipeline.BestPathHiderOperation.java

public JComponent getSettingsComponent(final SettingsChangeCallback settingsChangeCallback,
        final VisualGraph graph) {
    long nodeCount = graph.getAllNodes().size();

    if (oldCount != 0) {
        long newTarget = (target * nodeCount) / oldCount;
        this.target = Math.max(newTarget, target);
    } else// w w  w  .  ja v a2 s  . com
        this.target = nodeCount;

    this.oldCount = nodeCount;

    JPanel ret = new JPanel();

    // if int overflows, we're fucked
    final JSlider sl = new JSlider(0, (int) nodeCount, (int) Math.min(target, nodeCount));
    sl.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent arg0) {
            if (target == sl.getValue())
                return;
            target = sl.getValue();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    ret.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.gridy = 0;
    //c.gridwidth=2;

    ret.add(sl, c);
    c.gridy++;

    int choices = graph.getNodesOfInterest().size() + 1;

    Object[] items = new Object[choices];
    items[0] = "All PoIs";

    for (int i = 1; i < choices; i++) {
        items[i] = i + " nearest";
    }
    final JComboBox pathTypeBox = new JComboBox(items);
    pathTypeBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            int i = pathTypeBox.getSelectedIndex();
            grader.setPathK(i);
            settingsChangeCallback.settingsChanged(false);
        }
    });

    ret.add(new JLabel("hide by best path quality to:"), c);
    c.gridy++;
    ret.add(pathTypeBox, c);
    c.gridy++;

    System.out.println("new confpane nodeCount = " + nodeCount);

    final JCheckBox useMatchingColoring = new JCheckBox();
    ret.add(useMatchingColoring, c);

    useMatchingColoring.setAction(new AbstractAction("Use matching coloring") {
        public void actionPerformed(ActionEvent arg0) {
            matchColoring = useMatchingColoring.isSelected();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    useMatchingColoring.setAlignmentX(JComponent.CENTER_ALIGNMENT);

    c.gridy++;

    final JCheckBox labelsBox = new JCheckBox();
    ret.add(labelsBox, c);

    labelsBox.setAction(new AbstractAction("Show goodness in node labels") {
        public void actionPerformed(ActionEvent arg0) {
            showLabel = labelsBox.isSelected();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    return ret;
}

From source file:edu.ku.brc.specify.datamodel.busrules.AgentBusRules.java

@Override
public void beforeMerge(final Object dataObj, final DataProviderSessionIFace session) {
    super.beforeMerge(dataObj, session);

    Agent agent = (Agent) dataObj;/*from  ww  w . ja  v a 2 s  .c o  m*/

    if (agent.getDivision() == null) {
        agent.setDivision(AppContextMgr.getInstance().getClassObject(Division.class));
    }

    try {
        if (agent.getId() == null) {
            session.save(agent);
        }

        for (GroupPerson gp : agent.getGroups()) {
            if (gp.getId() == null) {
                session.save(gp);
            }
        }

        for (GroupPerson gp : agent.getMembers()) {
            if (gp.getId() == null) {
                session.save(gp);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    //session.attach(agent);

    if (agent.getAgentType() == null) {
        if (typeComp instanceof ValComboBox) {
            JComboBox cbx = ((ValComboBox) typeComp).getComboBox();
            byte agentType = (byte) cbx.getSelectedIndex();
            if (agentType == -1) {
                agentType = Agent.PERSON;
            }
            agent.setAgentType(agentType);
        }
    }

    /*if (!contains(agent, AppContextMgr.getInstance().getClassObject(Discipline.class)))
    {
    agent.getDisciplines().add(AppContextMgr.getInstance().getClassObject(Discipline.class));
    AppContextMgr.getInstance().getClassObject(Discipline.class).getAgents().add(agent);
    }*/
}

From source file:io.github.jeremgamer.editor.panels.GeneralSettings.java

public GeneralSettings() {
    this.setBorder(BorderFactory.createTitledBorder(""));

    JPanel namePanel = new JPanel();
    JLabel nameLabel = new JLabel("Nom :");
    namePanel.add(nameLabel);/*from www.j ava2 s.  co m*/
    name.setPreferredSize(new Dimension(220, 30));
    namePanel.add(name);
    CaretListener caretUpdateName = new CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent e) {
            JTextField text = (JTextField) e.getSource();
            gs.set("name", text.getText());
        }
    };
    name.addCaretListener(caretUpdateName);
    this.add(namePanel);

    adress.setEditable(false);
    CaretListener caretUpdateAdress = new CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent e) {
            JTextField text = (JTextField) e.getSource();
            gs.set("adress", text.getText());
        }
    };
    adress.addCaretListener(caretUpdateAdress);
    JPanel subTypePanel = new JPanel();
    JLabel typeLabel = new JLabel("Type :");
    subTypePanel.add(typeLabel);
    type.setPreferredSize(new Dimension(220, 30));
    type.addItem("Minecraft classique");
    type.addItem("Minecraft personnalis");
    if (new File("projects/" + Editor.getProjectName() + "/data.zip").exists()) {
        type.setSelectedIndex(1);
        browse.setEnabled(true);
        browse.setText("Supprimer l'import");
    } else {
        browse.setEnabled(false);
    }
    type.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            if (combo.getSelectedIndex() == 1) {
                browse.setEnabled(true);
                adress.setEnabled(true);
                adress.setEditable(true);
            } else {
                browse.setEnabled(false);
                adress.setEnabled(false);
                adress.setEditable(false);
            }
            gs.set("type", combo.getSelectedIndex());
        }

    });
    subTypePanel.add(type);
    JPanel typePanel = new JPanel();
    typePanel.setLayout(new BoxLayout(typePanel, BoxLayout.PAGE_AXIS));

    typePanel.add(subTypePanel);
    JPanel browsePanel = new JPanel();
    browsePanel.add(browse);
    JPanel adressPanel = new JPanel();
    adressPanel.setLayout(new BoxLayout(adressPanel, BoxLayout.PAGE_AXIS));
    JLabel adressLabel = new JLabel("Adresse de tlchargement :");
    adressPanel.setPreferredSize(new Dimension(0, 47));
    adress.setPreferredSize(new Dimension(0, 30));
    adressPanel.add(adressLabel);
    adressPanel.add(adress);
    typePanel.add(adressPanel);

    this.add(typePanel);
    closeOnStart.setSelected(true);
    closeOnStart.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (closeOnStart.isSelected()) {
                gs.set("close", true);
            } else {
                gs.set("close", false);
            }
        }

    });
    this.add(closeOnStart);

    JPanel look = new JPanel();
    look.setBorder(BorderFactory.createTitledBorder("Apparence"));
    look.setPreferredSize(new Dimension(290, 340));
    JPanel colors = new JPanel();
    cDark.setSelected(true);
    bg.add(cLight);
    bg.add(cDark);
    colors.add(cLight);
    colors.add(cDark);
    cLight.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            gs.set("color", 0);
        }

    });
    cDark.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            gs.set("color", 1);
        }

    });
    look.add(colors);
    JPanel checks = new JPanel();
    checks.setLayout(new BoxLayout(checks, BoxLayout.PAGE_AXIS));
    borders.setSelected(true);
    borders.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (borders.isSelected()) {
                gs.set("borders", true);
            } else {
                gs.set("borders", false);
            }
        }

    });
    resize.setSelected(true);
    resize.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (resize.isSelected()) {
                gs.set("resizable", true);
            } else {
                gs.set("resizable", false);
            }
        }

    });
    alwaysOnTop.setSelected(false);
    alwaysOnTop.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (alwaysOnTop.isSelected()) {
                gs.set("top", true);
            } else {
                gs.set("top", false);
            }
        }

    });
    checks.add(borders);
    checks.add(resize);
    checks.add(alwaysOnTop);
    checks.setPreferredSize(new Dimension(270, 60));

    JPanel size = new JPanel();
    width.setPreferredSize(new Dimension(57, 30));
    widthMin.setPreferredSize(new Dimension(57, 30));
    widthMax.setPreferredSize(new Dimension(57, 30));
    height.setPreferredSize(new Dimension(57, 30));
    heightMin.setPreferredSize(new Dimension(57, 30));
    heightMax.setPreferredSize(new Dimension(57, 30));
    JPanel widthPanel = new JPanel();
    widthPanel.setPreferredSize(new Dimension(130, 150));
    widthPanel.setBorder(BorderFactory.createTitledBorder("Largeur"));
    widthPanel.setLayout(new BoxLayout(widthPanel, BoxLayout.PAGE_AXIS));
    JPanel widthPanelBase = new JPanel();
    widthPanelBase.add(new JLabel("Base :"));
    widthPanelBase.add(width);
    JPanel widthPanelMin = new JPanel();
    widthPanelMin.add(new JLabel("Min :"));
    widthPanelMin.add(Box.createRigidArea(new Dimension(5, 1)));
    widthPanelMin.add(widthMin);
    JPanel widthPanelMax = new JPanel();
    widthPanelMax.add(new JLabel("Max :"));
    widthPanelMax.add(Box.createRigidArea(new Dimension(3, 1)));
    widthPanelMax.add(widthMax);
    widthPanel.add(widthPanelBase);
    widthPanel.add(widthPanelMin);
    widthPanel.add(widthPanelMax);

    JPanel heightPanel = new JPanel();
    heightPanel.setPreferredSize(new Dimension(130, 150));
    heightPanel.setBorder(BorderFactory.createTitledBorder("Hauteur"));
    heightPanel.setLayout(new BoxLayout(heightPanel, BoxLayout.PAGE_AXIS));
    JPanel heightPanelBase = new JPanel();
    heightPanelBase.add(new JLabel("Base :"));
    heightPanelBase.add(height);
    JPanel heightPanelMin = new JPanel();
    heightPanelMin.add(new JLabel("Min :"));
    heightPanelMin.add(Box.createRigidArea(new Dimension(5, 1)));
    heightPanelMin.add(heightMin);
    JPanel heightPanelMax = new JPanel();
    heightPanelMax.add(new JLabel("Max :"));
    heightPanelMax.add(Box.createRigidArea(new Dimension(3, 1)));
    heightPanelMax.add(heightMax);
    heightPanel.add(heightPanelBase);
    heightPanel.add(heightPanelMin);
    heightPanel.add(heightPanelMax);
    size.add(widthPanel);
    size.add(heightPanel);

    width.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            gs.set("width", spinner.getValue());
        }
    });
    widthMin.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            gs.set("widthMin", spinner.getValue());
        }
    });
    widthMax.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            ;
            gs.set("widthMax", spinner.getValue());
        }
    });
    height.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            gs.set("height", spinner.getValue());
        }
    });
    heightMin.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            gs.set("heightMin", spinner.getValue());
        }
    });
    heightMax.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            ;
            gs.set("heightMax", spinner.getValue());
        }
    });

    look.add(checks);
    look.add(size);

    JPanel bottom = new JPanel();
    bottom.setLayout(new BoxLayout(bottom, BoxLayout.LINE_AXIS));
    JButton music = new JButton("Ajouter de la musique");
    music.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            new MusicFrame((JFrame) SwingUtilities.windowForComponent(adress), gs);
        }

    });
    bottom.add(music);
    JButton icons = new JButton("Icnes");
    icons.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            new IconFrame((JFrame) SwingUtilities.windowForComponent(adress));
        }

    });
    bottom.add(icons);

    look.add(bottom);

    this.add(look);

    load();
}

From source file:com.eviware.soapui.support.components.SimpleForm.java

public String getComponentValue(String label) {
    JComponent component = getComponent(label);
    if (component == null) {
        return (String) (hiddenValues == null ? null : hiddenValues.get(label));
    }/* www.ja v  a2s  . c o  m*/

    if (component instanceof JTextComponent) {
        return ((JTextComponent) component).getText();
    }

    if (component instanceof JComboBox) {
        JComboBox comboBox = ((JComboBox) component);
        int selectedIndex = comboBox.getSelectedIndex();
        if (selectedIndex != -1) {
            if (comboBoxMaps.containsKey(component)) {
                Object[] keys = (Object[]) comboBoxMaps.get(comboBox);
                Object value = keys[selectedIndex];
                return (String) value == null ? null : value.toString();
            } else {
                Object value = comboBox.getSelectedItem();
                return (String) value == null ? null : value.toString();
            }
        }
    }

    if (component instanceof JList) {
        return (String) ((JList) component).getSelectedValue();
    }

    if (component instanceof JCheckBox) {
        return String.valueOf(((JCheckBox) component).isSelected());
    } else if (component instanceof JFormComponent) {
        return ((JFormComponent) component).getValue();
    }

    return null;
}

From source file:edu.gmu.cs.sim.util.media.chart.BarChartGenerator.java

protected void buildGlobalAttributes(LabelledList list) {
    // create the chart
    CategoryPlot plot = (CategoryPlot) (chart.getPlot());
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinePaint(new Color(200, 200, 200));
    plot.setRangeGridlinePaint(new Color(200, 200, 200));

    // define the renderers
    barRenderer = new BarRenderer();
    reviseRenderer(barRenderer);/*from  w  w w . j ava 2 s  .  c om*/

    stackedBarRenderer = new StackedBarRenderer(false);
    reviseRenderer(stackedBarRenderer);

    percentageRenderer = new StackedBarRenderer(true);
    reviseRenderer(percentageRenderer);

    plot.setRenderer(barRenderer);

    xLabel = new PropertyField() {
        public String newValue(String newValue) {
            setXAxisLabel(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    xLabel.setValue(getXAxisLabel());

    list.add(new JLabel("X Label"), xLabel);

    yLabel = new PropertyField() {
        public String newValue(String newValue) {
            setYAxisLabel(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    yLabel.setValue(getYAxisLabel());

    list.add(new JLabel("Y Label"), yLabel);

    final JCheckBox gridlines = new JCheckBox();
    gridlines.setSelected(false);
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            hasgridlines = (e.getStateChange() == ItemEvent.SELECTED);
            updateGridLines();
        }
    };
    gridlines.addItemListener(il);

    list.add(new JLabel("Grid Lines"), gridlines);

    final JCheckBox labels = new JCheckBox();
    labels.setSelected(true);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                getBarRenderer().setBaseItemLabelsVisible(true);
                getStackedBarRenderer().setBaseItemLabelsVisible(true);
                getPercentageRenderer().setBaseItemLabelsVisible(true);
            } else {
                getBarRenderer().setBaseItemLabelsVisible(false);
                getStackedBarRenderer().setBaseItemLabelsVisible(false);
                getPercentageRenderer().setBaseItemLabelsVisible(false);
            }
        }
    };
    labels.addItemListener(il);
    list.add(new JLabel("Labels"), labels);

    final JComboBox barType = new JComboBox();
    barType.setEditable(false);
    barType.setModel(new DefaultComboBoxModel(
            new java.util.Vector(Arrays.asList(new String[] { "Separate", "Stacked", "Percentage" }))));
    barType.setSelectedIndex(0);
    barType.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            CategoryPlot plot = (CategoryPlot) (chart.getPlot());
            int type = barType.getSelectedIndex();

            if (type == 0) // separate
            {
                plot.setRenderer(getBarRenderer());
            } else if (type == 1) // stacked
            {
                plot.setRenderer(getStackedBarRenderer());
            } else // percentage
            {
                plot.setRenderer(getPercentageRenderer());
            }
        }
    });
    list.add(new JLabel("Bars"), barType);

    final JCheckBox horizontal = new JCheckBox();
    horizontal.setSelected(false);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            CategoryPlot plot = (CategoryPlot) (chart.getPlot());
            if (e.getStateChange() == ItemEvent.SELECTED) {
                plot.setOrientation(PlotOrientation.HORIZONTAL);
                ishorizontal = true;
            } else {
                plot.setOrientation(PlotOrientation.VERTICAL);
                ishorizontal = false;
            }
            updateGridLines();
        }
    };
    horizontal.addItemListener(il);

    list.add(new JLabel("Horizontal"), horizontal);
}

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 {//from   w  w w. ja  v  a2 s  .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 {/*w  w w . j a  v  a  2s.  c  om*/
            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);
    }
}