Example usage for java.awt.event ItemListener ItemListener

List of usage examples for java.awt.event ItemListener ItemListener

Introduction

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

Prototype

ItemListener

Source Link

Usage

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

/**
 * This method initializes jComboBox1/*ww w. j  a va2  s.co  m*/
 * 
 * @return javax.swing.JComboBox
 */
private JComboBox getJComboBoxFillOpacity() {
    if (jComboBoxFillOpacity == null) {
        jComboBoxFillOpacity = new OpacityJComboBox();

        jComboBoxFillOpacity.setModel(new DefaultComboBoxModel(OPACITY_VALUES));

        Fill ff = symbolizer.getFill();
        if (ff != null) {
            if (ff.getOpacity() == null)
                ff.setOpacity(ASUtil.ff2.literal(1f));

            ASUtil.selectOrInsert(jComboBoxFillOpacity, ff.getOpacity());
        }

        // Initialize the enabled state
        boolean enabled = (symbolizer.getFill() != null && symbolizer.getFill().getGraphicFill() != null);
        jComboBoxFillOpacity.setEnabled(enabled);
        jLabelFillOpacity.setEnabled(enabled);

        jComboBoxFillOpacity.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(jComboBoxFillOpacity);

    }
    return jComboBoxFillOpacity;
}

From source file:org.languagetool.gui.Main.java

private void createGUI() {
    loadRecentFiles();//from w  ww .  j  a  v  a2  s.  c  o m
    frame = new JFrame("LanguageTool " + JLanguageTool.VERSION);

    setLookAndFeel();
    openAction = new OpenAction();
    saveAction = new SaveAction();
    saveAsAction = new SaveAsAction();
    checkAction = new CheckAction();
    autoCheckAction = new AutoCheckAction(true);
    showResultAction = new ShowResultAction(true);

    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new CloseListener());
    URL iconUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(TRAY_ICON);
    frame.setIconImage(new ImageIcon(iconUrl).getImage());

    textArea = new JTextArea();
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.addKeyListener(new ControlReturnTextCheckingListener());

    textLineNumber = new TextLineNumber(textArea, 2);
    numberedTextAreaPane = new JScrollPane(textArea);
    numberedTextAreaPane.setRowHeaderView(textLineNumber);

    resultArea = new JTextPane();
    undoRedo = new UndoRedoSupport(this.textArea, messages);
    frame.setJMenuBar(createMenuBar());

    GridBagConstraints buttonCons = new GridBagConstraints();

    JPanel insidePanel = new JPanel();
    insidePanel.setOpaque(false);
    insidePanel.setLayout(new GridBagLayout());

    buttonCons.gridx = 0;
    buttonCons.gridy = 0;
    buttonCons.anchor = GridBagConstraints.LINE_START;
    insidePanel.add(new JLabel(messages.getString("textLanguage") + " "), buttonCons);

    //create a ComboBox with flags, do not include hidden languages
    languageBox = LanguageComboBox.create(messages, EXTERNAL_LANGUAGE_SUFFIX, true, false);
    buttonCons.gridx = 1;
    buttonCons.gridy = 0;
    buttonCons.anchor = GridBagConstraints.LINE_START;
    insidePanel.add(languageBox, buttonCons);

    JCheckBox autoDetectBox = new JCheckBox(messages.getString("atd"));
    buttonCons.gridx = 2;
    buttonCons.gridy = 0;
    buttonCons.gridwidth = GridBagConstraints.REMAINDER;
    buttonCons.anchor = GridBagConstraints.LINE_START;
    insidePanel.add(autoDetectBox, buttonCons);

    buttonCons.gridx = 0;
    buttonCons.gridy = 1;
    buttonCons.gridwidth = GridBagConstraints.REMAINDER;
    buttonCons.fill = GridBagConstraints.HORIZONTAL;
    buttonCons.anchor = GridBagConstraints.LINE_END;
    buttonCons.weightx = 1.0;
    insidePanel.add(statusLabel, buttonCons);

    Container contentPane = frame.getContentPane();
    GridBagLayout gridLayout = new GridBagLayout();
    contentPane.setLayout(gridLayout);
    GridBagConstraints cons = new GridBagConstraints();

    cons.gridx = 0;
    cons.gridy = 1;
    cons.fill = GridBagConstraints.HORIZONTAL;
    cons.anchor = GridBagConstraints.FIRST_LINE_START;
    JToolBar toolbar = new JToolBar("Toolbar", JToolBar.HORIZONTAL);
    toolbar.setFloatable(false);
    contentPane.add(toolbar, cons);

    JButton openButton = new JButton(openAction);
    openButton.setHideActionText(true);
    openButton.setFocusable(false);
    toolbar.add(openButton);

    JButton saveButton = new JButton(saveAction);
    saveButton.setHideActionText(true);
    saveButton.setFocusable(false);
    toolbar.add(saveButton);

    JButton saveAsButton = new JButton(saveAsAction);
    saveAsButton.setHideActionText(true);
    saveAsButton.setFocusable(false);
    toolbar.add(saveAsButton);

    JButton spellButton = new JButton(this.checkAction);
    spellButton.setHideActionText(true);
    spellButton.setFocusable(false);
    toolbar.add(spellButton);

    JToggleButton autoSpellButton = new JToggleButton(autoCheckAction);
    autoSpellButton.setHideActionText(true);
    autoSpellButton.setFocusable(false);
    toolbar.add(autoSpellButton);

    JButton clearTextButton = new JButton(new ClearTextAction());
    clearTextButton.setHideActionText(true);
    clearTextButton.setFocusable(false);
    toolbar.add(clearTextButton);

    cons.insets = new Insets(5, 5, 5, 5);
    cons.fill = GridBagConstraints.BOTH;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.gridx = 0;
    cons.gridy = 2;
    cons.weighty = 5.0f;
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, numberedTextAreaPane, new JScrollPane(resultArea));
    mainPanel.setLayout(new GridLayout(0, 1));
    contentPane.add(mainPanel, cons);
    mainPanel.add(splitPane);

    cons.fill = GridBagConstraints.HORIZONTAL;
    cons.gridx = 0;
    cons.gridy = 3;
    cons.weightx = 1.0f;
    cons.weighty = 0.0f;
    cons.insets = new Insets(4, 12, 4, 12);
    contentPane.add(insidePanel, cons);

    ltSupport = new LanguageToolSupport(this.frame, this.textArea, this.undoRedo);
    ResultAreaHelper.install(messages, ltSupport, resultArea);
    languageBox.selectLanguage(ltSupport.getLanguage());
    languageBox.setEnabled(!ltSupport.getConfig().getAutoDetect());
    autoDetectBox.setSelected(ltSupport.getConfig().getAutoDetect());
    taggerShowsDisambigLog = ltSupport.getConfig().getTaggerShowsDisambigLog();

    languageBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                // we cannot re-use the existing LT object anymore
                frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));
                Language lang = languageBox.getSelectedLanguage();
                ComponentOrientation componentOrientation = ComponentOrientation
                        .getOrientation(lang.getLocale());
                textArea.applyComponentOrientation(componentOrientation);
                resultArea.applyComponentOrientation(componentOrientation);
                ltSupport.setLanguage(lang);
            }
        }
    });
    autoDetectBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            boolean selected = e.getStateChange() == ItemEvent.SELECTED;
            languageBox.setEnabled(!selected);
            ltSupport.getConfig().setAutoDetect(selected);
            if (selected) {
                Language detected = ltSupport.autoDetectLanguage(textArea.getText());
                languageBox.selectLanguage(detected);
            }
        }
    });
    ltSupport.addLanguageToolListener(new LanguageToolListener() {
        @Override
        public void languageToolEventOccurred(LanguageToolEvent event) {
            if (event.getType() == LanguageToolEvent.Type.CHECKING_STARTED) {
                String msg = org.languagetool.tools.Tools.i18n(messages, "checkStart");
                statusLabel.setText(msg);
                if (event.getCaller() == getFrame()) {
                    setWaitCursor();
                    checkAction.setEnabled(false);
                }
            } else if (event.getType() == LanguageToolEvent.Type.CHECKING_FINISHED) {
                if (event.getCaller() == getFrame()) {
                    checkAction.setEnabled(true);
                    unsetWaitCursor();
                }
                String msg = org.languagetool.tools.Tools.i18n(messages, "checkDone",
                        event.getSource().getMatches().size(), event.getElapsedTime());
                statusLabel.setText(msg);
            } else if (event.getType() == LanguageToolEvent.Type.LANGUAGE_CHANGED) {
                languageBox.selectLanguage(ltSupport.getLanguage());
            } else if (event.getType() == LanguageToolEvent.Type.RULE_ENABLED) {
                //this will trigger a check and the result will be updated by
                //the CHECKING_FINISHED event
            } else if (event.getType() == LanguageToolEvent.Type.RULE_DISABLED) {
                String msg = org.languagetool.tools.Tools.i18n(messages, "checkDoneNoTime",
                        event.getSource().getMatches().size());
                statusLabel.setText(msg);
            }
        }
    });
    frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));
    Language lang = ltSupport.getLanguage();
    ComponentOrientation componentOrientation = ComponentOrientation.getOrientation(lang.getLocale());
    textArea.applyComponentOrientation(componentOrientation);
    resultArea.applyComponentOrientation(componentOrientation);

    ResourceBundle textLanguageMessageBundle = JLanguageTool.getMessageBundle(ltSupport.getLanguage());
    textArea.setText(textLanguageMessageBundle.getString("guiDemoText"));

    Configuration config = ltSupport.getConfig();
    if (config.getFontName() != null || config.getFontStyle() != Configuration.FONT_STYLE_INVALID
            || config.getFontSize() != Configuration.FONT_SIZE_INVALID) {
        String fontName = config.getFontName();
        if (fontName == null) {
            fontName = textArea.getFont().getFamily();
        }
        int fontSize = config.getFontSize();
        if (fontSize == Configuration.FONT_SIZE_INVALID) {
            fontSize = textArea.getFont().getSize();
        }
        Font font = new Font(fontName, config.getFontStyle(), fontSize);
        textArea.setFont(font);
    }

    frame.pack();
    frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    frame.setLocationByPlatform(true);
    splitPane.setDividerLocation(200);
    MainWindowStateBean state = localStorage.loadProperty("gui.state", MainWindowStateBean.class);
    if (state != null) {
        if (state.getBounds() != null) {
            frame.setBounds(state.getBounds());
            ResizeComponentListener.setBoundsProperty(frame, state.getBounds());
        }
        if (state.getDividerLocation() != null) {
            splitPane.setDividerLocation(state.getDividerLocation());
        }
        if (state.getState() != null) {
            frame.setExtendedState(state.getState());
        }
    }
    ResizeComponentListener.attachToWindow(frame);
    maybeStartServer();
}

