Example usage for java.awt.event ItemEvent SELECTED

List of usage examples for java.awt.event ItemEvent SELECTED

Introduction

In this page you can find the example usage for java.awt.event ItemEvent SELECTED.

Prototype

int SELECTED

To view the source code for java.awt.event ItemEvent SELECTED.

Click Source Link

Document

This state-change value indicates that an item was selected.

Usage

From source file:org.smart.migrate.ui.UpdateRelatePKDialog.java

private void cbxPKTableItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbxPKTableItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        initFields(cbxPKLogic, (String) evt.getItem());
        initFields(cbxPK, (String) evt.getItem());
    }/*from   w ww . j  a  v  a2s.  co m*/
}

From source file:net.pms.encoders.VLCVideo.java

@Override
public JComponent config() {
    // Apply the orientation for the locale
    Locale locale = new Locale(configuration.getLanguage());
    ComponentOrientation orientation = ComponentOrientation.getOrientation(locale);
    String colSpec = FormLayoutUtil.getColSpec("right:pref, 3dlu, pref:grow, 7dlu, right:pref, 3dlu, pref:grow",
            orientation);//w  w w . ja  v  a  2 s .c o  m
    FormLayout layout = new FormLayout(colSpec, "");
    // Here goes my 3rd try to learn JGoodies Form
    layout.setColumnGroups(new int[][] { { 1, 5 }, { 3, 7 } });
    DefaultFormBuilder mainPanel = new DefaultFormBuilder(layout);

    mainPanel.appendSeparator(Messages.getString("VlcTrans.1"));
    mainPanel.append(experimentalCodecs = new JCheckBox(Messages.getString("VlcTrans.3"),
            configuration.isVlcExperimentalCodecs()), 3);
    experimentalCodecs.setContentAreaFilled(false);
    experimentalCodecs.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setVlcExperimentalCodecs(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    mainPanel.append(audioSyncEnabled = new JCheckBox(Messages.getString("VlcTrans.4"),
            configuration.isVlcAudioSyncEnabled()), 3);
    audioSyncEnabled.setContentAreaFilled(false);
    audioSyncEnabled.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setVlcAudioSyncEnabled(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    mainPanel.nextLine();

    // Developer stuff. Theoretically is temporary 
    mainPanel.appendSeparator(Messages.getString("VlcTrans.10"));

    // Add scale as a subpanel because it has an awkward layout
    mainPanel.append(Messages.getString("VlcTrans.11"));
    FormLayout scaleLayout = new FormLayout("pref,3dlu,pref", "");
    DefaultFormBuilder scalePanel = new DefaultFormBuilder(scaleLayout);
    double startingScale = Double.valueOf(configuration.getVlcScale());
    scalePanel.append(scale = new JTextField(String.valueOf(startingScale)));
    final JSlider scaleSlider = new JSlider(JSlider.HORIZONTAL, 0, 10, (int) (startingScale * 10));
    scalePanel.append(scaleSlider);
    scaleSlider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent ce) {
            String value = String.valueOf((double) scaleSlider.getValue() / 10);
            scale.setText(value);
            configuration.setVlcScale(value);
        }
    });
    scale.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            String typed = scale.getText();
            if (!typed.matches("\\d\\.\\d")) {
                return;
            }
            double value = Double.parseDouble(typed);
            scaleSlider.setValue((int) (value * 10));
            configuration.setVlcScale(String.valueOf(value));
        }
    });
    mainPanel.append(scalePanel.getPanel(), 3);

    // Audio sample rate
    FormLayout sampleRateLayout = new FormLayout(
            "right:pref, 3dlu, right:pref, 3dlu, right:pref, 3dlu, left:pref", "");
    DefaultFormBuilder sampleRatePanel = new DefaultFormBuilder(sampleRateLayout);
    sampleRateOverride = new JCheckBox(Messages.getString("VlcTrans.17"),
            configuration.getVlcSampleRateOverride());
    sampleRatePanel.append(Messages.getString("VlcTrans.18"), sampleRateOverride);
    sampleRate = new JTextField(configuration.getVlcSampleRate(), 8);
    sampleRate.setEnabled(configuration.getVlcSampleRateOverride());
    sampleRate.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setVlcSampleRate(sampleRate.getText());
        }
    });
    sampleRatePanel.append(Messages.getString("VlcTrans.19"), sampleRate);
    sampleRateOverride.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            boolean checked = e.getStateChange() == ItemEvent.SELECTED;
            configuration.setVlcSampleRateOverride(checked);
            sampleRate.setEnabled(checked);
        }
    });

    mainPanel.nextLine();
    mainPanel.append(sampleRatePanel.getPanel(), 7);

    // Extra options
    mainPanel.nextLine();
    mainPanel.append(Messages.getString("VlcTrans.20"), extraParams = new JTextField(), 5);

    return mainPanel.getPanel();
}

From source file:sim.util.media.chart.ChartGenerator.java

/** Generates a new ChartGenerator with a blank chart.  Before anything else, buildChart() is called.  */
public ChartGenerator() {
    // create the chart
    buildChart();//from  w  w  w.  j  av  a  2s  .  co m
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.setAntiAlias(true);

    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    split.setBorder(new EmptyBorder(0, 0, 0, 0));
    JScrollPane scroll = new JScrollPane();
    JPanel b = new JPanel();
    b.setLayout(new BorderLayout());
    b.add(seriesAttributes, BorderLayout.NORTH);
    b.add(new JPanel(), BorderLayout.CENTER);
    scroll.getViewport().setView(b);
    scroll.setBackground(getBackground());
    scroll.getViewport().setBackground(getBackground());
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());

    LabelledList list = new LabelledList("Chart Properties");
    DisclosurePanel pan1 = new DisclosurePanel("Chart Properties", list);
    globalAttributes.add(pan1);

    JLabel j = new JLabel("Right-Click or Control-Click");
    j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC));
    list.add(j);
    j = new JLabel("on Chart for More Options");
    j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC));
    list.add(j);

    titleField = new PropertyField() {
        public String newValue(String newValue) {
            setTitle(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    titleField.setValue(chart.getTitle().getText());

    list.add(new JLabel("Title"), titleField);

    buildGlobalAttributes(list);

    final JCheckBox legendCheck = new JCheckBox();
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                LegendTitle title = new LegendTitle(chart.getPlot());
                title.setLegendItemGraphicPadding(new org.jfree.ui.RectangleInsets(0, 8, 0, 4));
                chart.addLegend(title);
            } else {
                chart.removeLegend();
            }
        }
    };
    legendCheck.addItemListener(il);
    list.add(new JLabel("Legend"), legendCheck);
    legendCheck.setSelected(true);

    /*
      final JCheckBox aliasCheck = new JCheckBox();
      aliasCheck.setSelected(chart.getAntiAlias());
      il = new ItemListener()
      {
      public void itemStateChanged(ItemEvent e)
      {
      chart.setAntiAlias( e.getStateChange() == ItemEvent.SELECTED );
      }
      };
      aliasCheck.addItemListener(il);
      list.add(new JLabel("Antialias"), aliasCheck);
    */

    JPanel pdfButtonPanel = new JPanel();
    pdfButtonPanel.setBorder(new javax.swing.border.TitledBorder("Chart Output"));
    DisclosurePanel pan2 = new DisclosurePanel("Chart Output", pdfButtonPanel);

    pdfButtonPanel.setLayout(new BorderLayout());
    Box pdfbox = new Box(BoxLayout.Y_AXIS);
    pdfButtonPanel.add(pdfbox, BorderLayout.WEST);

    JButton pdfButton = new JButton("Save as PDF");
    pdfbox.add(pdfButton);
    pdfButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            FileDialog fd = new FileDialog(frame, "Choose PDF file...", FileDialog.SAVE);
            fd.setFile(chart.getTitle().getText() + ".pdf");
            fd.setVisible(true);
            String fileName = fd.getFile();
            if (fileName != null) {
                Dimension dim = chartPanel.getPreferredSize();
                PDFEncoder.generatePDF(chart, dim.width, dim.height,
                        new File(fd.getDirectory(), Utilities.ensureFileEndsWith(fd.getFile(), ".pdf")));
            }
        }
    });
    movieButton = new JButton("Create a Movie");
    pdfbox.add(movieButton);
    pdfbox.add(Box.createGlue());
    movieButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (movieMaker == null)
                startMovie();
            else
                stopMovie();
        }
    });

    globalAttributes.add(pan2);

    // we add into an outer box so we can later on add more global seriesAttributes
    // as the user instructs and still have glue be last
    Box outerAttributes = Box.createVerticalBox();
    outerAttributes.add(globalAttributes);
    outerAttributes.add(Box.createGlue());

    p.add(outerAttributes, BorderLayout.NORTH);
    p.add(scroll, BorderLayout.CENTER);
    p.setMinimumSize(new Dimension(0, 0));
    p.setPreferredSize(new Dimension(200, 0));
    split.setLeftComponent(p);

    // Add scale and proportion fields
    Box header = Box.createHorizontalBox();

    final double MAXIMUM_SCALE = 8;

    fixBox = new JCheckBox("Fill");
    fixBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setFixed(fixBox.isSelected());
        }
    });
    header.add(fixBox);
    fixBox.setSelected(true);

    // add the scale field
    scaleField = new NumberTextField("  Scale: ", 1.0, true) {
        public double newValue(double newValue) {
            if (newValue <= 0.0)
                newValue = currentValue;
            if (newValue > MAXIMUM_SCALE)
                newValue = currentValue;
            scale = newValue;
            resizeChart();
            return newValue;
        }
    };
    scaleField.setToolTipText("Zoom in and out");
    scaleField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
    scaleField.setEnabled(false);
    scaleField.setText("");
    header.add(scaleField);

    // add the proportion field
    proportionField = new NumberTextField("  Proportion: ", 1.5, true) {
        public double newValue(double newValue) {
            if (newValue <= 0.0)
                newValue = currentValue;
            proportion = newValue;
            resizeChart();
            return newValue;
        }
    };
    proportionField.setToolTipText("Change the chart proportions (ratio of width to height)");
    proportionField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
    header.add(proportionField);

    chartHolder.setMinimumSize(new Dimension(0, 0));
    chartHolder.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    chartHolder.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    chartHolder.getViewport().setBackground(Color.gray);
    JPanel p2 = new JPanel();
    p2.setLayout(new BorderLayout());
    p2.add(chartHolder, BorderLayout.CENTER);
    p2.add(header, BorderLayout.NORTH);
    split.setRightComponent(p2);
    setLayout(new BorderLayout());
    add(split, BorderLayout.CENTER);

    // set the default to be white, which looks good when printed
    chart.setBackgroundPaint(Color.WHITE);

    // JFreeChart has a hillariously broken way of handling font scaling.
    // It allows fonts to scale independently in X and Y.  We hack a workaround here.
    chartPanel.setMinimumDrawHeight((int) DEFAULT_CHART_HEIGHT);
    chartPanel.setMaximumDrawHeight((int) DEFAULT_CHART_HEIGHT);
    chartPanel.setMinimumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion));
    chartPanel.setMaximumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion));
    chartPanel.setPreferredSize(new java.awt.Dimension((int) (DEFAULT_CHART_HEIGHT * DEFAULT_CHART_PROPORTION),
            (int) (DEFAULT_CHART_HEIGHT)));
}

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