From source file:org.tinymediamanager.ui.settings.GeneralSettingsPanel.java

/**
 * Instantiates a new general settings panel.
 *///  w  w  w.j a v  a2  s.c  o m
public GeneralSettingsPanel() {
    setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("left:max(200px;min):grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(200px;default):grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, }));

    JPanel panelUI = new JPanel();
    panelUI.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.ui"), TitledBorder.LEADING, //$NON-NLS-1$
            TitledBorder.TOP, null, null));
    add(panelUI, "2, 2, 3, 1, fill, fill");
    panelUI.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("100dlu"), FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("default:grow"), FormSpecs.UNRELATED_GAP_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, FormSpecs.UNRELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, }));
    LocaleComboBox actualLocale = null;
    // cbLanguage = new JComboBox(Utils.getLanguages().toArray());
    Locale settingsLang = Utils.getLocaleFromLanguage(Globals.settings.getLanguage());
    for (Locale l : Utils.getLanguages()) {
        LocaleComboBox localeComboBox = new LocaleComboBox(l);
        locales.add(localeComboBox);
        if (l.equals(settingsLang)) {
            actualLocale = localeComboBox;
        }
    }

    JLabel lblUiLanguage = new JLabel(BUNDLE.getString("Settings.language"));
    panelUI.add(lblUiLanguage, "2, 2");
    cbLanguage = new JComboBox(locales.toArray());
    panelUI.add(cbLanguage, "4, 2");

    if (actualLocale != null) {
        cbLanguage.setSelectedItem(actualLocale);
    }

    JSeparator separator = new JSeparator();
    separator.setOrientation(SwingConstants.VERTICAL);
    panelUI.add(separator, "8, 2, 1, 7");

    JLabel lblFontFamily = new JLabel(BUNDLE.getString("Settings.fontfamily")); //$NON-NLS-1$
    panelUI.add(lblFontFamily, "10, 2, right, default");
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    cbFontFamily = new JComboBox(env.getAvailableFontFamilyNames());
    cbFontFamily.setSelectedItem(Globals.settings.getFontFamily());
    int index = cbFontFamily.getSelectedIndex();
    if (index < 0) {
        cbFontFamily.setSelectedItem("Dialog");
        index = cbFontFamily.getSelectedIndex();
    }
    if (index < 0) {
        cbFontFamily.setSelectedIndex(0);
    }
    panelUI.add(cbFontFamily, "12, 2, fill, default");

    JLabel lblFontSize = new JLabel(BUNDLE.getString("Settings.fontsize")); //$NON-NLS-1$
    panelUI.add(lblFontSize, "10, 4, right, default");

    cbFontSize = new JComboBox(DEFAULT_FONT_SIZES);
    cbFontSize.setSelectedItem(Globals.settings.getFontSize());
    index = cbFontSize.getSelectedIndex();
    if (index < 0) {
        cbFontSize.setSelectedIndex(0);
    }

    panelUI.add(cbFontSize, "12, 4, fill, default");

    JPanel panel = new JPanel();
    panelUI.add(panel, "2, 6, 5, 1, fill, fill");
    panel.setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
            ColumnSpec.decode("100dlu"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), },
            new RowSpec[] { FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, }));

    JLabel lblMissingTranslation = new JLabel(BUNDLE.getString("tmm.helptranslate"));
    panel.add(lblMissingTranslation, "1, 1, 5, 1");

    lblLinkTransifex = new LinkLabel("https://www.transifex.com/projects/p/tinymediamanager/");
    panel.add(lblLinkTransifex, "1, 3, 5, 1");
    lblLinkTransifex.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                TmmUIHelper.browseUrl(lblLinkTransifex.getNormalText());
            } catch (Exception e) {
                LOGGER.error(e.getMessage());
                MessageManager.instance
                        .pushMessage(new Message(MessageLevel.ERROR, lblLinkTransifex.getNormalText(),
                                "message.erroropenurl", new String[] { ":", e.getLocalizedMessage() }));//$NON-NLS-2$
            }
        }
    });

    tpFontHint = new JTextPane();
    tpFontHint.setOpaque(false);
    TmmFontHelper.changeFont(tpFontHint, 0.833);
    tpFontHint.setText(BUNDLE.getString("Settings.fonts.hint")); //$NON-NLS-1$
    panelUI.add(tpFontHint, "10, 6, 5, 1");

    lblLanguageHint = new JLabel("");
    TmmFontHelper.changeFont(lblLanguageHint, Font.BOLD);
    panelUI.add(lblLanguageHint, "2, 8, 5, 1");

    lblFontChangeHint = new JLabel("");
    TmmFontHelper.changeFont(lblFontChangeHint, Font.BOLD);
    panelUI.add(lblFontChangeHint, "10, 8, 5, 1");

    JPanel panelMemory = new JPanel();
    panelMemory.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.memoryborder"), //$NON-NLS-1$
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    add(panelMemory, "2, 4, fill, fill");
    panelMemory.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("250px:grow(4)"),
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(20dlu;default)"),
                    ColumnSpec.decode("left:default:grow(5)"), },
            new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                    RowSpec.decode("default:grow"), FormFactory.RELATED_GAP_ROWSPEC, }));

    JLabel lblMemoryT = new JLabel(BUNDLE.getString("Settings.memory")); //$NON-NLS-1$
    panelMemory.add(lblMemoryT, "2, 1");

    sliderMemory = new JSlider();
    sliderMemory.setPaintLabels(true);
    sliderMemory.setPaintTicks(true);
    sliderMemory.setSnapToTicks(true);
    sliderMemory.setMajorTickSpacing(512);
    sliderMemory.setMinorTickSpacing(128);
    sliderMemory.setMinimum(256);
    sliderMemory.setMaximum(1536);
    sliderMemory.setValue(512);
    panelMemory.add(sliderMemory, "4, 1, fill, default");

    lblMemory = new JLabel("512"); //$NON-NLS-1$
    panelMemory.add(lblMemory, "6, 1, right, default");

    JLabel lblMb = new JLabel("MB");
    panelMemory.add(lblMb, "7, 1, left, default");

    tpMemoryHint = new JTextPane();
    tpMemoryHint.setOpaque(false);
    tpMemoryHint.setText(BUNDLE.getString("Settings.memory.hint")); //$NON-NLS-1$
    TmmFontHelper.changeFont(tpMemoryHint, 0.833);
    panelMemory.add(tpMemoryHint, "2, 3, 6, 1, fill, fill");

    JPanel panelProxySettings = new JPanel();
    panelProxySettings.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.proxy"), //$NON-NLS-1$
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    add(panelProxySettings, "4, 4, fill, fill");
    panelProxySettings.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), },
            new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.RELATED_GAP_ROWSPEC, }));

    JLabel lblProxyHost = new JLabel(BUNDLE.getString("Settings.proxyhost")); //$NON-NLS-1$
    panelProxySettings.add(lblProxyHost, "2, 2, right, default");

    tfProxyHost = new JTextField();
    lblProxyHost.setLabelFor(tfProxyHost);
    panelProxySettings.add(tfProxyHost, "4, 2, fill, default");
    tfProxyHost.setColumns(10);

    JLabel lblProxyPort = new JLabel(BUNDLE.getString("Settings.proxyport")); //$NON-NLS-1$
    panelProxySettings.add(lblProxyPort, "2, 4, right, default");

    tfProxyPort = new JTextField();
    lblProxyPort.setLabelFor(tfProxyPort);
    panelProxySettings.add(tfProxyPort, "4, 4, fill, default");
    tfProxyPort.setColumns(10);

    JLabel lblProxyUser = new JLabel(BUNDLE.getString("Settings.proxyuser")); //$NON-NLS-1$
    panelProxySettings.add(lblProxyUser, "2, 6, right, default");

    tfProxyUsername = new JTextField();
    lblProxyUser.setLabelFor(tfProxyUsername);
    panelProxySettings.add(tfProxyUsername, "4, 6, fill, default");
    tfProxyUsername.setColumns(10);

    JLabel lblProxyPassword = new JLabel(BUNDLE.getString("Settings.proxypass")); //$NON-NLS-1$
    panelProxySettings.add(lblProxyPassword, "2, 8, right, default");

    tfProxyPassword = new JPasswordField();
    lblProxyPassword.setLabelFor(tfProxyPassword);
    panelProxySettings.add(tfProxyPassword, "4, 8, fill, default");

    JPanel panelMediaPlayer = new JPanel();
    panelMediaPlayer.setBorder(
            new TitledBorder(null, "MediaPlayer", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    add(panelMediaPlayer, "2, 6, fill, fill");
    panelMediaPlayer.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, }));

    tpMediaPlayer = new JTextPane();
    tpMediaPlayer.setOpaque(false);
    TmmFontHelper.changeFont(tpMediaPlayer, 0.833);
    tpMediaPlayer.setText(BUNDLE.getString("Settings.mediaplayer.hint")); //$NON-NLS-1$
    panelMediaPlayer.add(tpMediaPlayer, "2, 2, 3, 1, fill, fill");

    tfMediaPlayer = new JTextField();
    panelMediaPlayer.add(tfMediaPlayer, "2, 4, fill, default");
    tfMediaPlayer.setColumns(10);

    btnSearchMediaPlayer = new JButton(BUNDLE.getString("Button.chooseplayer")); //$NON-NLS-1$
    btnSearchMediaPlayer.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            Path file = TmmUIHelper.selectFile(BUNDLE.getString("Button.chooseplayer")); //$NON-NLS-1$
            if (file != null && Utils.isRegularFile(file) || Platform.isMac()) {
                tfMediaPlayer.setText(file.toAbsolutePath().toString());
            }
        }
    });
    panelMediaPlayer.add(btnSearchMediaPlayer, "4, 4");

    JPanel panelCache = new JPanel();
    panelCache.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.cache"), TitledBorder.LEADING, //$NON-NLS-1$
            TitledBorder.TOP, null, null));
    add(panelCache, "4, 6, fill, fill");
    panelCache.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, }));

    chckbxImageCache = new JCheckBox(BUNDLE.getString("Settings.imagecache"));//$NON-NLS-1$
    panelCache.add(chckbxImageCache, "2, 2, 3, 1");

    JLabel lblImageCacheQuality = new JLabel(BUNDLE.getString("Settings.imagecachetype"));//$NON-NLS-1$
    panelCache.add(lblImageCacheQuality, "2, 4, right, default");

    cbImageCacheQuality = new JComboBox(ImageCache.CacheType.values());
    panelCache.add(cbImageCacheQuality, "4, 4, fill, default");

    JPanel panelAnalytics = new JPanel();
    panelAnalytics.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.analytics.border"), //$NON-NLS-1$
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    add(panelAnalytics, "2, 8, fill, fill");
    panelAnalytics.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LINE_GAP_ROWSPEC, }));

    chckbxAnalytics = new JCheckBox(BUNDLE.getString("Settings.analytics"));//$NON-NLS-1$
    panelAnalytics.add(chckbxAnalytics, "2, 2");

    JTextPane tpAnalyticsDescription = new JTextPane();
    tpAnalyticsDescription.setText(BUNDLE.getString("Settings.analytics.desc"));//$NON-NLS-1$
    tpAnalyticsDescription.setOpaque(false);
    panelAnalytics.add(tpAnalyticsDescription, "2, 4, fill, fill");

    JPanel panelMisc = new JPanel();
    panelMisc.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.misc"), TitledBorder.LEADING, //$NON-NLS-1$
            TitledBorder.TOP, null, null));
    add(panelMisc, "4, 8, fill, fill");
    panelMisc.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormFactory.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.RELATED_GAP_ROWSPEC, }));

    chckbxDeleteTrash = new JCheckBox(BUNDLE.getString("Settings.deletetrash"));
    panelMisc.add(chckbxDeleteTrash, "2, 2, 3, 1");

    initDataBindings();

    initMemorySlider();

    // listen to changes of the combo box
    ItemListener listener = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            checkChanges();
        }
    };

    cbLanguage.addItemListener(listener);
    cbFontSize.addItemListener(listener);
    cbFontFamily.addItemListener(listener);
}

From source file:org.tinymediamanager.ui.movies.settings.MovieImageSettingsPanel.java

/**
 * Instantiates a new movie image settings panel.
 *///from ww  w  .  java 2s  . co  m
public MovieImageSettingsPanel() {
    // data init
    List<String> enabledArtworkProviders = settings.getMovieArtworkScrapers();
    int selectedIndex = -1;
    int counter = 0;
    for (MediaScraper scraper : MovieList.getInstance().getAvailableArtworkScrapers()) {
        ArtworkScraper artworkScraper = new ArtworkScraper(scraper);
        if (enabledArtworkProviders.contains(artworkScraper.getScraperId())) {
            artworkScraper.active = true;
            if (selectedIndex < 0) {
                selectedIndex = counter;
            }
        }
        scrapers.add(artworkScraper);
        counter++;
    }

    // init UI
    setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, }));

    JPanel panelMovieImages = new JPanel();
    panelMovieImages.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.poster"), TitledBorder.LEADING, //$NON-NLS-1$
            TitledBorder.TOP, null, null));
    add(panelMovieImages, "2, 2, default, fill");
    panelMovieImages.setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC,
            FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
            FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("200dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("100dlu:grow"),
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));

    scrollPaneScraperDetails = new JScrollPane();
    scrollPaneScraperDetails.setBorder(null);
    scrollPaneScraperDetails.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    panelMovieImages.add(scrollPaneScraperDetails, "6, 1, 1, 7, fill, fill");

    panelScraperDetails = new ScrollablePanel();
    scrollPaneScraperDetails.setViewportView(panelScraperDetails);
    panelScraperDetails
            .setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow"), }, new RowSpec[] {
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));

    {
        // add a CSS rule to force body tags to use the default label font
        // instead of the value in javax.swing.text.html.default.csss
        Font font = UIManager.getFont("Label.font");
        String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize()
                + "pt; }";
        tpScraperDescription = new JTextPane();
        tpScraperDescription.setOpaque(false);
        tpScraperDescription.setEditorKit(new HTMLEditorKit());
        ((HTMLDocument) tpScraperDescription.getDocument()).getStyleSheet().addRule(bodyRule);
        panelScraperDetails.add(tpScraperDescription, "1, 1, fill, top");
    }
    panelScraperOptions = new JPanel();
    panelScraperOptions.setLayout(new FlowLayout(FlowLayout.LEFT));
    panelScraperDetails.add(panelScraperOptions, "1, 3, fill, top");

    scrollPaneScraper = new JScrollPane();
    panelMovieImages.add(scrollPaneScraper, "2, 2, 3, 1, fill, fill");

    tableScraper = new JTable();
    tableScraper.setRowHeight(29);
    scrollPaneScraper.setViewportView(tableScraper);

    JSeparator separator = new JSeparator();
    panelMovieImages.add(separator, "2, 3, 3, 1");

    JLabel lblImageTmdbPosterSize = new JLabel(BUNDLE.getString("image.poster.size"));
    panelMovieImages.add(lblImageTmdbPosterSize, "2, 5");

    cbImagePosterSize = new JComboBox(PosterSizes.values());
    panelMovieImages.add(cbImagePosterSize, "4, 5");

    JLabel lblImageTmdbFanartSize = new JLabel(BUNDLE.getString("image.fanart.size"));
    panelMovieImages.add(lblImageTmdbFanartSize, "2, 7");

    cbImageFanartSize = new JComboBox(FanartSizes.values());
    panelMovieImages.add(cbImageFanartSize, "4, 7");

    separator = new JSeparator();
    panelMovieImages.add(separator, "2, 9, 5, 1");

    panelFileNaming = new JPanel();
    panelMovieImages.add(panelFileNaming, "2, 11, 5, 1, fill, fill");
    panelFileNaming.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("default:grow"), },
            new RowSpec[] { FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));

    JLabel lblPosterFilename = new JLabel(BUNDLE.getString("image.poster.naming"));
    panelFileNaming.add(lblPosterFilename, "1, 1");

    cbMoviePosterFilename7 = new JCheckBox("<dynamic>.ext");
    panelFileNaming.add(cbMoviePosterFilename7, "3, 1");

    cbMoviePosterFilename4 = new JCheckBox("poster.ext");
    panelFileNaming.add(cbMoviePosterFilename4, "5, 1");

    cbMoviePosterFilename2 = new JCheckBox("movie.ext");
    panelFileNaming.add(cbMoviePosterFilename2, "7, 1");

    cbMoviePosterFilename8 = new JCheckBox("<dynamic>-poster.ext");
    panelFileNaming.add(cbMoviePosterFilename8, "9, 1");

    cbMoviePosterFilename6 = new JCheckBox("folder.ext");
    panelFileNaming.add(cbMoviePosterFilename6, "11, 1");

    JLabel lblFanartFileNaming = new JLabel(BUNDLE.getString("image.fanart.naming"));
    panelFileNaming.add(lblFanartFileNaming, "1, 3");

    cbMovieFanartFilename1 = new JCheckBox("<dynamic>-fanart.ext");
    panelFileNaming.add(cbMovieFanartFilename1, "3, 3");

    cbMovieFanartFilename3 = new JCheckBox("<dynamic>.fanart.ext");
    panelFileNaming.add(cbMovieFanartFilename3, "5, 3");

    cbMovieFanartFilename2 = new JCheckBox("fanart.ext");
    panelFileNaming.add(cbMovieFanartFilename2, "7, 3");

    tpFileNamingHint = new JTextPane();
    panelFileNaming.add(tpFileNamingHint, "1, 5, 11, 1, fill, fill");
    tpFileNamingHint.setText(BUNDLE.getString("Settings.naming.info")); //$NON-NLS-1$
    tpFileNamingHint.setBackground(UIManager.getColor("Panel.background"));
    TmmFontHelper.changeFont(tpFileNamingHint, 0.833);

    panelExtraArtwork = new JPanel();
    panelExtraArtwork.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.extraartwork"),
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    add(panelExtraArtwork, "2, 4, default, fill");
    panelExtraArtwork.setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC,
            ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
            FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
            ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
            FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, }));

    chckbxBanner = new JCheckBox(BUNDLE.getString("mediafiletype.banner"));
    panelExtraArtwork.add(chckbxBanner, "2, 2");

    chckbxClearArt = new JCheckBox(BUNDLE.getString("mediafiletype.clearart"));
    panelExtraArtwork.add(chckbxClearArt, "4, 2");

    chckbxThumb = new JCheckBox(BUNDLE.getString("mediafiletype.thumb"));
    panelExtraArtwork.add(chckbxThumb, "6, 2");

    chckbxLogo = new JCheckBox(BUNDLE.getString("mediafiletype.logo"));
    panelExtraArtwork.add(chckbxLogo, "8, 2");

    chckbxDiscArt = new JCheckBox(BUNDLE.getString("mediafiletype.discart"));
    panelExtraArtwork.add(chckbxDiscArt, "10, 2");

    separator = new JSeparator();
    panelExtraArtwork.add(separator, "2, 4, 9, 1");

    chckbxEnableExtrathumbs = new JCheckBox(BUNDLE.getString("Settings.enable.extrathumbs"));
    panelExtraArtwork.add(chckbxEnableExtrathumbs, "2, 6, 3, 1");

    chckbxResizeExtrathumbsTo = new JCheckBox(BUNDLE.getString("Settings.resize.extrathumbs"));
    panelExtraArtwork.add(chckbxResizeExtrathumbsTo, "6, 6, 3, 1");

    spExtrathumbWidth = new JSpinner();
    panelExtraArtwork.add(spExtrathumbWidth, "10, 6");
    spExtrathumbWidth.setPreferredSize(new Dimension(49, 20));

    lblDownload = new JLabel(BUNDLE.getString("Settings.amount.autodownload"));
    panelExtraArtwork.add(lblDownload, "2, 8, 7, 1, right, default");

    spDownloadCountExtrathumbs = new JSpinner();
    panelExtraArtwork.add(spDownloadCountExtrathumbs, "10, 8");
    spDownloadCountExtrathumbs.setPreferredSize(new Dimension(49, 20));

    chckbxEnableExtrafanart = new JCheckBox(BUNDLE.getString("Settings.enable.extrafanart"));
    panelExtraArtwork.add(chckbxEnableExtrafanart, "2, 10, 9, 1");

    lblDownloadCount = new JLabel(BUNDLE.getString("Settings.amount.autodownload"));
    panelExtraArtwork.add(lblDownloadCount, "2, 12, 7, 1, right, default");

    spDownloadCountExtrafanart = new JSpinner();
    panelExtraArtwork.add(spDownloadCountExtrafanart, "10, 12");
    spDownloadCountExtrafanart.setPreferredSize(new Dimension(49, 20));

    separator = new JSeparator();
    panelExtraArtwork.add(separator, "2, 14, 9, 1");

    cbActorImages = new JCheckBox(BUNDLE.getString("Settings.actor.download"));
    panelExtraArtwork.add(cbActorImages, "2, 16, 9, 1");

    separator = new JSeparator();
    panelExtraArtwork.add(separator, "2, 18, 9, 1");

    chckbxMovieSetArtwork = new JCheckBox(BUNDLE.getString("Settings.movieset.store.movie")); //$NON-NLS-1$
    panelExtraArtwork.add(chckbxMovieSetArtwork, "2, 20, 9, 1");

    chckbxStoreMoviesetArtwork = new JCheckBox(BUNDLE.getString("Settings.movieset.store")); //$NON-NLS-1$
    panelExtraArtwork.add(chckbxStoreMoviesetArtwork, "2, 22, 9, 1");

    lblFoldername = new JLabel(BUNDLE.getString("Settings.movieset.foldername")); //$NON-NLS-1$
    panelExtraArtwork.add(lblFoldername, "2, 24, 3, 1, right, default");

    tfMovieSetArtworkFolder = new JTextField();
    panelExtraArtwork.add(tfMovieSetArtworkFolder, "6, 24, 3, 1");
    tfMovieSetArtworkFolder.setColumns(10);

    btnSelectFolder = new JButton(BUNDLE.getString("Settings.movieset.buttonselect")); //$NON-NLS-1$
    panelExtraArtwork.add(btnSelectFolder, "10, 24");
    btnSelectFolder.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Path file = TmmUIHelper.selectDirectory(BUNDLE.getString("Settings.movieset.folderchooser")); //$NON-NLS-1$
            if (file != null && Files.isDirectory(file)) {
                tfMovieSetArtworkFolder.setText(file.toAbsolutePath().toString());
            }
        }
    });

    initDataBindings();

    // poster filenames
    List<MoviePosterNaming> moviePosterFilenames = settings.getMoviePosterFilenames();
    if (moviePosterFilenames.contains(MoviePosterNaming.MOVIE_JPG)) {
        cbMoviePosterFilename2.setSelected(true);
    }
    if (moviePosterFilenames.contains(MoviePosterNaming.POSTER_JPG)) {
        cbMoviePosterFilename4.setSelected(true);
    }
    if (moviePosterFilenames.contains(MoviePosterNaming.FOLDER_JPG)) {
        cbMoviePosterFilename6.setSelected(true);
    }
    if (moviePosterFilenames.contains(MoviePosterNaming.FILENAME_JPG)) {
        cbMoviePosterFilename7.setSelected(true);
    }
    if (moviePosterFilenames.contains(MoviePosterNaming.FILENAME_POSTER_JPG)) {
        cbMoviePosterFilename8.setSelected(true);
    }

    // fanart filenames
    List<MovieFanartNaming> movieFanartFilenames = settings.getMovieFanartFilenames();
    if (movieFanartFilenames.contains(MovieFanartNaming.FILENAME_FANART_JPG)) {
        cbMovieFanartFilename1.setSelected(true);
    }
    if (movieFanartFilenames.contains(MovieFanartNaming.FANART_JPG)) {
        cbMovieFanartFilename2.setSelected(true);
    }
    if (movieFanartFilenames.contains(MovieFanartNaming.FILENAME_FANART2_JPG)) {
        cbMovieFanartFilename3.setSelected(true);
    }

    // listen to changes of the checkboxes
    ItemListener listener = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            checkChanges();
        }
    };
    cbMovieFanartFilename2.addItemListener(listener);
    cbMovieFanartFilename3.addItemListener(listener);

    cbMovieFanartFilename1.addItemListener(listener);
    cbMoviePosterFilename2.addItemListener(listener);
    cbMoviePosterFilename4.addItemListener(listener);
    cbMoviePosterFilename7.addItemListener(listener);
    cbMoviePosterFilename8.addItemListener(listener);
    cbMoviePosterFilename6.addItemListener(listener);

    // adjust table columns
    // Checkbox and Logo shall have minimal width
    TableColumnResizer.setMaxWidthForColumn(tableScraper, 0, 2);
    TableColumnResizer.setMaxWidthForColumn(tableScraper, 1, 2);
    TableColumnResizer.adjustColumnPreferredWidths(tableScraper, 5);

    tableScraper.getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent arg0) {
            // click on the checkbox
            if (arg0.getColumn() == 0) {
                int row = arg0.getFirstRow();
                ArtworkScraper changedScraper = scrapers.get(row);
                if (changedScraper.active) {
                    settings.addMovieArtworkScraper(changedScraper.getScraperId());
                } else {
                    settings.removeMovieArtworkScraper(changedScraper.getScraperId());
                }
            }
        }
    });

    // implement selection listener to load settings
    tableScraper.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            int index = tableScraper.convertRowIndexToModel(tableScraper.getSelectedRow());
            if (index > -1) {
                panelScraperOptions.removeAll();
                if (scrapers.get(index).getMediaProvider().getProviderInfo().getConfig().hasConfig()) {
                    panelScraperOptions
                            .add(new MediaScraperConfigurationPanel(scrapers.get(index).getMediaProvider()));
                }
                panelScraperOptions.revalidate();
            }
        }
    });

    // select default artwork scraper
    if (selectedIndex < 0) {
        selectedIndex = 0;
    }
    if (counter > 0) {
        tableScraper.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex);
    }
}