/** Generates a new ChartGenerator with a blank chart.  Before anything else, buildChart() is called.  */
public ChartGenerator() {
    // create the chart
    buildChart();/*from   ww w  . j a v a 2s .c  om*/
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.setAntiAlias(true);

    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    split.setBorder(new EmptyBorder(0, 0, 0, 0));
    JScrollPane scroll = new JScrollPane();
    JPanel b = new JPanel();
    b.setLayout(new BorderLayout());
    b.add(seriesAttributes, BorderLayout.NORTH);
    b.add(new JPanel(), BorderLayout.CENTER);
    scroll.getViewport().setView(b);
    scroll.setBackground(getBackground());
    scroll.getViewport().setBackground(getBackground());
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());

    LabelledList list = new LabelledList("Chart Properties");
    DisclosurePanel pan1 = new DisclosurePanel("Chart Properties", list);
    globalAttributes.add(pan1);

    JLabel j = new JLabel("Right-Click or Control-Click");
    j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC));
    list.add(j);
    j = new JLabel("on Chart for More Options");
    j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC));
    list.add(j);

    titleField = new PropertyField() {
        public String newValue(String newValue) {
            setTitle(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    titleField.setValue(chart.getTitle().getText());

    list.add(new JLabel("Title"), titleField);

    buildGlobalAttributes(list);

    final JCheckBox legendCheck = new JCheckBox();
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                LegendTitle title = new LegendTitle(chart.getPlot());
                title.setLegendItemGraphicPadding(new org.jfree.ui.RectangleInsets(0, 8, 0, 4));
                chart.addLegend(title);
            } else {
                chart.removeLegend();
            }
        }
    };
    legendCheck.addItemListener(il);
    list.add(new JLabel("Legend"), legendCheck);
    legendCheck.setSelected(true);

    /*
      final JCheckBox aliasCheck = new JCheckBox();
      aliasCheck.setSelected(chart.getAntiAlias());
      il = new ItemListener()
      {
      public void itemStateChanged(ItemEvent e)
      {
      chart.setAntiAlias( e.getStateChange() == ItemEvent.SELECTED );
      }
      };
      aliasCheck.addItemListener(il);
      list.add(new JLabel("Antialias"), aliasCheck);
    */

    JPanel pdfButtonPanel = new JPanel();
    pdfButtonPanel.setBorder(new javax.swing.border.TitledBorder("Chart Output"));
    DisclosurePanel pan2 = new DisclosurePanel("Chart Output", pdfButtonPanel);

    pdfButtonPanel.setLayout(new BorderLayout());
    Box pdfbox = new Box(BoxLayout.Y_AXIS);
    pdfButtonPanel.add(pdfbox, BorderLayout.WEST);

    JButton pdfButton = new JButton("Save as PDF");
    pdfbox.add(pdfButton);
    pdfButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            FileDialog fd = new FileDialog(frame, "Choose PDF file...", FileDialog.SAVE);
            fd.setFile(chart.getTitle().getText() + ".pdf");
            fd.setVisible(true);
            String fileName = fd.getFile();
            if (fileName != null) {
                Dimension dim = chartPanel.getPreferredSize();
                PDFEncoder.generatePDF(chart, dim.width, dim.height,
                        new File(fd.getDirectory(), Utilities.ensureFileEndsWith(fd.getFile(), ".pdf")));
            }
        }
    });
    movieButton = new JButton("Create a Movie");
    pdfbox.add(movieButton);
    pdfbox.add(Box.createGlue());
    movieButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (movieMaker == null) {
                startMovie();
            } else {
                stopMovie();
            }
        }
    });

    globalAttributes.add(pan2);

    // we add into an outer box so we can later on add more global seriesAttributes
    // as the user instructs and still have glue be last
    Box outerAttributes = Box.createVerticalBox();
    outerAttributes.add(globalAttributes);
    outerAttributes.add(Box.createGlue());

    p.add(outerAttributes, BorderLayout.NORTH);
    p.add(scroll, BorderLayout.CENTER);
    p.setMinimumSize(new Dimension(0, 0));
    p.setPreferredSize(new Dimension(200, 0));
    split.setLeftComponent(p);

    // Add scale and proportion fields
    Box header = Box.createHorizontalBox();

    final double MAXIMUM_SCALE = 8;

    fixBox = new JCheckBox("Fill");
    fixBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setFixed(fixBox.isSelected());
        }
    });
    header.add(fixBox);
    fixBox.setSelected(true);

    // add the scale field
    scaleField = new NumberTextField("  Scale: ", 1.0, true) {
        public double newValue(double newValue) {
            if (newValue <= 0.0) {
                newValue = currentValue;
            }
            if (newValue > MAXIMUM_SCALE) {
                newValue = currentValue;
            }
            scale = newValue;
            resizeChart();
            return newValue;
        }
    };
    scaleField.setToolTipText("Zoom in and out");
    scaleField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
    scaleField.setEnabled(false);
    scaleField.setText("");
    header.add(scaleField);

    // add the proportion field
    proportionField = new NumberTextField("  Proportion: ", 1.5, true) {
        public double newValue(double newValue) {
            if (newValue <= 0.0) {
                newValue = currentValue;
            }
            proportion = newValue;
            resizeChart();
            return newValue;
        }
    };
    proportionField.setToolTipText("Change the chart proportions (ratio of width to height)");
    proportionField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
    header.add(proportionField);

    chartHolder.setMinimumSize(new Dimension(0, 0));
    chartHolder.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    chartHolder.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    chartHolder.getViewport().setBackground(Color.gray);
    JPanel p2 = new JPanel();
    p2.setLayout(new BorderLayout());
    p2.add(chartHolder, BorderLayout.CENTER);
    p2.add(header, BorderLayout.NORTH);
    split.setRightComponent(p2);
    setLayout(new BorderLayout());
    add(split, BorderLayout.CENTER);

    // set the default to be white, which looks good when printed
    chart.setBackgroundPaint(Color.WHITE);

    // JFreeChart has a hillariously broken way of handling font scaling.
    // It allows fonts to scale independently in X and Y.  We hack a workaround here.
    chartPanel.setMinimumDrawHeight((int) DEFAULT_CHART_HEIGHT);
    chartPanel.setMaximumDrawHeight((int) DEFAULT_CHART_HEIGHT);
    chartPanel.setMinimumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion));
    chartPanel.setMaximumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion));
    chartPanel.setPreferredSize(new java.awt.Dimension((int) (DEFAULT_CHART_HEIGHT * DEFAULT_CHART_PROPORTION),
            (int) (DEFAULT_CHART_HEIGHT)));
}

From source file:com.jsystem.j2autoit.AutoItAgent.java

private static void createAndShowGUI() {
    //Check the SystemTray support
    if (!SystemTray.isSupported()) {
        Log.error("SystemTray is not supported\n");
        return;/*from w  ww.  j  a  v a2s .co m*/
    }
    final PopupMenu popup = new PopupMenu();
    final TrayIcon trayIcon = new TrayIcon(createImage("images/jsystem_ico.gif", "tray icon"));
    final SystemTray tray = SystemTray.getSystemTray();

    // Create a popup menu components
    final MenuItem aboutItem = new MenuItem("About");
    final MenuItem startAgentItem = new MenuItem("Start J2AutoIt Agent");
    final MenuItem stopAgentItem = new MenuItem("Stop J2AutoIt Agent");
    final MenuItem exitItem = new MenuItem("Exit");
    final MenuItem changePortItem = new MenuItem("Setting J2AutoIt Port");
    final MenuItem deleteTemporaryFilesItem = new MenuItem("Delete J2AutoIt Script");
    final MenuItem temporaryHistoryFilesItem = new MenuItem("History Size");
    final MenuItem displayLogFile = new MenuItem("Log");
    final MenuItem forceShutDownTimeOutItem = new MenuItem("Force ShutDown TimeOut");
    final MenuItem writeConfigurationToFile = new MenuItem("Save Configuration To File");
    final CheckboxMenuItem debugModeItem = new CheckboxMenuItem("Debug Mode", isDebug);
    final CheckboxMenuItem forceAutoItShutDownItem = new CheckboxMenuItem("Force AutoIt Script ShutDown",
            isForceAutoItShutDown);
    final CheckboxMenuItem autoDeleteHistoryItem = new CheckboxMenuItem("Auto Delete History",
            isAutoDeleteFiles);
    final CheckboxMenuItem useAutoScreenShot = new CheckboxMenuItem("Auto Screenshot", isUseScreenShot);

    //Add components to popup menu
    popup.add(aboutItem);
    popup.add(writeConfigurationToFile);
    popup.addSeparator();
    popup.add(forceAutoItShutDownItem);
    popup.add(forceShutDownTimeOutItem);
    popup.addSeparator();
    popup.add(debugModeItem);
    popup.add(displayLogFile);
    popup.add(useAutoScreenShot);
    popup.addSeparator();
    popup.add(autoDeleteHistoryItem);
    popup.add(deleteTemporaryFilesItem);
    popup.add(temporaryHistoryFilesItem);
    popup.addSeparator();
    popup.add(changePortItem);
    popup.addSeparator();
    popup.add(startAgentItem);
    popup.add(stopAgentItem);
    popup.addSeparator();
    popup.add(exitItem);

    trayIcon.setToolTip("J2AutoIt Agent");
    trayIcon.setImageAutoSize(true);
    trayIcon.setPopupMenu(popup);
    final DisplayLogFile displayLog = new DisplayLogFile();
    try {
        tray.add(trayIcon);
    } catch (AWTException e) {
        Log.error("TrayIcon could not be added.\n");
        return;
    }

    trayIcon.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
            startAgentItem.setEnabled(!serverState);
            stopAgentItem.setEnabled(serverState);
            deleteTemporaryFilesItem.setEnabled(isDebug && HistoryFile.containEntries());
            autoDeleteHistoryItem.setEnabled(isDebug);
            temporaryHistoryFilesItem.setEnabled(isDebug && isAutoDeleteFiles);
            displayLogFile.setEnabled(isDebug);
            forceShutDownTimeOutItem.setEnabled(isForceAutoItShutDown);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }
    });

    writeConfigurationToFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            AutoItProperties.DEBUG_MODE_KEY.setValue(isDebug.toString());
            AutoItProperties.AUTO_DELETE_TEMPORARY_SCRIPT_FILE_KEY.setValue(isAutoDeleteFiles.toString());
            AutoItProperties.AUTO_IT_SCRIPT_HISTORY_SIZE_KEY.setValue(DEFAULT_HistorySize.toString());
            AutoItProperties.FORCE_AUTO_IT_PROCESS_SHUTDOWN_KEY.setValue(isForceAutoItShutDown.toString());
            AutoItProperties.AGENT_PORT_KEY.setValue(webServicePort.toString());
            AutoItProperties.SERVER_UP_ON_INIT_KEY.setValue(serverState.toString());
            if (!AutoItProperties.savePropertiesFileSafely()) {
                Log.error("Fail to save properties file");
            }
        }
    });

    debugModeItem.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            isDebug = (e.getStateChange() == ItemEvent.SELECTED);
            deleteTemporaryFilesItem.setEnabled(isDebug && HistoryFile.containEntries());
            Log.infoLog("Keeping the temp file is " + (isDebug ? "en" : "dis") + "able\n");
            trayIcon.displayMessage((isDebug ? "Debug" : "Normal") + " Mode",
                    "The system will " + (isDebug ? "not " : "") + "delete \nthe temporary autoIt scripts."
                            + (isDebug ? "\nSee log file for more info." : ""),
                    MessageType.INFO);
        }
    });

    useAutoScreenShot.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            isUseScreenShot = (e.getStateChange() == ItemEvent.SELECTED);
            Log.infoLog("Auto screenshot is " + (isUseScreenShot ? "" : "in") + "active\n");
        }
    });

    forceAutoItShutDownItem.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            isForceAutoItShutDown = (e.getStateChange() == ItemEvent.SELECTED);
            Log.infoLog((isForceAutoItShutDown ? "Force" : "Soft") + " AutoIt Script ShutDown\n");
            trayIcon.displayMessage("AutoIt Script Termination",
                    (isForceAutoItShutDown ? "Hard shutdown" : "Soft shutdown"), MessageType.INFO);
        }
    });

    autoDeleteHistoryItem.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            isAutoDeleteFiles = (e.getStateChange() == ItemEvent.SELECTED);
            Log.infoLog((isAutoDeleteFiles ? "Auto" : "Manual") + " AutoIt Script Deletion\n");
            trayIcon.displayMessage("AutoIt Script Deletion", (isAutoDeleteFiles ? "Auto" : "Manual") + " Mode",
                    MessageType.INFO);
            if (isAutoDeleteFiles) {
                HistoryFile.init();
            } else {
                HistoryFile.close();
            }
        }
    });

    forceShutDownTimeOutItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String timeOutAsString = JOptionPane.showInputDialog(
                    "Please Insert Force ShutDown TimeOut (in seconds)",
                    String.valueOf(shutDownTimeOut / 1000));
            try {
                shutDownTimeOut = 1000 * Long.parseLong(timeOutAsString);
            } catch (Exception e2) {
            }
            Log.infoLog("Setting the force shutdown time out to : " + (shutDownTimeOut / 1000) + " seconds.\n");
        }
    });

    displayLogFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                displayLog.reBuild(Log.getCurrentLogs());
                displayLog.actionPerformed(actionEvent);
            } catch (Exception e2) {
            }
        }
    });

    temporaryHistoryFilesItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String historySize = JOptionPane.showInputDialog("Please Insert History AutoIt Script Files",
                    String.valueOf(HistoryFile.getHistory_Size()));
            try {
                int temp = Integer.parseInt(historySize);
                if (temp > 0) {
                    if (HistoryFile.getHistory_Size() != temp) {
                        HistoryFile.setHistory_Size(temp);
                        Log.infoLog("The history files size is " + historySize + NEW_LINE);
                    }
                } else {
                    Log.warning("Illegal History Size: " + historySize + NEW_LINE);
                }
            } catch (Exception exception) {
                Log.throwableLog(exception.getMessage(), exception);
            }
        }
    });

    deleteTemporaryFilesItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            HistoryFile.forceDeleteAll();
        }
    });

    startAgentItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            runWebServer();
        }
    });

    stopAgentItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            shutDownWebServer();
        }
    });

    aboutItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JOptionPane.showMessageDialog(null, "J2AutoIt Agent By JSystem And Aqua Software");
        }
    });

    changePortItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String portAsString = JOptionPane.showInputDialog("Please Insert new Port",
                    String.valueOf(webServicePort));
            if (portAsString != null) {
                try {
                    int temp = Integer.parseInt(portAsString);
                    if (temp > 1000) {
                        if (temp != webServicePort) {
                            webServicePort = temp;
                            shutDownWebServer();
                            startAutoItWebServer(webServicePort);
                            runWebServer();
                        }
                    } else {
                        Log.warning("Port number should be greater then 1000\n");
                    }
                } catch (Exception exception) {
                    Log.error("Illegal port number\n");
                    return;
                }
            }
        }
    });

    exitItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            tray.remove(trayIcon);
            shutDownWebServer();
            Log.info("Exiting from J2AutoIt Agent\n");
            System.exit(0);
        }
    });
}