From source file:org.tinymediamanager.ui.tvshows.settings.TvShowScraperSettingsPanel.java

/**
 * Instantiates a new movie scraper settings panel.
 *//*from ww w .j  a  v  a2  s .  co m*/
public TvShowScraperSettingsPanel() {
    // data init
    MediaScraper defaultMediaScraper = TvShowList.getInstance().getDefaultMediaScraper();
    int selectedIndex = 0;
    int counter = 0;
    for (MediaScraper scraper : TvShowList.getInstance().getAvailableMediaScrapers()) {
        TvShowScraper tvShowScraper = new TvShowScraper(scraper);
        if (scraper.equals(defaultMediaScraper)) {
            tvShowScraper.defaultScraper = true;
            selectedIndex = counter;
        }
        scrapers.add(tvShowScraper);
        counter++;
    }
    List<String> enabledArtworkProviders = settings.getTvShowArtworkScrapers();
    int artworkSelectedIndex = -1;
    int counterAW = 0;
    for (MediaScraper scraper : TvShowList.getInstance().getAvailableArtworkScrapers()) {
        ArtworkScraper artworkScraper = new ArtworkScraper(scraper);
        if (enabledArtworkProviders.contains(artworkScraper.getScraperId())) {
            artworkScraper.active = true;
            if (artworkSelectedIndex < 0) {
                artworkSelectedIndex = counterAW;
            }
        }
        artworkScrapers.add(artworkScraper);
        counterAW++;
    }
    // UI init
    setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, }));
    JPanel panelTvShowScrapers = new JPanel();
    panelTvShowScrapers.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"),
            BUNDLE.getString("scraper.metadata.defaults"), TitledBorder.LEADING, TitledBorder.TOP, null, null)); // $NON-NLS-1$
    add(panelTvShowScrapers, "2, 2, fill, top");
    panelTvShowScrapers.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("default:grow"), },
            new RowSpec[] { FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, RowSpec.decode("100dlu:grow"),
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, }));

    scrollPaneScraper = new JScrollPane();
    panelTvShowScrapers.add(scrollPaneScraper, "1, 2, 3, 1, fill, fill");

    tableScraper = new JTable();
    tableScraper.setRowHeight(29);
    scrollPaneScraper.setViewportView(tableScraper);

    scrollPaneScraperDetails = new JScrollPane();
    scrollPaneScraperDetails.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPaneScraperDetails.setBorder(null);
    panelTvShowScrapers.add(scrollPaneScraperDetails, "5, 2, fill, fill");

    panelScraperDetails = new ScrollablePanel();
    scrollPaneScraperDetails.setViewportView(panelScraperDetails);
    panelScraperDetails.setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("200dlu:grow"), },
            new RowSpec[] { RowSpec.decode("default:grow"), FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, }));

    // add a CSS rule to force body tags to use the default label font
    // instead of the value in javax.swing.text.html.default.csss
    Font font = UIManager.getFont("Label.font");
    String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize()
            + "pt; }";
    tpScraperDescription = new JTextPane();
    tpScraperDescription.setOpaque(false);
    tpScraperDescription.setEditorKit(new HTMLEditorKit());
    ((HTMLDocument) tpScraperDescription.getDocument()).getStyleSheet().addRule(bodyRule);
    panelScraperDetails.add(tpScraperDescription, "1, 1, fill, top");
    panelScraperOptions = new JPanel();
    panelScraperOptions.setLayout(new FlowLayout(FlowLayout.LEFT));
    panelScraperDetails.add(panelScraperOptions, "1, 3, fill, top");

    JSeparator separator = new JSeparator();
    panelTvShowScrapers.add(separator, "1, 4, 5, 1");

    JLabel lblScraperLanguage = new JLabel(BUNDLE.getString("Settings.preferredLanguage")); //$NON-NLS-1$
    panelTvShowScrapers.add(lblScraperLanguage, "1, 6, right, default");

    cbScraperTmdbLanguage = new JComboBox(MediaLanguages.values());
    panelTvShowScrapers.add(cbScraperTmdbLanguage, "3, 6");

    JLabel lblCountry = new JLabel(BUNDLE.getString("Settings.certificationCountry")); //$NON-NLS-1$
    panelTvShowScrapers.add(lblCountry, "1, 8, right, default");

    cbCountry = new JComboBox(CountryCode.values());
    panelTvShowScrapers.add(cbCountry, "3, 8, fill, default");

    btnGroupThumbFilenaming = new ButtonGroup();

    panelArtworkScrapers = new JPanel();
    panelArtworkScrapers.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.images"), //$NON-NLS-1$
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    add(panelArtworkScrapers, "2, 4, fill, fill");
    panelArtworkScrapers.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, RowSpec.decode("80dlu:grow"),
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, }));

    scrollPaneArtworkScraper = new JScrollPane();
    panelArtworkScrapers.add(scrollPaneArtworkScraper, "2, 2, fill, fill");

    tableArtworkScraper = new JTable();
    tableArtworkScraper.setRowHeight(29);
    scrollPaneArtworkScraper.setViewportView(tableArtworkScraper);

    scrollPaneArtworkScraperDetails = new JScrollPane();
    scrollPaneArtworkScraperDetails.setBorder(null);
    panelArtworkScrapers.add(scrollPaneArtworkScraperDetails, "4, 2, fill, fill");

    panelArtworkScraperDetails = new JPanel();
    scrollPaneArtworkScraperDetails.setViewportView(panelArtworkScraperDetails);
    panelArtworkScraperDetails.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("200dlu:grow"), },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), }));

    tpArtworkScraperDescription = new JTextPane();
    tpArtworkScraperDescription.setEditorKit(new HTMLEditorKit());
    ((HTMLDocument) tpArtworkScraperDescription.getDocument()).getStyleSheet().addRule(bodyRule);
    tpArtworkScraperDescription.setOpaque(false);
    panelArtworkScraperDetails.add(tpArtworkScraperDescription, "2, 2, fill, fill");

    panelArtworkScraperOptions = new JPanel();
    panelArtworkScraperOptions.setLayout(new FlowLayout(FlowLayout.LEFT));
    panelArtworkScraperDetails.add(panelArtworkScraperOptions, "2, 4, fill, fill");

    separator = new JSeparator();
    panelArtworkScrapers.add(separator, "2, 4, 3, 1");

    panelImages = new JPanel();
    panelArtworkScrapers.add(panelImages, "2, 6, 3, 1, fill, fill");
    panelImages.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), },
            new RowSpec[] { RowSpec.decode("23px"), }));

    lblNewLabel = new JLabel(BUNDLE.getString("image.thumb.naming"));
    panelImages.add(lblNewLabel, "1, 1, left, center");
    rdbtnThumbWithPostfix = new JRadioButton("<dynamic>-thumb.ext");
    panelImages.add(rdbtnThumbWithPostfix, "3, 1, fill, top");
    btnGroupThumbFilenaming.add(rdbtnThumbWithPostfix);
    rdbtnThumbTbn = new JRadioButton("<dynamic>.tbn");
    btnGroupThumbFilenaming.add(rdbtnThumbTbn);
    rdbtnThumbWoPostfix = new JRadioButton("<dynamic>.ext");
    panelImages.add(rdbtnThumbWoPostfix, "5, 1, fill, top");
    btnGroupThumbFilenaming.add(rdbtnThumbWoPostfix);
    panelImages.add(rdbtnThumbTbn, "7, 1");

    panelScraperMetadataContainer = new JPanel();
    panelScraperMetadataContainer.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"),
            BUNDLE.getString("scraper.metadata.defaults"), TitledBorder.LEADING, TitledBorder.TOP, null, //$NON-NLS-1$
            new Color(51, 51, 51)));
    add(panelScraperMetadataContainer, "2, 6, fill, top");
    panelScraperMetadataContainer.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), },
            new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                    FormFactory.DEFAULT_ROWSPEC, }));

    panelScraperMetadata = new TvShowScraperMetadataPanel(
            Settings.getInstance().getTvShowScraperMetadataConfig());
    panelScraperMetadataContainer.add(panelScraperMetadata, "1, 1, 2, 1, fill, default");

    chckbxAutomaticallyScrapeImages = new JCheckBox(BUNDLE.getString("Settings.default.autoscrape")); //$NON-NLS-1$
    panelScraperMetadataContainer.add(chckbxAutomaticallyScrapeImages, "2, 3");

    initDataBindings();

    {
        // adjust table columns
        // Checkbox and Logo shall have minimal width
        TableColumnResizer.setMaxWidthForColumn(tableScraper, 0, 2);
        TableColumnResizer.setMaxWidthForColumn(tableScraper, 1, 2);
        TableColumnResizer.adjustColumnPreferredWidths(tableScraper, 5);

        TableColumnResizer.setMaxWidthForColumn(tableArtworkScraper, 0, 2);
        TableColumnResizer.setMaxWidthForColumn(tableArtworkScraper, 1, 2);
        TableColumnResizer.adjustColumnPreferredWidths(tableArtworkScraper, 5);

        // implement listener to simulate button group
        tableScraper.getModel().addTableModelListener(new TableModelListener() {
            @Override
            public void tableChanged(TableModelEvent arg0) {
                // click on the checkbox
                if (arg0.getColumn() == 0) {
                    int row = arg0.getFirstRow();
                    TvShowScraper changedScraper = scrapers.get(row);
                    // if flag inNFO was changed, change all other trailers flags
                    if (changedScraper.getDefaultScraper()) {
                        settings.setTvShowScraper(changedScraper.getScraperId());
                        for (TvShowScraper scraper : scrapers) {
                            if (scraper != changedScraper) {
                                scraper.setDefaultScraper(Boolean.FALSE);
                            }
                        }
                    }
                }
            }
        });

        // implement selection listener to load settings
        tableScraper.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                int index = tableScraper.convertRowIndexToModel(tableScraper.getSelectedRow());
                if (index > -1) {
                    panelScraperOptions.removeAll();
                    if (scrapers.get(index).getMediaProvider().getProviderInfo().getConfig().hasConfig()) {
                        panelScraperOptions.add(
                                new MediaScraperConfigurationPanel(scrapers.get(index).getMediaProvider()));
                    }
                    panelScraperOptions.revalidate();
                }
            }
        });

        tableArtworkScraper.getModel().addTableModelListener(new TableModelListener() {
            @Override
            public void tableChanged(TableModelEvent arg0) {
                // click on the checkbox
                if (arg0.getColumn() == 0) {
                    int row = arg0.getFirstRow();
                    ArtworkScraper changedScraper = artworkScrapers.get(row);
                    if (changedScraper.active) {
                        settings.addTvShowArtworkScraper(changedScraper.getScraperId());
                    } else {
                        settings.removeTvShowArtworkScraper(changedScraper.getScraperId());
                    }
                }
            }
        });
        // implement selection listener to load settings
        tableArtworkScraper.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                int index = tableArtworkScraper.convertRowIndexToModel(tableArtworkScraper.getSelectedRow());
                if (index > -1) {
                    panelArtworkScraperOptions.removeAll();
                    if (artworkScrapers.get(index).getMediaProvider().getProviderInfo().getConfig()
                            .hasConfig()) {
                        panelArtworkScraperOptions.add(new MediaScraperConfigurationPanel(
                                artworkScrapers.get(index).getMediaProvider()));
                    }
                    panelArtworkScraperOptions.revalidate();
                }
            }
        });

        // select default TV show scraper
        if (counter > 0) {
            tableScraper.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex);
        }

        // select default artwork scraper
        if (counterAW > 0) {
            tableArtworkScraper.getSelectionModel().setSelectionInterval(artworkSelectedIndex,
                    artworkSelectedIndex);
        }

        ItemListener itemListener = new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                checkChanges();
            }
        };

        rdbtnThumbWoPostfix.addItemListener(itemListener);
        rdbtnThumbWithPostfix.addItemListener(itemListener);
        rdbtnThumbTbn.addItemListener(itemListener);

        switch (settings.getTvShowEpisodeThumbFilename()) {
        case FILENAME_THUMB_POSTFIX:
            rdbtnThumbWithPostfix.setSelected(true);
            break;

        case FILENAME_THUMB:
            rdbtnThumbWoPostfix.setSelected(true);
            break;

        case FILENAME_THUMB_TBN:
            rdbtnThumbTbn.setSelected(true);
            break;

        default:
            break;
        }
    }
}

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

/**
 * This method initializes jComboBox1// ww  w.java2  s . c o m
 * 
 * @return javax.swing.JComboBox
 */
private JComboBox getJComboBoxStrokeOpacity() {
    if (jComboBoxStrokeOpacity == null) {
        jComboBoxStrokeOpacity = new OpacityJComboBox();
        jComboBoxStrokeOpacity.setModel(new DefaultComboBoxModel(OPACITY_VALUES));

        if (symbolizer.getStroke() != null) {
            // We have a stroke, so now we need opacity

            if (symbolizer.getStroke().getOpacity() == null) {
                symbolizer.getStroke().setOpacity(ASUtil.ff2.literal("1."));
            }

            ASUtil.selectOrInsert(jComboBoxStrokeOpacity, symbolizer.getStroke().getOpacity());
        }

        else {
            jComboBoxStrokeOpacity.setEnabled(false);
        }

        jComboBoxStrokeOpacity.addItemListener(new ItemListener() {

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

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

                    PolygonSymbolEditGUI.this.firePropertyChange(PROPERTY_UPDATED, null, null);
                }
            }

        });

        SwingUtil.addMouseWheelForCombobox(jComboBoxStrokeOpacity);
    }
    return jComboBoxStrokeOpacity;
}

From source file:davmail.ui.SettingsFrame.java