From source file:net.pms.newgui.NavigationShareTab.java

private void initSimpleComponents(CellConstraints cc) {
    // Thumbnail seeking position
    seekpos = new JTextField("" + configuration.getThumbnailSeekPos());
    seekpos.addKeyListener(new KeyAdapter() {
        @Override//  w w w  .  j  a  va  2 s  . c om
        public void keyReleased(KeyEvent e) {
            try {
                int ab = Integer.parseInt(seekpos.getText());
                configuration.setThumbnailSeekPos(ab);
                if (configuration.getUseCache()) {
                    PMS.get().getDatabase().init(true);
                }
            } catch (NumberFormatException nfe) {
                LOGGER.debug("Could not parse thumbnail seek position from \"" + seekpos.getText() + "\"");
            }

        }
    });
    if (configuration.isThumbnailGenerationEnabled()) {
        seekpos.setEnabled(true);
    } else {
        seekpos.setEnabled(false);
    }

    // Generate thumbnails
    thumbgenCheckBox = new JCheckBox(Messages.getString("NetworkTab.2"),
            configuration.isThumbnailGenerationEnabled());
    thumbgenCheckBox.setContentAreaFilled(false);
    thumbgenCheckBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setThumbnailGenerationEnabled((e.getStateChange() == ItemEvent.SELECTED));
            seekpos.setEnabled(configuration.isThumbnailGenerationEnabled());
            mplayer_thumb.setEnabled(configuration.isThumbnailGenerationEnabled());
        }
    });

    // Use MPlayer for video thumbnails
    mplayer_thumb = new JCheckBox(Messages.getString("FoldTab.14"), configuration.isUseMplayerForVideoThumbs());
    mplayer_thumb.setToolTipText(Messages.getString("FoldTab.61"));
    mplayer_thumb.setContentAreaFilled(false);
    mplayer_thumb.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setUseMplayerForVideoThumbs((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    if (configuration.isThumbnailGenerationEnabled()) {
        mplayer_thumb.setEnabled(true);
    } else {
        mplayer_thumb.setEnabled(false);
    }

    // DVD ISO thumbnails
    dvdiso_thumb = new JCheckBox(Messages.getString("FoldTab.19"), configuration.isDvdIsoThumbnails());
    dvdiso_thumb.setContentAreaFilled(false);
    dvdiso_thumb.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setDvdIsoThumbnails((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Image thumbnails
    image_thumb = new JCheckBox(Messages.getString("FoldTab.21"), configuration.getImageThumbnailsEnabled());
    image_thumb.setContentAreaFilled(false);
    image_thumb.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setImageThumbnailsEnabled((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Audio thumbnails import
    final KeyedComboBoxModel<CoverSupplier, String> thumbKCBM = new KeyedComboBoxModel<>(
            new CoverSupplier[] { CoverSupplier.NONE, CoverSupplier.COVER_ART_ARCHIVE },
            new String[] { Messages.getString("FoldTab.35"), Messages.getString("FoldTab.73") });
    audiothumbnail = new JComboBox<>(thumbKCBM);
    audiothumbnail.setEditable(false);

    thumbKCBM.setSelectedKey(configuration.getAudioThumbnailMethod());

    audiothumbnail.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setAudioThumbnailMethod(thumbKCBM.getSelectedKey());
                LOGGER.info("Setting {} {}", Messages.getRootString("FoldTab.26"),
                        thumbKCBM.getSelectedValue());
            }
        }
    });

    // Alternate video cover art folder
    defaultThumbFolder = new JTextField(configuration.getAlternateThumbFolder());
    defaultThumbFolder.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setAlternateThumbFolder(defaultThumbFolder.getText());
        }
    });

    // Alternate video cover art folder button
    select = new CustomJButton("...");
    select.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser;
            try {
                chooser = new JFileChooser();
            } catch (Exception ee) {
                chooser = new JFileChooser(new RestrictedFileSystemView());
            }
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28"));
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                defaultThumbFolder.setText(chooser.getSelectedFile().getAbsolutePath());
                configuration.setAlternateThumbFolder(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });

    // Show Server Settings folder
    isShowFolderServerSettings = new JCheckBox(Messages.getString("FoldTab.ShowServerSettingsFolder"),
            configuration.isShowServerSettingsFolder());
    isShowFolderServerSettings.setContentAreaFilled(false);
    isShowFolderServerSettings.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowServerSettingsFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Show #--TRANSCODE--# folder
    isShowFolderTranscode = new JCheckBox(Messages.getString("FoldTab.ShowTranscodeFolder"),
            configuration.isShowTranscodeFolder());
    isShowFolderTranscode.setContentAreaFilled(false);
    isShowFolderTranscode.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowTranscodeFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Show Media Library folder
    isShowFolderMediaLibrary = new JCheckBox(Messages.getString("FoldTab.ShowMediaLibraryFolder"),
            configuration.isShowMediaLibraryFolder());
    isShowFolderMediaLibrary.setContentAreaFilled(false);
    isShowFolderMediaLibrary.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowMediaLibraryFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Browse compressed archives
    archive = new JCheckBox(Messages.getString("NetworkTab.1"), configuration.isArchiveBrowsing());
    archive.setContentAreaFilled(false);
    archive.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setArchiveBrowsing(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    // Enable the Media Library
    cacheenable = new JCheckBox(Messages.getString("NetworkTab.EnableMediaLibrary"),
            configuration.getUseCache());
    cacheenable.setToolTipText(Messages.getString("FoldTab.ShowMediaLibraryFolderTooltip"));
    cacheenable.setContentAreaFilled(false);
    cacheenable.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setUseCache((e.getStateChange() == ItemEvent.SELECTED));
            cachereset.setEnabled(configuration.getUseCache());
            setScanLibraryEnabled(configuration.getUseCache());
        }
    });

    // Reset cache
    cachereset = new CustomJButton(Messages.getString("NetworkTab.EmptyMediaLibrary"));
    cachereset.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int option = JOptionPane.showConfirmDialog(looksFrame,
                    Messages.getString("NetworkTab.MediaLibraryEmptiedExceptFullyPlayed") + "\n"
                            + Messages.getString("NetworkTab.19"),
                    Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION);
            if (option == JOptionPane.YES_OPTION) {
                PMS.get().getDatabase().init(true);
            }

        }
    });
    cachereset.setEnabled(configuration.getUseCache());

    // Hide file extensions
    hideextensions = new JCheckBox(Messages.getString("FoldTab.5"), configuration.isHideExtensions());
    hideextensions.setContentAreaFilled(false);
    if (configuration.isPrettifyFilenames()) {
        hideextensions.setEnabled(false);
    }
    hideextensions.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setHideExtensions((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Hide transcoding engine names
    hideengines = new JCheckBox(Messages.getString("FoldTab.8"), configuration.isHideEngineNames());
    hideengines.setToolTipText(Messages.getString("FoldTab.46"));
    hideengines.setContentAreaFilled(false);
    hideengines.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setHideEngineNames((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Hide empty folders
    hideemptyfolders = new JCheckBox(Messages.getString("FoldTab.31"), configuration.isHideEmptyFolders());
    hideemptyfolders.setToolTipText(Messages.getString("FoldTab.59"));
    hideemptyfolders.setContentAreaFilled(false);
    hideemptyfolders.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setHideEmptyFolders((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Show iTunes library
    itunes = new JCheckBox(Messages.getString("FoldTab.30"), configuration.isShowItunesLibrary());
    itunes.setToolTipText(Messages.getString("FoldTab.47"));
    itunes.setContentAreaFilled(false);
    if (!(Platform.isMac() || Platform.isWindows())) {
        itunes.setEnabled(false);
    }
    itunes.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowItunesLibrary((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Show iPhoto library
    iphoto = new JCheckBox(Messages.getString("FoldTab.29"), configuration.isShowIphotoLibrary());
    iphoto.setContentAreaFilled(false);
    if (!Platform.isMac()) {
        iphoto.setEnabled(false);
    }
    iphoto.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowIphotoLibrary((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Show aperture library
    aperture = new JCheckBox(Messages.getString("FoldTab.34"), configuration.isShowApertureLibrary());
    aperture.setContentAreaFilled(false);
    if (!Platform.isMac()) {
        aperture.setEnabled(false);
    }
    aperture.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowApertureLibrary((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // File order
    final KeyedComboBoxModel<Integer, String> kcbm = new KeyedComboBoxModel<>(
            new Integer[] { UMSUtils.SORT_LOC_SENS, // alphabetical
                    UMSUtils.SORT_LOC_NAT, // natural sort
                    UMSUtils.SORT_INS_ASCII, // ASCIIbetical
                    UMSUtils.SORT_MOD_NEW, // newest first
                    UMSUtils.SORT_MOD_OLD, // oldest first
                    UMSUtils.SORT_RANDOM, // random
                    UMSUtils.SORT_NO_SORT // no sorting
            },
            new String[] { Messages.getString("FoldTab.15"), Messages.getString("FoldTab.22"),
                    Messages.getString("FoldTab.20"), Messages.getString("FoldTab.16"),
                    Messages.getString("FoldTab.17"), Messages.getString("FoldTab.58"),
                    Messages.getString("FoldTab.62") });
    sortmethod = new JComboBox<>(kcbm);
    sortmethod.setEditable(false);
    kcbm.setSelectedKey(configuration.getSortMethod(null));

    sortmethod.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setSortMethod(kcbm.getSelectedKey());
                LOGGER.info("Setting {} {}", Messages.getRootString("FoldTab.18"), kcbm.getSelectedValue());
            }
        }
    });

    // Ignore the word "the" while sorting
    ignorethewordthe = new JCheckBox(Messages.getString("FoldTab.39"), configuration.isIgnoreTheWordAandThe());
    ignorethewordthe.setToolTipText(Messages.getString("FoldTab.44"));
    ignorethewordthe.setContentAreaFilled(false);
    ignorethewordthe.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setIgnoreTheWordAandThe((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    atzLimit = new JTextField("" + configuration.getATZLimit());
    atzLimit.setToolTipText(Messages.getString("FoldTab.49"));
    atzLimit.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            try {
                int ab = Integer.parseInt(atzLimit.getText());
                configuration.setATZLimit(ab);
            } catch (NumberFormatException nfe) {
                LOGGER.debug("Could not parse ATZ limit from \"" + atzLimit.getText() + "\"");
                LOGGER.debug("The full error was: " + nfe);
            }
        }
    });

    isShowFolderLiveSubtitles = new JCheckBox(Messages.getString("FoldTab.ShowLiveSubtitlesFolder"),
            configuration.isShowLiveSubtitlesFolder());
    isShowFolderLiveSubtitles.setContentAreaFilled(false);
    isShowFolderLiveSubtitles.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowLiveSubtitlesFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    prettifyfilenames = new JCheckBox(Messages.getString("FoldTab.43"), configuration.isPrettifyFilenames());
    prettifyfilenames.setToolTipText(Messages.getString("FoldTab.45"));
    prettifyfilenames.setContentAreaFilled(false);
    prettifyfilenames.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setPrettifyFilenames((e.getStateChange() == ItemEvent.SELECTED));
            hideextensions.setEnabled((e.getStateChange() != ItemEvent.SELECTED));
            episodeTitles.setEnabled((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    episodeTitles = new JCheckBox(Messages.getString("FoldTab.74"), configuration.isUseInfoFromIMDb());
    episodeTitles.setToolTipText(Messages.getString("FoldTab.64"));
    episodeTitles.setContentAreaFilled(false);
    if (!configuration.isPrettifyFilenames()) {
        episodeTitles.setEnabled(false);
    }
    episodeTitles.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setUseInfoFromIMDb((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    isShowFolderNewMedia = new JCheckBox(Messages.getString("FoldTab.ShowNewMediaFolder"),
            configuration.isShowNewMediaFolder());
    isShowFolderNewMedia.setToolTipText(Messages.getString("FoldTab.66"));
    isShowFolderNewMedia.setContentAreaFilled(false);
    isShowFolderNewMedia.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowNewMediaFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    resume = new JCheckBox(Messages.getString("NetworkTab.68"), configuration.isResumeEnabled());
    resume.setToolTipText(Messages.getString("NetworkTab.69"));
    resume.setContentAreaFilled(false);
    resume.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setResume((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    isShowFolderRecentlyPlayed = new JCheckBox(Messages.getString("FoldTab.ShowRecentlyPlayedFolder"),
            configuration.isShowRecentlyPlayedFolder());
    isShowFolderRecentlyPlayed.setContentAreaFilled(false);
    isShowFolderRecentlyPlayed.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowRecentlyPlayedFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Fully played action
    final KeyedComboBoxModel<FullyPlayedAction, String> fullyPlayedActionModel = new KeyedComboBoxModel<>(
            new FullyPlayedAction[] { FullyPlayedAction.NO_ACTION, FullyPlayedAction.MARK,
                    FullyPlayedAction.HIDE_VIDEO, FullyPlayedAction.MOVE_FOLDER, FullyPlayedAction.MOVE_TRASH },
            new String[] { Messages.getString("FoldTab.67"), Messages.getString("FoldTab.68"),
                    Messages.getString("FoldTab.69"), Messages.getString("FoldTab.70"),
                    Messages.getString("FoldTab.71") });
    fullyPlayedAction = new JComboBox<>(fullyPlayedActionModel);
    fullyPlayedAction.setEditable(false);
    fullyPlayedActionModel.setSelectedKey(configuration.getFullyPlayedAction());
    fullyPlayedAction.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setFullyPlayedAction(fullyPlayedActionModel.getSelectedKey());
                fullyPlayedOutputDirectory
                        .setEnabled(fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.MOVE_FOLDER);
                selectFullyPlayedOutputDirectory
                        .setEnabled(fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.MOVE_FOLDER);

                if (configuration.getUseCache()
                        && fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.NO_ACTION) {
                    PMS.get().getDatabase().init(true);
                }
            }
        }
    });

    // Watched video output directory
    fullyPlayedOutputDirectory = new JTextField(configuration.getFullyPlayedOutputDirectory());
    fullyPlayedOutputDirectory.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setFullyPlayedOutputDirectory(fullyPlayedOutputDirectory.getText());
        }
    });
    fullyPlayedOutputDirectory
            .setEnabled(configuration.getFullyPlayedAction() == FullyPlayedAction.MOVE_FOLDER);

    // Watched video output directory selection button
    selectFullyPlayedOutputDirectory = new CustomJButton("...");
    selectFullyPlayedOutputDirectory.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser;
            try {
                chooser = new JFileChooser();
            } catch (Exception ee) {
                chooser = new JFileChooser(new RestrictedFileSystemView());
            }
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28"));
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                fullyPlayedOutputDirectory.setText(chooser.getSelectedFile().getAbsolutePath());
                configuration.setFullyPlayedOutputDirectory(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    selectFullyPlayedOutputDirectory
            .setEnabled(configuration.getFullyPlayedAction() == FullyPlayedAction.MOVE_FOLDER);
}

From source file:net.sf.taverna.t2.activities.spreadsheet.views.SpreadsheetImportConfigView.java

@Override
protected void initialise() {
    super.initialise();
    newConfiguration = getJson().deepCopy();

    // title// w  ww  .  j ava2 s.  c om
    titlePanel = new JPanel(new BorderLayout());
    titlePanel.setBackground(Color.WHITE);
    addDivider(titlePanel, SwingConstants.BOTTOM, true);

    titleLabel = new JLabel(SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.panelTitle"));
    titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 13.5f));
    titleIcon = new JLabel("");
    titleMessage = new DialogTextArea(DEFAULT_MESSAGE);
    titleMessage.setMargin(new Insets(5, 10, 10, 10));
    // titleMessage.setMinimumSize(new Dimension(0, 30));
    titleMessage.setFont(titleMessage.getFont().deriveFont(11f));
    titleMessage.setEditable(false);
    titleMessage.setFocusable(false);
    // titleMessage.setFont(titleLabel.getFont().deriveFont(Font.PLAIN,
    // 12f));

    // column range
    columnLabel = new JLabel(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.columnSectionLabel"));

    JsonNode columnRange = newConfiguration.get("columnRange");
    columnFromValue = new JTextField(new UpperCaseDocument(),
            SpreadsheetUtils.getColumnLabel(columnRange.get("start").intValue()), 4);
    columnFromValue.setMinimumSize(columnFromValue.getPreferredSize());
    columnToValue = new JTextField(new UpperCaseDocument(),
            SpreadsheetUtils.getColumnLabel(columnRange.get("end").intValue()), 4);
    columnToValue.setMinimumSize(columnToValue.getPreferredSize());

    columnFromValue.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
            checkValue(columnFromValue.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            checkValue(columnFromValue.getText());
        }

        private void checkValue(String text) {
            if (text.trim().equals("")) {
                addErrorMessage(EMPTY_FROM_COLUMN_ERROR_MESSAGE);
            } else if (text.trim().matches("[A-Za-z]+")) {
                String fromColumn = columnFromValue.getText().toUpperCase();
                String toColumn = columnToValue.getText().toUpperCase();
                int fromColumnIndex = SpreadsheetUtils.getColumnIndex(fromColumn);
                int toColumnIndex = SpreadsheetUtils.getColumnIndex(toColumn);
                if (checkColumnRange(fromColumnIndex, toColumnIndex)) {
                    columnMappingTableModel.setFromColumn(fromColumnIndex);
                    columnMappingTableModel.setToColumn(toColumnIndex);
                    newConfiguration.set("columnRange", newConfiguration.objectNode()
                            .put("start", fromColumnIndex).put("end", toColumnIndex));
                    validatePortNames();
                }
                removeErrorMessage(FROM_COLUMN_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_FROM_COLUMN_ERROR_MESSAGE);
            } else {
                addErrorMessage(FROM_COLUMN_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_FROM_COLUMN_ERROR_MESSAGE);
            }
        }

    });

    columnToValue.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
            checkValue(columnToValue.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            checkValue(columnToValue.getText());
        }

        private void checkValue(String text) {
            if (text.trim().equals("")) {
                addErrorMessage(EMPTY_TO_COLUMN_ERROR_MESSAGE);
            } else if (text.trim().matches("[A-Za-z]+")) {
                String fromColumn = columnFromValue.getText().toUpperCase();
                String toColumn = columnToValue.getText().toUpperCase();
                int fromColumnIndex = SpreadsheetUtils.getColumnIndex(fromColumn);
                int toColumnIndex = SpreadsheetUtils.getColumnIndex(toColumn);
                if (checkColumnRange(fromColumnIndex, toColumnIndex)) {
                    columnMappingTableModel.setFromColumn(fromColumnIndex);
                    columnMappingTableModel.setToColumn(toColumnIndex);
                    newConfiguration.set("columnRange", newConfiguration.objectNode()
                            .put("start", fromColumnIndex).put("end", toColumnIndex));
                    validatePortNames();
                }
                removeErrorMessage(TO_COLUMN_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_TO_COLUMN_ERROR_MESSAGE);

            } else {
                addErrorMessage(TO_COLUMN_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_TO_COLUMN_ERROR_MESSAGE);
            }
        }
    });

    // row range
    rowLabel = new JLabel(SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.rowSectionLabel"));
    addDivider(rowLabel, SwingConstants.TOP, false);

    rowSelectAllOption = new JCheckBox(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.selectAllRowsOption"));
    rowExcludeFirstOption = new JCheckBox(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.excludeHeaderRowOption"));
    rowIgnoreBlankRows = new JCheckBox(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.ignoreBlankRowsOption"));
    rowSelectAllOption.setFocusable(false);
    rowExcludeFirstOption.setFocusable(false);

    JsonNode rowRange = newConfiguration.get("rowRange");
    rowFromValue = new JTextField(new NumericDocument(), String.valueOf(rowRange.get("start").intValue() + 1),
            4);
    if (rowRange.get("end").intValue() == -1) {
        rowToValue = new JTextField(new NumericDocument(), "", 4);
    } else {
        rowToValue = new JTextField(new NumericDocument(), String.valueOf(rowRange.get("end").intValue() + 1),
                4);
    }
    rowFromValue.setMinimumSize(rowFromValue.getPreferredSize());
    rowToValue.setMinimumSize(rowToValue.getPreferredSize());

    if (newConfiguration.get("allRows").booleanValue()) {
        rowSelectAllOption.setSelected(true);
        rowFromValue.setEditable(false);
        rowFromValue.setEnabled(false);
        rowToValue.setEditable(false);
        rowToValue.setEnabled(false);
    } else {
        rowExcludeFirstOption.setEnabled(false);
    }
    rowExcludeFirstOption.setSelected(newConfiguration.get("excludeFirstRow").booleanValue());
    rowIgnoreBlankRows.setSelected(newConfiguration.get("ignoreBlankRows").booleanValue());

    rowFromValue.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
            checkValue(rowFromValue.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            checkValue(rowFromValue.getText());
        }

        private void checkValue(String text) {
            if (text.trim().equals("")) {
                addErrorMessage(EMPTY_FROM_ROW_ERROR_MESSAGE);
            } else if (text.trim().matches("[1-9][0-9]*")) {
                checkRowRange(rowFromValue.getText(), rowToValue.getText());
                int fromRow = Integer.parseInt(rowFromValue.getText());
                ((ObjectNode) newConfiguration.get("rowRange")).put("start", fromRow - 1);
                removeErrorMessage(FROM_ROW_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_FROM_ROW_ERROR_MESSAGE);
            } else {
                addErrorMessage(FROM_ROW_ERROR_MESSAGE);
                removeErrorMessage(EMPTY_FROM_ROW_ERROR_MESSAGE);
            }
        }
    });

    rowToValue.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
            checkValue(rowToValue.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            checkValue(rowToValue.getText());
        }

        private void checkValue(String text) {
            if (text.trim().equals("")) {
                ((ObjectNode) newConfiguration.get("rowRange")).put("end", -1);
                removeErrorMessage(TO_ROW_ERROR_MESSAGE);
                removeErrorMessage(INCONSISTENT_ROW_MESSAGE);
            } else if (text.trim().matches("[0-9]+")) {
                checkRowRange(rowFromValue.getText(), rowToValue.getText());
                int toRow = Integer.parseInt(rowToValue.getText());
                ((ObjectNode) newConfiguration.get("rowRange")).put("end", toRow - 1);
                removeErrorMessage(TO_ROW_ERROR_MESSAGE);
            } else {
                addErrorMessage(TO_ROW_ERROR_MESSAGE);
            }
        }
    });

    rowSelectAllOption.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                newConfiguration.put("allRows", true);
                rowExcludeFirstOption.setEnabled(true);
                if (rowExcludeFirstOption.isSelected()) {
                    rowFromValue.setText("2");
                } else {
                    rowFromValue.setText("1");
                }
                rowToValue.setText("");
                rowFromValue.setEditable(false);
                rowFromValue.setEnabled(false);
                rowToValue.setEditable(false);
                rowToValue.setEnabled(false);
            } else {
                newConfiguration.put("allRows", false);
                rowExcludeFirstOption.setEnabled(false);
                rowFromValue.setEditable(true);
                rowFromValue.setEnabled(true);
                rowToValue.setEditable(true);
                rowToValue.setEnabled(true);
            }
        }
    });

    rowExcludeFirstOption.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                newConfiguration.put("excludeFirstRow", true);
                rowFromValue.setText("2");
                ((ObjectNode) newConfiguration.get("rowRange")).put("start", 1);
            } else {
                newConfiguration.put("excludeFirstRow", false);
                rowFromValue.setText("1");
                ((ObjectNode) newConfiguration.get("rowRange")).put("start", 0);
            }
        }
    });

    rowIgnoreBlankRows.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            newConfiguration.put("ignoreBlankRows", e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    // empty cells
    emptyCellLabel = new JLabel(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.emptyCellSectionLabel"));
    addDivider(emptyCellLabel, SwingConstants.TOP, false);

    emptyCellButtonGroup = new ButtonGroup();
    emptyCellEmptyStringOption = new JRadioButton(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.emptyStringOption"));
    emptyCellUserDefinedOption = new JRadioButton(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.userDefinedOption"));
    emptyCellErrorValueOption = new JRadioButton(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.generateErrorOption"));
    emptyCellEmptyStringOption.setFocusable(false);
    emptyCellUserDefinedOption.setFocusable(false);
    emptyCellErrorValueOption.setFocusable(false);

    emptyCellUserDefinedValue = new JTextField(newConfiguration.get("emptyCellValue").textValue());

    emptyCellButtonGroup.add(emptyCellEmptyStringOption);
    emptyCellButtonGroup.add(emptyCellUserDefinedOption);
    emptyCellButtonGroup.add(emptyCellErrorValueOption);

    if (newConfiguration.get("emptyCellPolicy").textValue().equals("GENERATE_ERROR")) {
        emptyCellErrorValueOption.setSelected(true);
        emptyCellUserDefinedValue.setEnabled(false);
        emptyCellUserDefinedValue.setEditable(false);
    } else if (newConfiguration.get("emptyCellPolicy").textValue().equals("EMPTY_STRING")) {
        emptyCellEmptyStringOption.setSelected(true);
        emptyCellUserDefinedValue.setEnabled(false);
        emptyCellUserDefinedValue.setEditable(false);
    } else {
        emptyCellUserDefinedOption.setSelected(true);
        emptyCellUserDefinedValue.setText(newConfiguration.get("emptyCellValue").textValue());
        emptyCellUserDefinedValue.setEnabled(true);
        emptyCellUserDefinedValue.setEditable(true);
    }

    emptyCellEmptyStringOption.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            newConfiguration.put("emptyCellPolicy", "EMPTY_STRING");
            emptyCellUserDefinedValue.setEnabled(false);
            emptyCellUserDefinedValue.setEditable(false);
        }
    });
    emptyCellUserDefinedOption.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            newConfiguration.put("emptyCellPolicy", "USER_DEFINED");
            emptyCellUserDefinedValue.setEnabled(true);
            emptyCellUserDefinedValue.setEditable(true);
            emptyCellUserDefinedValue.requestFocusInWindow();
        }
    });
    emptyCellErrorValueOption.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            newConfiguration.put("emptyCellPolicy", "GENERATE_ERROR");
            emptyCellUserDefinedValue.setEnabled(false);
            emptyCellUserDefinedValue.setEditable(false);
        }
    });

    emptyCellUserDefinedValue.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            newConfiguration.put("emptyCellValue", emptyCellUserDefinedValue.getText());
        }

        public void insertUpdate(DocumentEvent e) {
            newConfiguration.put("emptyCellValue", emptyCellUserDefinedValue.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            newConfiguration.put("emptyCellValue", emptyCellUserDefinedValue.getText());
        }
    });

    // column mappings
    columnMappingLabel = new JLabel(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.columnMappingSectionLabel"));
    addDivider(columnMappingLabel, SwingConstants.TOP, false);

    Map<String, String> columnToPortMapping = new HashMap<>();
    if (newConfiguration.has("columnNames")) {
        for (JsonNode columnName : newConfiguration.get("columnNames")) {
            columnToPortMapping.put(columnName.get("column").textValue(), columnName.get("port").textValue());
        }
    }
    columnMappingTableModel = new SpreadsheetImportConfigTableModel(columnFromValue.getText(),
            columnToValue.getText(), columnToPortMapping);

    columnMappingTable = new JTable();
    columnMappingTable.setRowSelectionAllowed(false);
    columnMappingTable.getTableHeader().setReorderingAllowed(false);
    columnMappingTable.setGridColor(Color.LIGHT_GRAY);
    // columnMappingTable.setFocusable(false);

    columnMappingTable.setColumnModel(new DefaultTableColumnModel() {
        public TableColumn getColumn(int columnIndex) {
            TableColumn column = super.getColumn(columnIndex);
            if (columnIndex == 0) {
                column.setMaxWidth(100);
            }
            return column;
        }
    });

    TableCellEditor defaultEditor = columnMappingTable.getDefaultEditor(String.class);
    if (defaultEditor instanceof DefaultCellEditor) {
        DefaultCellEditor defaultCellEditor = (DefaultCellEditor) defaultEditor;
        defaultCellEditor.setClickCountToStart(1);
        Component editorComponent = defaultCellEditor.getComponent();
        if (editorComponent instanceof JTextComponent) {
            final JTextComponent textField = (JTextComponent) editorComponent;
            textField.getDocument().addDocumentListener(new DocumentListener() {
                public void changedUpdate(DocumentEvent e) {
                    updateModel(textField.getText());
                }

                public void insertUpdate(DocumentEvent e) {
                    updateModel(textField.getText());
                }

                public void removeUpdate(DocumentEvent e) {
                    updateModel(textField.getText());
                }

                private void updateModel(String text) {
                    int row = columnMappingTable.getEditingRow();
                    int column = columnMappingTable.getEditingColumn();
                    columnMappingTableModel.setValueAt(text, row, column);

                    ArrayNode columnNames = newConfiguration.arrayNode();
                    Map<String, String> columnToPortMapping = columnMappingTableModel.getColumnToPortMapping();
                    for (Entry<String, String> entry : columnToPortMapping.entrySet()) {
                        columnNames.add(newConfiguration.objectNode().put("column", entry.getKey()).put("port",
                                entry.getValue()));
                    }
                    newConfiguration.put("columnNames", columnNames);
                    validatePortNames();
                }

            });
        }
    }

    columnMappingTable.setModel(columnMappingTableModel);

    // output format
    outputFormatLabel = new JLabel(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.outputFormatSectionLabel"));

    outputFormatMultiplePort = new JRadioButton(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.multiplePortOption"));
    outputFormatSinglePort = new JRadioButton(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.singlePortOption"));
    outputFormatMultiplePort.setFocusable(false);
    outputFormatSinglePort.setFocusable(false);

    outputFormatDelimiterLabel = new JLabel(
            SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.userDefinedCsvDelimiter"));
    outputFormatDelimiter = new JTextField(newConfiguration.get("csvDelimiter").textValue(), 5);

    outputFormatButtonGroup = new ButtonGroup();
    outputFormatButtonGroup.add(outputFormatMultiplePort);
    outputFormatButtonGroup.add(outputFormatSinglePort);

    if (newConfiguration.get("outputFormat").textValue().equals("PORT_PER_COLUMN")) {
        outputFormatMultiplePort.setSelected(true);
        outputFormatDelimiterLabel.setEnabled(false);
        outputFormatDelimiter.setEnabled(false);
    } else {
        outputFormatSinglePort.setSelected(true);
        columnMappingLabel.setEnabled(false);
        enableTable(columnMappingTable, false);
    }

    outputFormatMultiplePort.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            outputFormatDelimiterLabel.setEnabled(false);
            outputFormatDelimiter.setEnabled(false);
            columnMappingLabel.setEnabled(true);
            enableTable(columnMappingTable, true);
            newConfiguration.put("outputFormat", "PORT_PER_COLUMN");
        }
    });
    outputFormatSinglePort.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            outputFormatDelimiterLabel.setEnabled(true);
            outputFormatDelimiter.setEnabled(true);
            columnMappingLabel.setEnabled(false);
            enableTable(columnMappingTable, false);
            newConfiguration.put("outputFormat", "SINGLE_PORT");
        }

    });
    outputFormatDelimiter.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            handleUpdate();
        }

        public void insertUpdate(DocumentEvent e) {
            handleUpdate();
        }

        public void removeUpdate(DocumentEvent e) {
            handleUpdate();
        }

        private void handleUpdate() {
            String text = null;
            try {
                text = StringEscapeUtils.unescapeJava(outputFormatDelimiter.getText());
            } catch (RuntimeException re) {
            }
            if (text == null || text.length() == 0) {
                newConfiguration.put("csvDelimiter", ",");
            } else {
                newConfiguration.put("csvDelimiter", text.substring(0, 1));
            }
        }

    });

    // buttons
    nextButton = new JButton(SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.nextButton"));
    nextButton.setFocusable(false);
    nextButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            backButton.setVisible(true);
            nextButton.setVisible(false);
            cardLayout.last(contentPanel);
        }
    });

    backButton = new JButton(SpreadsheetImportUIText.getString("SpreadsheetImportConfigView.backButton"));
    backButton.setFocusable(false);
    backButton.setVisible(false);
    backButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            nextButton.setVisible(true);
            backButton.setVisible(false);
            cardLayout.first(contentPanel);
        }
    });

    buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    addDivider(buttonPanel, SwingConstants.TOP, true);

    removeAll();
    layoutPanel();
}

From source file:king.flow.action.DefaultMsgSendAction.java

protected void showDoneMsg(final TLSResult result) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override/*from   w w  w . j ava 2s .  c o m*/
        public void run() {
            if (doneDisplayList.size() == 1) {
                showOnComponent(getBlockMeta(doneDisplayList.get(0)), result);
            } else {
                try {
                    JSONParser jsonParser = new JSONParser();
                    Object element = jsonParser.parse(result.getOkMsg());
                    if (element instanceof JSONArray) {
                        JSONArray jsonArray = (JSONArray) element;
                        int len = Integer.min(doneDisplayList.size(), jsonArray.size());
                        for (int i = 0; i < len; i++) {
                            TLSResult freshResult = new TLSResult(result.getRetCode(),
                                    jsonArray.get(i).toString(), result.getErrMsg(), result.getPrtMsg());
                            showOnComponent(getBlockMeta(doneDisplayList.get(i)), freshResult);
                        }
                    } else {
                        showOnComponent(getBlockMeta(doneDisplayList.get(0)), result);
                    }
                } catch (Exception e) {
                    getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING,
                            "Exception encounters during successful json value parsing : \n{0}", e);
                }
            }

            CommonUtil.cachePrintMsg(result.getPrtMsg());
            if (result.getRedirection() != null) {
                String redirection = result.getRedirection();
                getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO,
                        "Be forced to jump to page[{0}], ignore designated page[{1}]",
                        new Object[] { redirection, String.valueOf(next.getNextPanel()) });
                int forwardPage = 0;
                try {
                    forwardPage = Integer.parseInt(redirection);
                } catch (Exception e) {
                    panelJump(next.getNextPanel());
                    return;
                }
                Object blockMeta = getBlockMeta(forwardPage);
                if (blockMeta == null || !(blockMeta instanceof Panel)) {
                    getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO,
                            "Be forced to jump to page[{0}], but page[{0}] is invalid Panel type. It is type[{1}]",
                            new Object[] { redirection,
                                    (blockMeta == null ? "NULL" : blockMeta.getClass().getSimpleName()) });
                    panelJump(next.getNextPanel());
                    return;
                }
                panelJump(forwardPage);
            } else {
                panelJump(next.getNextPanel());

                //trigger the action denoted in sendMsgAction
                Integer trigger = next.getTrigger();
                if (trigger != null && getBlockMeta(trigger) != null) {
                    final Component blockMeta = (Component) getBlockMeta(trigger);
                    switch (blockMeta.getType()) {
                    case COMBO_BOX:
                        JComboBox comboBlock = getBlock(trigger, JComboBox.class);
                        ItemListener[] itemListeners = comboBlock.getItemListeners();
                        ItemEvent e = new ItemEvent(comboBlock, ItemEvent.ITEM_STATE_CHANGED,
                                comboBlock.getItemAt(comboBlock.getItemCount() - 1).toString(),
                                ItemEvent.SELECTED);
                        for (ItemListener itemListener : itemListeners) {
                            itemListener.itemStateChanged(e);//wait and hang on util progress dialog gets to dispose
                        }
                        if (comboBlock.isEditable()) {
                            String value = comboBlock.getEditor().getItem().toString();
                            if (value.length() == 0) {
                                return;
                            }
                        }
                        break;
                    case BUTTON:
                        JButton btnBlock = getBlock(trigger, JButton.class);
                        btnBlock.doClick();
                        break;
                    default:
                        getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING,
                                "Invalid trigger component[{0}] as unsupported type[{1}]",
                                new Object[] { trigger, blockMeta.getType() });
                        break;
                    }
                } //trigger dealing 
                  //keep next cursor on correct component
                Integer nextCursor = next.getNextCursor();
                if (nextCursor != null && getBlockMeta(nextCursor) != null) {
                    JComponent block = getBlock(nextCursor, JComponent.class);
                    block.requestFocusInWindow();
                }
            } // no redirection branch
        }
    });
}