protected JPanel getSmartCardPanel() {
    JPanel clientKeystorePanel = new JPanel(new GridLayout(2, 1));
    clientKeystorePanel.setLayout(new BoxLayout(clientKeystorePanel, BoxLayout.Y_AXIS));
    clientKeystorePanel//  w ww  . j  a v a 2  s.c  o  m
            .setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_CLIENT_CERTIFICATE")));

    clientKeystoreTypeCombo = new JComboBox(new String[] { "PKCS11", "JKS", "PKCS12" });
    clientKeystoreTypeCombo.setSelectedItem(Settings.getProperty("davmail.ssl.clientKeystoreType"));
    clientKeystoreFileField = new JTextField(Settings.getProperty("davmail.ssl.clientKeystoreFile"), 17);
    clientKeystorePassField = new JPasswordField(Settings.getProperty("davmail.ssl.clientKeystorePass"), 15);

    pkcs11LibraryField = new JTextField(Settings.getProperty("davmail.ssl.pkcs11Library"), 17);
    pkcs11ConfigField = new JTextArea(2, 17);
    pkcs11ConfigField.setText(Settings.getProperty("davmail.ssl.pkcs11Config"));
    pkcs11ConfigField.setBorder(pkcs11LibraryField.getBorder());
    pkcs11ConfigField.setFont(pkcs11LibraryField.getFont());

    JPanel clientKeystoreTypePanel = new JPanel(new GridLayout(1, 2));
    addSettingComponent(clientKeystoreTypePanel, BundleMessage.format("UI_CLIENT_KEY_STORE_TYPE"),
            clientKeystoreTypeCombo, BundleMessage.format("UI_CLIENT_KEY_STORE_TYPE_HELP"));
    clientKeystorePanel.add(clientKeystoreTypePanel);

    final JPanel cardPanel = new JPanel(new CardLayout());
    clientKeystorePanel.add(cardPanel);

    JPanel clientKeystoreFilePanel = new JPanel(new GridLayout(2, 2));
    addSettingComponent(clientKeystoreFilePanel, BundleMessage.format("UI_CLIENT_KEY_STORE"),
            clientKeystoreFileField, BundleMessage.format("UI_CLIENT_KEY_STORE_HELP"));
    addSettingComponent(clientKeystoreFilePanel, BundleMessage.format("UI_CLIENT_KEY_STORE_PASSWORD"),
            clientKeystorePassField, BundleMessage.format("UI_CLIENT_KEY_STORE_PASSWORD_HELP"));
    cardPanel.add(clientKeystoreFilePanel, "FILE");

    JPanel pkcs11Panel = new JPanel(new GridLayout(2, 2));
    addSettingComponent(pkcs11Panel, BundleMessage.format("UI_PKCS11_LIBRARY"), pkcs11LibraryField,
            BundleMessage.format("UI_PKCS11_LIBRARY_HELP"));
    addSettingComponent(pkcs11Panel, BundleMessage.format("UI_PKCS11_CONFIG"), pkcs11ConfigField,
            BundleMessage.format("UI_PKCS11_CONFIG_HELP"));
    cardPanel.add(pkcs11Panel, "PKCS11");

    ((CardLayout) cardPanel.getLayout()).show(cardPanel, (String) clientKeystoreTypeCombo.getSelectedItem());

    clientKeystoreTypeCombo.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            CardLayout cardLayout = (CardLayout) (cardPanel.getLayout());
            if ("PKCS11".equals(event.getItem())) {
                cardLayout.show(cardPanel, "PKCS11");
            } else {
                cardLayout.show(cardPanel, "FILE");
            }
        }
    });
    updateMaximumSize(clientKeystorePanel);
    return clientKeystorePanel;
}