From source file:org.geopublishing.atlasStyler.swing.PolygonSymbolEditGUI.java

/**
 * This method initializes jComboBox//ww w .ja v  a 2 s  . c o  m
 * 
 * This {@link JComboBox} has the same Model as the FillOpacity
 * 
 * @return javax.swing.JComboBox
 */
private JComboBox getJComboBoxFillGraphicOpacity() {
    if (jComboBoxGraphicFillOpacity == null) {
        jComboBoxGraphicFillOpacity = new OpacityJComboBox();

        // Initialize correctly
        boolean enabled = (symbolizer.getFill() != null && symbolizer.getFill().getGraphicFill() != null);
        jComboBoxGraphicFillOpacity.setEnabled(enabled);
        jLabelGraphicFillOpacity.setEnabled(enabled);

        // This {@link JComboBox} has the same Model as the
        // FillOpacityCOmboBox
        jComboBoxGraphicFillOpacity.setModel(getJComboBoxFillOpacity().getModel());
        final Fill ff = symbolizer.getFill();
        if (ff != null) {
            ASUtil.selectOrInsert(jComboBoxGraphicFillOpacity, ff.getOpacity());
        }

        jComboBoxGraphicFillOpacity.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {

                    symbolizer.getFill().setOpacity(ASUtil.ff2.literal(e.getItem()));

                    firePropertyChange(PROPERTY_UPDATED, null, null);

                }
            }

        });
        SwingUtil.addMouseWheelForCombobox(jComboBoxGraphicFillOpacity);

    }
    return jComboBoxGraphicFillOpacity;
}