From source file:com.jwmsolutions.timeCheck.gui.TodoForm.java

private JComboBox getJcbListsObject() {
    if (jcbLists == null) {
        ComboBoxModel jcbListModel = new DefaultComboBoxModel(new String[] { "Item One", "Item Two" });
        jcbListModel.setSelectedItem("");
        jcbLists = new JComboBox();
        jcbLists.setModel(jcbListModel);
        jcbLists.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
        jcbLists.setAutoscrolls(true);/*from w ww.j  a  v  a2s  .com*/
        jcbLists.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent evt) {
                jcbListsItemStateChanged(evt);
            }
        });
    }
    return jcbLists;
}

From source file:org.squidy.designer.Designer.java

/**
 * Initializes menu bar.//  w ww.  ja v a2  s.co m
 */
private void initMenuBar() {

    JMenuBar menuBar = new JMenuBar();

    JMenu workspace = new JMenu("Workspace");
    workspace.add(new AbstractAction("Open from...") {

        /*
         * (non-Javadoc)
         * 
         * @see
         * java.awt.event.ActionListener#actionPerformed(java.awt.event.
         * ActionEvent)
         */
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileHidingEnabled(true);
            fileChooser.setFileFilter(new FileFilter() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see
                 * javax.swing.filechooser.FileFilter#accept(java.io.File)
                 */
                @Override
                public boolean accept(File f) {
                    return f.isDirectory() || f.getName().endsWith(".sdy");
                }

                /*
                 * (non-Javadoc)
                 * 
                 * @see javax.swing.filechooser.FileFilter#getDescription()
                 */
                @Override
                public String getDescription() {
                    return "Squidy Workspace";
                }
            });
            int option = fileChooser.showOpenDialog(Designer.this);

            if (option == JFileChooser.APPROVE_OPTION) {

                // Stop replacing workspace if currently running.
                if (data != null) {
                    data.getWorkspace().stop();
                }

                File workspaceFile = fileChooser.getSelectedFile();

                if (storage instanceof LocalJAXBStorage) {
                    ((LocalJAXBStorage) storage).setWorkspaceFile(workspaceFile);
                    load();
                } else {
                    try {
                        data = ModelViewHandler.getModelViewHandler().load(new FileInputStream(workspaceFile));

                        WorkspaceShape workspace = data.getWorkspaceShape();
                        workspace.setModel(data);
                        workspace.setStorageHandler(Designer.this);
                        workspace.initialize();
                        LayoutConstraint lc = workspace.getLayoutConstraint();
                        workspace.setScale(lc.getScale());
                        workspace.setOffset(lc.getX(), lc.getY());

                        getCanvas().getLayer().addChild(workspace);

                        zoomToZoomedShape(data);
                    } catch (SquidyException e1) {
                        e1.printStackTrace();
                    } catch (FileNotFoundException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    });

    workspace.add(new AbstractAction("Export as...") {

        /*
         * (non-Javadoc)
         * 
         * @see
         * java.awt.event.ActionListener#actionPerformed(java.awt.event.
         * ActionEvent)
         */
        public void actionPerformed(ActionEvent e) {

            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileHidingEnabled(true);
            fileChooser.setFileFilter(new FileFilter() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see
                 * javax.swing.filechooser.FileFilter#accept(java.io.File)
                 */
                @Override
                public boolean accept(File f) {
                    return f.isDirectory() || f.getName().endsWith(".sdy");
                }

                /*
                 * (non-Javadoc)
                 * 
                 * @see javax.swing.filechooser.FileFilter#getDescription()
                 */
                @Override
                public String getDescription() {
                    return "Squidy Workspace";
                }
            });

            if (storage instanceof LocalJAXBStorage) {
                fileChooser.setSelectedFile(((LocalJAXBStorage) storage).getWorkspaceFile());
            }

            int option = fileChooser.showSaveDialog(Designer.this);

            if (option == JFileChooser.APPROVE_OPTION) {

                File workspaceFile = fileChooser.getSelectedFile();

                try {
                    ModelViewHandler.getModelViewHandler().save(new FileOutputStream(workspaceFile), data);
                } catch (FileNotFoundException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
        }
    });

    JMenu options = new JMenu("Options");
    rendering.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            VisualShape.setRenderPrimitiveRect(rendering.isSelected());
            data.setRenderPrimitiveRect(rendering.isSelected());
            storage.store(data);
            repaint();
        }
    });
    options.add(rendering);

    JMenu storage = new JMenu("Storage");

    ButtonGroup group = new ButtonGroup();

    final JRadioButtonMenuItem storageLocalJAXB = new JRadioButtonMenuItem("Local JAXB");
    storageLocalJAXB.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (storageLocalJAXB.isSelected()) {
                setStorageMode(StorageMode.FILE);
            }
        }
    });
    storage.add(storageLocalJAXB);
    group.add(storageLocalJAXB);

    final JRadioButtonMenuItem storageBaseX = new JRadioButtonMenuItem("BaseX");
    storageBaseX.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (storageBaseX.isSelected()) {
                setStorageMode(StorageMode.BASEX);
            }
        }
    });
    storageBaseX.setSelected(storageType.equals(BaseXStorage.class));

    storage.add(storageBaseX);
    group.add(storageBaseX);
    options.add(storage);

    menuBar.add(workspace);
    menuBar.add(options);

    setJMenuBar(menuBar);
}