From source file:com.microsoft.azure.hdinsight.spark.ui.SparkSubmissionContentPanel.java

private void addSelectedArtifactLineItem() {
    final String tipInfo = "The Artifact you want to use.";
    JLabel artifactSelectLabel = new JLabel("Select an Artifact to submit");
    artifactSelectLabel.setToolTipText(tipInfo);

    selectedArtifactComboBox = new ComboBox();
    selectedArtifactComboBox.setToolTipText(tipInfo);

    errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()] = new JLabel(
            "Artifact should not be null!");
    errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()]
            .setForeground(DarkThemeManager.getInstance().getErrorMessageColor());
    errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()].setVisible(false);

    errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()] = new JLabel(
            "Could not find the local jar package for Artifact");
    errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()]
            .setForeground(DarkThemeManager.getInstance().getErrorMessageColor());
    errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()].setVisible(false);

    selectedArtifactTextField = new TextFieldWithBrowseButton();
    selectedArtifactTextField.setToolTipText("Artifact from local jar package.");
    selectedArtifactTextField.setEditable(true);
    selectedArtifactTextField.setEnabled(false);
    selectedArtifactTextField.getTextField().getDocument().addDocumentListener(new DocumentListener() {
        @Override//ww  w . j av  a2  s  . c om
        public void insertUpdate(DocumentEvent e) {
            setVisibleForFixedErrorMessageLabel(2,
                    !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            setVisibleForFixedErrorMessageLabel(2,
                    !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            setVisibleForFixedErrorMessageLabel(2,
                    !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
        }
    });

    selectedArtifactTextField.getButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(false, false, true, false, true,
                    false);
            chooserDescriptor.setTitle("Select Local Artifact File");
            VirtualFile chooseFile = FileChooser.chooseFile(chooserDescriptor, null, null);
            if (chooseFile != null) {
                String path = chooseFile.getPath();
                if (path.endsWith("!/")) {
                    path = path.substring(0, path.length() - 2);
                }
                selectedArtifactTextField.setText(path);
            }
        }
    });

    intelliJArtifactRadioButton = new JRadioButton("Artifact from IntelliJ project:", true);
    localArtifactRadioButton = new JRadioButton("Artifact from local disk:", false);

    intelliJArtifactRadioButton.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectedArtifactComboBox.setEnabled(true);
                selectedArtifactTextField.setEnabled(false);
                mainClassTextField.setButtonEnabled(true);

                setVisibleForFixedErrorMessageLabel(2, false);

                if (selectedArtifactComboBox.getItemCount() == 0) {
                    setVisibleForFixedErrorMessageLabel(2, true);
                }
            }
        }
    });

    localArtifactRadioButton.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectedArtifactComboBox.setEnabled(false);
                selectedArtifactTextField.setEnabled(true);
                mainClassTextField.setButtonEnabled(false);

                setVisibleForFixedErrorMessageLabel(1, false);

                if (StringHelper.isNullOrWhiteSpace(selectedArtifactTextField.getText())) {
                    setVisibleForFixedErrorMessageLabel(2, true);
                }
            }
        }
    });

    ButtonGroup group = new ButtonGroup();
    group.add(intelliJArtifactRadioButton);
    group.add(localArtifactRadioButton);

    intelliJArtifactRadioButton.setSelected(true);

    add(artifactSelectLabel, new GridBagConstraints(0, ++displayLayoutCurrentRow, 0, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin, margin, 0, margin), 0, 0));

    add(intelliJArtifactRadioButton,
            new GridBagConstraints(0, ++displayLayoutCurrentRow, 1, 1, 0, 0, GridBagConstraints.WEST,
                    GridBagConstraints.NONE, new Insets(margin / 3, margin * 3, 0, margin), 0, 0));

    add(selectedArtifactComboBox,
            new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST,
                    GridBagConstraints.HORIZONTAL, new Insets(margin / 3, margin, 0, margin), 0, 0));

    add(errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()],
            new GridBagConstraints(1, ++displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST,
                    GridBagConstraints.NONE, new Insets(0, margin, 0, 0), 0, 0));

    add(localArtifactRadioButton,
            new GridBagConstraints(0, ++displayLayoutCurrentRow, 1, 1, 0, 0, GridBagConstraints.WEST,
                    GridBagConstraints.NONE, new Insets(margin / 3, margin * 3, 0, margin), 0, 0));

    add(selectedArtifactTextField,
            new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 0, 0, GridBagConstraints.WEST,
                    GridBagConstraints.HORIZONTAL, new Insets(margin / 3, margin, 0, margin), 0, 0));
    add(errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()],
            new GridBagConstraints(1, ++displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST,
                    GridBagConstraints.NONE, new Insets(0, margin, 0, 0), 0, 0));
}