From source file:levelBuilder.DialogMaker.java

/**
 * Various routines necessary for displaying graph.
 *//* ww w . j a  va  2  s. com*/
private static void displayGraph() {
    JFrame frame = new JFrame("Dialog Maker");
    layout = new KKLayout<DialogNode, Double>(g);
    VisualizationViewer<DialogNode, Double> vv = new VisualizationViewer<DialogNode, Double>(layout);
    layout.setSize(new Dimension(windowWidth, windowHeight));
    vv.setPreferredSize(new Dimension(windowWidth, windowHeight));

    //Changes fields in node properties window when a node is selected
    pickedState = vv.getPickedVertexState();
    pickedState.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            Object subject = e.getItem();
            if (subject instanceof DialogNode) {
                selectedNode = (DialogNode) subject;
                textField.setText(selectedNode.getText());
                npcBox.setSelected(selectedNode.getIsNPC());
                String working = "";
                for (int c = 0; c < selectedNode.getChildren().length; c++) {
                    if (c == 0)
                        working += selectedNode.getChildren()[c].getText();
                    else
                        working += "," + selectedNode.getChildren()[c].getText();
                }
                if (working.equals("null"))
                    working = "";
                childrenField.setText(working.replace("]", "").replace("[", ""));
                working = Arrays.toString(selectedNode.getProbSets().get(strategy));
                if (working.equals("null"))
                    working = "";
                probSetField.setText(working.replace("]", "").replace("[", "").replace(" ", ""));
            }
        }
    });

    //Colors vertices according to 'initial', 'end', or 'middle' status.
    vv.getRenderContext().setVertexFillPaintTransformer(new Transformer<DialogNode, Paint>() {
        @Override
        public Paint transform(DialogNode n) {
            if (n.getText().equals("initial"))
                return new Color(100, 255, 100);
            if (n.getChildren().length == 0)
                return new Color(255, 100, 100);
            return new Color(100, 100, 255);
        }
    });

    //Labels vertices with node text.
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<DialogNode, String>() {
        @Override
        public String transform(DialogNode n) {
            return n.getText().split(" ")[0];
        }

    });

    //Draws shape of vertices according to player or non-player status.
    vv.getRenderContext().setVertexShapeTransformer(new Transformer<DialogNode, Shape>() {
        @Override
        public Shape transform(DialogNode n) {
            if (n.getIsNPC())
                return new Rectangle(-15, -15, 30, 30);
            else
                return new Ellipse2D.Double(-15.0, -15.0, 30.0, 30.0);
        }

    });

    //Labels edges with probability of child being selected under the current strategy.
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Double, String>() {
        @Override
        public String transform(Double e) {
            DialogNode source = g.getSource(e);
            if (source.getProbSets().size() > 0)
                for (int c = 0; c < source.getChildren().length; c++)
                    if (source.getChildren()[c].equals(g.getDest(e))) {
                        if (source.getProbSets().get(strategy) != null)
                            return Double.toString(source.getProbSets().get(strategy)[c]);
                        else //If node does not have probSet for that strategy, default to strategy 0.
                            return Double.toString(source.getProbSets().get(0)[c]);
                    }
            return null;
        }
    });
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);

    //Routines for editing mode.
    EditingModalGraphMouse<DialogNode, Double> gm = new EditingModalGraphMouse<DialogNode, Double>(
            vv.getRenderContext(),
            //Runs when a new node is created.
            new Factory<DialogNode>() {
                @Override
                public DialogNode create() {
                    DialogNode n = new DialogNode(isNPCBoxChecked, textField.getText(),
                            new ArrayList<double[]>(), new DialogNode[0]);
                    dg.addNode(n);
                    return n;
                }
            },
            //Runs when a new edge is created.
            new Factory<Double>() {
                @Override
                public Double create() {
                    addedEdgeID = Math.random();
                    return addedEdgeID;
                }
            });
    vv.setGraphMouse(gm);

    //Frame and mode menu.
    JMenuBar menuBar = new JMenuBar();
    JMenu modeMenu = gm.getModeMenu();
    modeMenu.setText("Mouse Mode");
    modeMenu.setIcon(null);
    modeMenu.setPreferredSize(new Dimension(100, 20));
    menuBar.add(modeMenu);
    frame.setJMenuBar(menuBar);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    frame.pack();
    frame.setVisible(true);

    //      //Sets position of each node.
    //      for (DialogNode n : nodeMap.values()) {
    //         Point2D.Double point = new Point2D.Double(n.getX(), n.getY());
    //         if (point.x != 0.0 && point.y != 0.0)
    //            layout.setLocation(n, point);
    //      }
}