Example usage for javax.swing.event ChangeListener ChangeListener

List of usage examples for javax.swing.event ChangeListener ChangeListener

Introduction

In this page you can find the example usage for javax.swing.event ChangeListener ChangeListener.

Prototype

ChangeListener

Source Link

Usage

From source file:es.unex.meigas.extFillData.FittingDataPanel.java

private JSpinner getJSpinnerOrder() {

    if (jSpinnerOrder == null) {
        final SpinnerListModel jSpinnerOrderModel = new SpinnerListModel(
                new String[] { "1", "2", "3", "4", "5", "6", "7" });
        jSpinnerOrder = new JSpinner();
        jSpinnerOrder.setModel(jSpinnerOrderModel);
        jSpinnerOrder.addChangeListener(new ChangeListener() {
            public void stateChanged(final ChangeEvent evt) {
                String s = (String) ((SpinnerListModel) jSpinnerOrder.getModel()).getValue();
                m_Lsf.calculate(Integer.parseInt(s));
                updateDataset();/*from w  ww  . j  a v  a  2 s .  co m*/
                s = m_Lsf.getExpression();
                getJLabel().setText("Ecuacion de ajuste: y = " + s);
            }
        });
    }

    return jSpinnerOrder;

}

From source file:gui.WikiCorpusClusteringView.java

/**
 *
 * @param br//w w  w . ja  v  a  2s.c om
 * @throws IOException
 */
private void setUpView(Graph graph) throws IOException {

    //Create a simple layout frame
    //specify the Fruchterman-Rheingold layout algorithm
    //        final AggregateLayout<Number, Number> layout =
    //                new AggregateLayout<Number, Number>(new FRLayout<Number, Number>(graph));

    //layout = new TreeLayout<String,Integer>(graph);
    Layout<Number, Number> layout = new KKLayout<Number, Number>(graph);
    layout.setSize(new Dimension(900, 900));

    vv = new VisualizationViewer<Number, Number>(layout);
    vv.setBackground(Color.white);
    //Tell the renderer to use our own customized color rendering
    vv.getRenderContext()
            .setVertexFillPaintTransformer(MapTransformer.<Number, Paint>getInstance(vertexPaints));
    vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<Number, Paint>() {
        public Paint transform(Number v) {
            if (vv.getPickedVertexState().isPicked(v)) {
                return Color.cyan;
            } else {
                return Color.BLACK;
            }
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(MapTransformer.<Number, Paint>getInstance(edgePaints));

    vv.getRenderContext().setEdgeStrokeTransformer(new Transformer<Number, Stroke>() {
        protected final Stroke THIN = new BasicStroke(1);
        protected final Stroke THICK = new BasicStroke(2);

        public Stroke transform(Number e) {
            Paint c = edgePaints.get(e);
            if (c == Color.LIGHT_GRAY) {
                return THIN;
            } else {
                return THICK;
            }
        }
    });

    //add restart button
    JButton scramble = new JButton("Restart");
    scramble.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Layout layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }
    });

    DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
    vv.setGraphMouse(gm);

    final JToggleButton groupVertices = new JToggleButton("Group Clusters");

    //Create slider to adjust the number of edges to remove when clustering
    final JSlider edgeBetweennessSlider = new JSlider(JSlider.HORIZONTAL);
    edgeBetweennessSlider.setBackground(Color.WHITE);
    edgeBetweennessSlider.setPreferredSize(new Dimension(210, 50));
    edgeBetweennessSlider.setPaintTicks(true);
    edgeBetweennessSlider.setMaximum(graph.getEdgeCount());
    edgeBetweennessSlider.setMinimum(0);
    edgeBetweennessSlider.setValue(0);
    edgeBetweennessSlider.setMajorTickSpacing(10);
    edgeBetweennessSlider.setPaintLabels(true);
    edgeBetweennessSlider.setPaintTicks(true);

    //      edgeBetweennessSlider.setBorder(BorderFactory.createLineBorder(Color.black));
    //TO DO: edgeBetweennessSlider.add(new JLabel("Node Size (PageRank With Priors):"));
    //I also want the slider value to appear
    final JPanel eastControls = new JPanel();
    eastControls.setOpaque(true);
    eastControls.setLayout(new BoxLayout(eastControls, BoxLayout.Y_AXIS));
    eastControls.add(Box.createVerticalGlue());
    eastControls.add(edgeBetweennessSlider);

    final String COMMANDSTRING = "Edges removed for clusters: ";
    final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue();

    final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize);
    eastControls.setBorder(sliderBorder);
    //eastControls.add(eastSize);
    eastControls.add(Box.createVerticalGlue());

    groupVertices.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {

            //clusterAndRecolor(layout, edgeBetweennessSlider.getValue(),
            //        similarColors, e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });

    //clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected());

    edgeBetweennessSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                int numEdgesToRemove = source.getValue();
                //clusterAndRecolor(layout, numEdgesToRemove, similarColors,
                //        groupVertices.isSelected());
                sliderBorder.setTitle(COMMANDSTRING + edgeBetweennessSlider.getValue());
                eastControls.repaint();
                vv.validate();
                vv.repaint();
            }
        }
    });

    Container content = getContentPane();
    content.add(new GraphZoomScrollPane(vv));
    JPanel south = new JPanel();
    JPanel grid = new JPanel(new GridLayout(2, 1));
    grid.add(scramble);
    grid.add(groupVertices);
    south.add(grid);
    south.add(eastControls);
    JPanel p = new JPanel();
    p.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    p.add(gm.getModeComboBox());
    south.add(p);
    content.add(south, BorderLayout.SOUTH);
}

From source file:com.diversityarrays.kdxplore.field.FieldViewDialog.java

public FieldViewDialog(Window owner, String title, SampleGroupChoice sgcSamples, Trial trial,
        SampleGroupChoice sgcNewMedia, KDSmartDatabase db) throws IOException {
    super(owner, title, ModalityType.MODELESS);

    advanceRetreatControls = Box.createHorizontalBox();
    advanceRetreatControls.add(new JButton(retreatAction));
    advanceRetreatControls.add(new JButton(advanceAction));

    autoAdvanceControls = Box.createHorizontalBox();
    autoAdvanceControls.add(new JButton(autoAdvanceAction));

    autoAdvanceOption.addActionListener(new ActionListener() {
        @Override/*from   w w w .j  a v  a2  s. c  om*/
        public void actionPerformed(ActionEvent e) {
            updateMovementControls();
        }
    });

    this.database = db;
    this.sampleGroupChoiceForSamples = sgcSamples;
    this.sampleGroupChoiceForNewMedia = sgcNewMedia;

    NumberSpinner fontSpinner = new NumberSpinner(new SpinnerNumberModel(), "0.00");

    this.fieldViewPanel = FieldViewPanel.create(database, trial, SeparatorVisibilityOption.VISIBLE, null,
            Box.createHorizontalGlue(), new JButton(showInfoAction), Box.createHorizontalGlue(),
            new JLabel("Font Size:"), fontSpinner, Box.createHorizontalGlue(), advanceRetreatControls,
            autoAdvanceOption, autoAdvanceControls);

    initialiseAction(advanceAction, "ic_object_advance_black.png", "Auto-Advance");

    this.xyProvider = fieldViewPanel.getXYprovider();
    this.traitMap = fieldViewPanel.getTraitMap();

    fieldLayoutTable = fieldViewPanel.getFieldLayoutTable();

    JScrollPane scrollPane = fieldViewPanel.getFieldTableScrollPane();
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    fieldLayoutTable.setTransferHandler(flth);
    fieldLayoutTable.setDropMode(DropMode.ON);

    fieldLayoutTable.addMouseListener(new MouseAdapter() {
        JPopupMenu popupMenu;

        @Override
        public void mouseClicked(MouseEvent e) {
            if (!SwingUtilities.isRightMouseButton(e) || 1 != e.getClickCount()) {
                return;
            }
            Point pt = e.getPoint();
            int row = fieldLayoutTable.rowAtPoint(pt);
            if (row >= 0) {
                int col = fieldLayoutTable.columnAtPoint(pt);
                if (col >= 0) {
                    Plot plot = fieldViewPanel.getPlotAt(col, row);
                    if (plot != null) {
                        if (popupMenu == null) {
                            popupMenu = new JPopupMenu("View Attachments");
                        }
                        popupMenu.removeAll();

                        Set<File> set = plot.getMediaFiles();
                        if (Check.isEmpty(set)) {
                            popupMenu.add(new JMenuItem("No Attachments available"));
                        } else {
                            for (File file : set) {
                                Action a = new AbstractAction(file.getName()) {
                                    @Override
                                    public void actionPerformed(ActionEvent e) {
                                        try {
                                            Desktop.getDesktop().browse(file.toURI());
                                        } catch (IOException e1) {
                                            MsgBox.warn(FieldViewDialog.this, e1, file.getName());
                                        }
                                    }
                                };
                                popupMenu.add(new JMenuItem(a));
                            }
                        }
                        popupMenu.show(fieldLayoutTable, pt.x, pt.y);
                    }
                }
            }
        }

    });
    Font font = fieldLayoutTable.getFont();
    float fontSize = font.getSize2D();

    fontSizeModel = new SpinnerNumberModel(fontSize, fontSize, 50.0, 1.0);
    fontSpinner.setModel(fontSizeModel);
    fontSizeModel.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            float fsize = fontSizeModel.getNumber().floatValue();
            System.out.println("Using fontSize=" + fsize);
            Font font = fieldLayoutTable.getFont().deriveFont(fsize);
            fieldLayoutTable.setFont(font);
            FontMetrics fm = fieldLayoutTable.getFontMetrics(font);
            int lineHeight = fm.getMaxAscent() + fm.getMaxDescent();
            fieldLayoutTable.setRowHeight(4 * lineHeight);

            //                GuiUtil.initialiseTableColumnWidths(fieldLayoutTable, false);

            fieldLayoutTable.repaint();
        }
    });

    fieldLayoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    fieldLayoutTable.setResizable(true, true);
    fieldLayoutTable.getTableColumnResizer().setResizeAllColumns(true);

    advanceAction.setEnabled(false);
    fieldLayoutTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                handlePlotSelection();
            }
        }
    });
    TableColumnModel columnModel = fieldLayoutTable.getColumnModel();
    columnModel.addColumnModelListener(new TableColumnModelListener() {
        @Override
        public void columnSelectionChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                handlePlotSelection();
            }
        }

        @Override
        public void columnRemoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnMoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent e) {
        }

        @Override
        public void columnAdded(TableColumnModelEvent e) {
        }
    });

    PropertyChangeListener listener = new PropertyChangeListener() {
        // Use a timer and redisplay other columns when delay is GT 100 ms

        Timer timer = new Timer(true);
        TimerTask timerTask;
        long lastActive;
        boolean busy = false;
        private int eventColumnWidth;
        private TableColumn eventColumn;

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (busy) {
                return;
            }

            if (evt.getSource() instanceof TableColumn && "width".equals(evt.getPropertyName())) {

                eventColumn = (TableColumn) evt.getSource();
                eventColumnWidth = eventColumn.getWidth();

                lastActive = System.currentTimeMillis();
                if (timerTask == null) {
                    timerTask = new TimerTask() {
                        @Override
                        public void run() {
                            if (System.currentTimeMillis() - lastActive > 200) {
                                timerTask.cancel();
                                timerTask = null;

                                busy = true;
                                try {
                                    for (Enumeration<TableColumn> en = columnModel.getColumns(); en
                                            .hasMoreElements();) {
                                        TableColumn tc = en.nextElement();
                                        if (tc != eventColumn) {
                                            tc.setWidth(eventColumnWidth);
                                        }
                                    }
                                } finally {
                                    busy = false;
                                }
                            }
                        }
                    };
                    timer.scheduleAtFixedRate(timerTask, 100, 150);
                }
            }
        }
    };
    for (Enumeration<TableColumn> en = columnModel.getColumns(); en.hasMoreElements();) {
        TableColumn tc = en.nextElement();
        tc.addPropertyChangeListener(listener);
    }

    Map<Integer, Plot> plotById = new HashMap<>();
    for (Plot plot : fieldViewPanel.getFieldLayout()) {
        plotById.put(plot.getPlotId(), plot);
    }

    TrialItemVisitor<Sample> sampleVisitor = new TrialItemVisitor<Sample>() {
        @Override
        public void setExpectedItemCount(int count) {
        }

        @Override
        public boolean consumeItem(Sample sample) throws IOException {

            Plot plot = plotById.get(sample.getPlotId());
            if (plot == null) {
                throw new IOException("Missing plot for plotId=" + sample.getPlotId() + " sampleIdent="
                        + Util.createUniqueSampleKey(sample));
            }
            plot.addSample(sample);

            SampleCounts counts = countsByTraitId.get(sample.getTraitId());
            if (counts == null) {
                counts = new SampleCounts();
                countsByTraitId.put(sample.getTraitId(), counts);
            }
            if (sample.hasBeenScored()) {
                ++counts.scored;
            } else {
                ++counts.unscored;
            }
            return true;
        }
    };
    database.visitSamplesForTrial(sampleGroupChoiceForSamples, trial.getTrialId(),
            SampleOrder.ALL_BY_PLOT_ID_THEN_TRAIT_ID_THEN_INSTANCE_NUMBER_ORDER_THEN_SPECIMEN_NUMBER,
            sampleVisitor);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    this.trial = trial;

    KDClientUtils.initAction(ImageId.SETTINGS_24, showInfoAction, "Trial Summary");

    Action clear = new AbstractAction("Clear") {
        @Override
        public void actionPerformed(ActionEvent e) {
            infoTextArea.setText("");
        }
    };
    JPanel bottom = new JPanel(new BorderLayout());
    bottom.add(GuiUtil.createLabelSeparator("Plot Details", new JButton(clear)), BorderLayout.NORTH);
    bottom.add(new JScrollPane(infoTextArea), BorderLayout.CENTER);
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, fieldViewPanel,
            new JScrollPane(infoTextArea));
    splitPane.setResizeWeight(0.0);
    splitPane.setOneTouchExpandable(true);

    setContentPane(splitPane);

    updateMovementControls();
    pack();
}

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

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

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

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

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

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

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

    });
    this.add(closeOnStart);

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

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

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

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

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

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

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

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

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

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

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

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

    });
    bottom.add(icons);

    look.add(bottom);

    this.add(look);

    load();
}

From source file:biomine.bmvis2.Vis.java

private void createGUI(String title) {
    //        try {
    //            System.setProperty("com.apple.macosx.AntiAliasedTextOn", "false");
    //            System.setProperty("com.apple.macosx.AntiAliasedGraphicsOn",
    //                    "false");
    //        } catch (Throwable t) {
    //            // Ignore property exceptions
    //        }/* w w w.ja  va2s .  c  om*/
    //        try {
    //            System.setProperty("sun.java2d.opengl", "true");
    //        } catch (Throwable t) {
    //            // Ignore property exceptions
    //        }

    this.setLayout(new GridLayout());
    this.tabs = new TabbedPaneHiddenBar();
    this.getContentPane().add(tabs);
    this.tabs.setVisible(true);

    tabs.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent arg0) {
            GraphTab tab = (GraphTab) tabs.getSelectedComponent();
            if (tab == null) {
                Logging.info("ui", "No graphs open, creating the default menu.");
                Vis.this.setJMenuBar(getDefaultMenu());
            } else {
                Vis.this.setJMenuBar(tab.getMenuBar());
            }
        }
    });

    if (appletContext == null) {
        Options opts = new Options();
        CommandLineParser parser = new PosixParser();
        CommandLine cmd = null;

        opts.addOption("h", "help", false, "Show help.");
        opts.addOption("s", "simple", false, "Show simple UI without side panes");
        opts.addOption("logcategories", true, "Logging categories delimited by spaces, all for all");
        opts.addOption("loglevel", true, "Logging level: 0 for debug, 1 for info, 2 for warning, 3 for error");
        opts.addOption("d", "debug", false, "Shorthand for logcategories all, loglevel -1");

        try {
            cmd = parser.parse(opts, args);
        } catch (ParseException e) {
            System.err.println(e.getLocalizedMessage());
            System.err.println();
            Vis.printCmdLineHelp(opts);
            System.exit(1);
        }

        if (cmd.hasOption("-h") || cmd.getArgList().size() == 0) {
            Vis.printCmdLineHelp(opts);
            System.exit(0);
        }

        if (cmd.hasOption("-s"))
            this.properties.put("simple", "true");

        if (cmd.hasOption("-d")) {
            Logging.init(new ArrayList<String>(Arrays.asList("all")), -1);
        } else {
            ArrayList<String> logCategories = null;
            Integer logLevel = null;
            if (cmd.hasOption("logcategories"))
                logCategories = new ArrayList<String>(
                        Arrays.asList(cmd.getOptionValue("logcategories").split(",")));
            if (cmd.hasOption("loglevel"))
                logLevel = Integer.parseInt(cmd.getOptionValue("loglevel"));

            if (logCategories != null || logLevel != null)
                Logging.init(logCategories, logLevel);
        }

        VisFrame frame = new VisFrame("BMVIS II");
        this.visFrame = frame;
        frame.add(this);

        boolean noneOpened = true;
        for (Object arg : cmd.getArgList()) {
            if (this.openTab((String) arg) != null)
                noneOpened = false;
        }

        if (noneOpened && cmd.getArgList().size() > 0) {
            String message = "No files could be opened! Exiting.";
            Logging.error("graph_reading", message);
            JOptionPane.showMessageDialog(this, message);
            System.exit(1);
        }

        this.visFrame.setVisible(true);

    } else {
        // Applet operation goes here...
        this.setVisible(true);

        try {
            if (getParameter("graph") != null) {
                String graphFile = getParameter("graph");

                URL u = new URL(getCodeBase(), graphFile);
                InputStream graphStream = u.openConnection().getInputStream();
                BMGraph bm = BMGraphUtils.readBMGraph(graphStream);
                graphStream.close();
                this.openTab(new FileGraphSource(bm));
            }
            if (getParameter("json") != null) {
                String jsonFile = getParameter("json");
                URL u = new URL(getCodeBase(), jsonFile);
                InputStream jsonStream = u.openConnection().getInputStream();

                openJSONTab(StreamToString.convertStreamToString(jsonStream), jsonFile);
            }
        } catch (IOException e) {
            Logging.error("graph_reading", e.toString());
            JOptionPane.showMessageDialog(this, e.getMessage());
        }
    }
}

From source file:SoundPlayer.java

JSlider createSlider(final FloatControl c) {
    if (c == null)
        return null;
    final JSlider s = new JSlider(0, 1000);
    final float min = c.getMinimum();
    final float max = c.getMaximum();
    final float width = max - min;
    float fval = c.getValue();
    s.setValue((int) ((fval - min) / width * 1000));

    java.util.Hashtable labels = new java.util.Hashtable(3);
    labels.put(new Integer(0), new JLabel(c.getMinLabel()));
    labels.put(new Integer(500), new JLabel(c.getMidLabel()));
    labels.put(new Integer(1000), new JLabel(c.getMaxLabel()));
    s.setLabelTable(labels);/*  w  w  w .  ja v a2s  .  c  o  m*/
    s.setPaintLabels(true);

    s.setBorder(new TitledBorder(c.getType().toString() + " " + c.getUnits()));

    s.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            int i = s.getValue();
            float f = min + (i * width / 1000.0f);
            c.setValue(f);
        }
    });
    return s;
}

From source file:de.huxhorn.lilith.swing.ViewActions.java

public ViewActions(MainFrame mainFrame) {
    this.mainFrame = mainFrame;

    containerChangeListener = new ChangeListener() {
        /**//from  www  .  j av a 2  s. c  o  m
         * Invoked when the target of the listener has changed its state.
         *
         * @param e a ChangeEvent object
         */
        public void stateChanged(ChangeEvent e) {
            updateActions();
        }
    };

    containerPropertyChangeListener = new PropertyChangeListener() {

        /**
         * This method gets called when a bound property is changed.
         *
         * @param evt A PropertyChangeEvent object describing the event source
         *            and the property that has changed.
         */

        public void propertyChange(PropertyChangeEvent evt) {
            if (ViewContainer.SELECTED_EVENT_PROPERTY_NAME.equals(evt.getPropertyName())) {
                setEventWrapper((EventWrapper) evt.getNewValue());
            }

        }
    };

    keyStrokeActionMapping = new HashMap<KeyStroke, CopyToClipboardAction>();
    // ##### Menu Actions #####
    // File
    OpenMenuAction openMenuAction = new OpenMenuAction();
    clearRecentFilesAction = new ClearRecentFilesAction();
    OpenInactiveLogMenuAction openInactiveLogMenuAction = new OpenInactiveLogMenuAction();
    ImportMenuAction importMenuAction = new ImportMenuAction();
    exportMenuAction = new ExportMenuAction();
    CleanAllInactiveLogsMenuAction cleanAllInactiveLogsMenuAction = new CleanAllInactiveLogsMenuAction();
    preferencesMenuAction = new PreferencesMenuAction();
    ExitMenuAction exitMenuAction = new ExitMenuAction();

    // Edit
    showUnfilteredEventAction = new ShowUnfilteredEventAction();
    gotoSourceAction = new GotoSourceAction();
    copySelectionAction = new CopySelectionAction();
    copyEventAction = new CopyToClipboardAction(new EventFormatter());
    copyLoggingActions = new ArrayList<CopyToClipboardAction>();
    copyLoggingActions.add(new CopyToClipboardAction(new EventJsonFormatter()));
    copyLoggingActions.add(new CopyToClipboardAction(new EventXmlFormatter()));
    copyLoggingActions.add(new CopyToClipboardAction(new LoggingMessageFormatter()));
    copyLoggingActions.add(new CopyToClipboardAction(new LoggingMessagePatternFormatter()));
    copyLoggingActions.add(new CopyToClipboardAction(new LoggingLoggerNameFormatter()));
    copyLoggingActions.add(new CopyToClipboardAction(new LoggingThrowableFormatter()));
    copyLoggingActions.add(new CopyToClipboardAction(new LoggingCallStackFormatter()));
    copyLoggingActions.add(new CopyToClipboardAction(new LoggingCallLocationFormatter()));
    copyLoggingActions.add(new CopyToClipboardAction(new LoggingMarkerFormatter()));
    copyLoggingActions.add(new CopyToClipboardAction(new LoggingMdcFormatter()));
    copyLoggingActions.add(new CopyToClipboardAction(new LoggingNdcFormatter()));
    copyAccessActions = new ArrayList<CopyToClipboardAction>();
    copyAccessActions.add(new CopyToClipboardAction(new AccessUriFormatter()));

    prepareClipboardActions(copyLoggingActions, keyStrokeActionMapping);
    prepareClipboardActions(copyAccessActions, keyStrokeActionMapping);

    // Search
    findMenuAction = new FindMenuAction();
    findPreviousAction = new FindPreviousAction();
    findNextAction = new FindNextAction();
    findPreviousActiveAction = new FindPreviousActiveAction();
    findNextActiveAction = new FindNextActiveAction();
    resetFindAction = new ResetFindAction();

    // View
    scrollToBottomMenuAction = new ScrollToBottomMenuAction();
    pauseMenuAction = new PauseMenuAction();
    clearMenuAction = new ClearMenuAction();
    attachMenuAction = new AttachMenuAction();
    disconnectMenuAction = new DisconnectMenuAction();

    focusMessageAction = new FocusMessageAction();
    focusEventsAction = new FocusEventsAction();

    //statisticsMenuAction = new StatisticsMenuAction();
    editSourceNameMenuAction = new EditSourceNameMenuAction();
    saveLayoutAction = new SaveLayoutAction();
    resetLayoutAction = new ResetLayoutAction();
    saveConditionMenuAction = new SaveConditionMenuAction();

    zoomInMenuAction = new ZoomInMenuAction();
    zoomOutMenuAction = new ZoomOutMenuAction();
    resetZoomMenuAction = new ResetZoomMenuAction();

    previousTabAction = new PreviousTabAction();
    nextTabAction = new NextTabAction();
    closeFilterAction = new CloseFilterAction();
    closeOtherFiltersAction = new CloseOtherFiltersAction();
    closeAllFiltersAction = new CloseAllFiltersAction();

    // Window
    ShowTaskManagerAction showTaskManagerAction = new ShowTaskManagerAction();
    closeAllAction = new CloseAllAction();
    closeOtherAction = new CloseOtherAction();
    minimizeAllAction = new MinimizeAllAction();
    minimizeAllOtherAction = new MinimizeAllOtherAction();
    removeInactiveAction = new RemoveInactiveAction();
    //clearAndRemoveInactiveAction=new ClearAndRemoveInactiveAction();

    // Help
    KeyboardHelpAction keyboardHelpAction = new KeyboardHelpAction();
    ShowLoveMenuAction showLoveMenuAction = new ShowLoveMenuAction();
    TipOfTheDayAction tipOfTheDayAction = new TipOfTheDayAction();
    DebugAction debugAction = new DebugAction();
    aboutAction = new AboutAction();
    CheckForUpdateAction checkForUpdateAction = new CheckForUpdateAction();
    TroubleshootingAction troubleshootingAction = new TroubleshootingAction();

    // ##### ToolBar Actions #####
    scrollToBottomToolBarAction = new ScrollToBottomToolBarAction();
    pauseToolBarAction = new PauseToolBarAction();
    clearToolBarAction = new ClearToolBarAction();
    findToolBarAction = new FindToolBarAction();
    //statisticsToolBarAction = new StatisticsToolBarAction();
    attachToolBarAction = new AttachToolBarAction();
    disconnectToolBarAction = new DisconnectToolBarAction();

    showTaskManagerItem = new JMenuItem(showTaskManagerAction);
    closeAllItem = new JMenuItem(closeAllAction);
    closeAllOtherItem = new JMenuItem(closeOtherAction);
    minimizeAllItem = new JMenuItem(minimizeAllAction);
    minimizeAllOtherItem = new JMenuItem(minimizeAllOtherAction);
    removeInactiveItem = new JMenuItem(removeInactiveAction);
    //clearAndRemoveInactiveItem = new JMenuItem(clearAndRemoveInactiveAction);

    toolbar = new JToolBar(SwingConstants.HORIZONTAL);
    toolbar.setFloatable(false);

    scrollToBottomButton = new JToggleButton(scrollToBottomToolBarAction);
    toolbar.add(scrollToBottomButton);

    JButton pauseButton = new JButton(pauseToolBarAction);
    toolbar.add(pauseButton);

    JButton clearButton = new JButton(clearToolBarAction);
    toolbar.add(clearButton);

    JButton findButton = new JButton(findToolBarAction);
    toolbar.add(findButton);

    JButton disconnectButton = new JButton(disconnectToolBarAction);
    toolbar.add(disconnectButton);

    toolbar.addSeparator();

    //JButton statisticsButton = new JButton(statisticsToolBarAction);
    //toolbar.add(statisticsButton);
    //toolbar.addSeparator();

    JButton attachButton = new JButton(attachToolBarAction);
    toolbar.add(attachButton);

    toolbar.addSeparator();

    PreferencesToolBarAction preferencesToolBarAction = new PreferencesToolBarAction();
    JButton preferencesButton = new JButton(preferencesToolBarAction);
    toolbar.add(preferencesButton);

    toolbar.addSeparator();

    ShowLoveToolbarAction showLoveToolbarAction = new ShowLoveToolbarAction();
    JButton showLoveButton = new JButton(showLoveToolbarAction);
    toolbar.add(showLoveButton);

    recentFilesMenu = new JMenu("Recent Files");

    Application app = mainFrame.getApplication();

    menubar = new JMenuBar();

    // File
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic('f');
    fileMenu.add(openMenuAction);
    fileMenu.add(recentFilesMenu);
    fileMenu.add(openInactiveLogMenuAction);
    fileMenu.add(cleanAllInactiveLogsMenuAction);
    fileMenu.add(importMenuAction);
    fileMenu.add(exportMenuAction);
    if (!app.isMac()) {
        fileMenu.addSeparator();
        fileMenu.add(preferencesMenuAction);
        fileMenu.addSeparator();
        fileMenu.add(exitMenuAction);
    }

    // Edit
    editMenu = new JMenu("Edit");
    editMenu.setMnemonic('e');
    editMenu.add(copySelectionAction);
    editMenu.addSeparator();
    editMenu.add(copyEventAction);
    editMenu.addSeparator();
    for (CopyToClipboardAction current : copyLoggingActions) {
        editMenu.add(current);
    }
    editMenu.addSeparator();
    for (CopyToClipboardAction current : copyAccessActions) {
        editMenu.add(current);
    }
    editMenu.addSeparator();
    customCopyMenu = new JMenu("Custom copy");
    customCopyPopupMenu = new JMenu("Custom copy");
    editMenu.add(customCopyMenu);
    editMenu.addSeparator();
    PasteStackTraceElementAction pasteStackTraceElementAction = new PasteStackTraceElementAction();
    editMenu.add(pasteStackTraceElementAction);

    // Search
    searchMenu = new JMenu("Search");
    searchMenu.setMnemonic('s');
    searchMenu.add(findMenuAction);
    searchMenu.add(resetFindAction);
    searchMenu.add(findPreviousAction);
    searchMenu.add(findNextAction);
    searchMenu.add(findPreviousActiveAction);
    searchMenu.add(findNextActiveAction);
    searchMenu.addSeparator();
    searchMenu.add(saveConditionMenuAction);
    searchMenu.addSeparator();

    focusMenu = new FocusMenu(mainFrame.getApplicationPreferences());
    excludeMenu = new ExcludeMenu(mainFrame.getApplicationPreferences());
    searchMenu.add(focusMenu);
    searchMenu.add(excludeMenu);

    // View
    viewMenu = new JMenu("View");
    viewMenu.setMnemonic('v');
    viewMenu.add(scrollToBottomMenuAction);
    viewMenu.add(pauseMenuAction);
    viewMenu.add(clearMenuAction);
    viewMenu.add(attachMenuAction);
    viewMenu.add(disconnectMenuAction);
    viewMenu.add(focusEventsAction);
    viewMenu.add(focusMessageAction);
    //viewMenu.add(statisticsMenuAction);
    viewMenu.add(editSourceNameMenuAction);
    viewMenu.addSeparator();
    viewMenu.add(zoomInMenuAction);
    viewMenu.add(zoomOutMenuAction);
    viewMenu.add(resetZoomMenuAction);
    viewMenu.addSeparator();
    JMenu layoutMenu = new JMenu("Layout");
    columnsMenu = new JMenu("Columns");
    layoutMenu.add(columnsMenu);
    layoutMenu.addSeparator();
    layoutMenu.add(saveLayoutAction);
    layoutMenu.add(resetLayoutAction);
    viewMenu.add(layoutMenu);
    viewMenu.addSeparator();
    viewMenu.add(previousTabAction);
    viewMenu.add(nextTabAction);
    viewMenu.addSeparator();
    viewMenu.add(closeFilterAction);
    viewMenu.add(closeOtherFiltersAction);
    viewMenu.add(closeAllFiltersAction);

    // Window
    windowMenu = new JMenu("Window");
    windowMenu.setMnemonic('w');

    // Help
    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic('h');

    helpMenu.add(keyboardHelpAction);
    helpMenu.add(showLoveMenuAction);
    helpMenu.add(tipOfTheDayAction);
    helpMenu.add(checkForUpdateAction);
    helpMenu.add(troubleshootingAction);
    helpMenu.addSeparator();
    helpMenu.add(debugAction);
    if (!app.isMac()) {
        helpMenu.addSeparator();
        helpMenu.add(aboutAction);
    }

    menubar.add(fileMenu);
    menubar.add(editMenu);
    menubar.add(searchMenu);
    menubar.add(viewMenu);
    menubar.add(windowMenu);
    menubar.add(helpMenu);

    updateWindowMenu();
    updateRecentFiles();
    updateActions();
}

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

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

    xLabel = new PropertyField() {
        public String newValue(String newValue) {
            setXAxisLabel(newValue);/*w  w  w  .j  a v a 2  s.  co m*/
            getChartPanel().repaint();
            return newValue;
        }
    };
    xLabel.setValue(getXAxisLabel());

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

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

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

    yLog = new JCheckBox();
    yLog.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (yLog.isSelected()) {
                LogarithmicAxis logAxis = new LogarithmicAxis(yLabel.getValue());
                logAxis.setStrictValuesFlag(false);
                ((CategoryPlot) (chart.getPlot())).setRangeAxis(logAxis);
            } else
                ((CategoryPlot) (chart.getPlot())).setRangeAxis(new NumberAxis(yLabel.getValue()));
        }
    });

    list.add(new JLabel("Y Log Axis"), yLog);

    final JCheckBox ygridlines = new JCheckBox();
    ygridlines.setSelected(false);
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(true);
            } else {
                ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(false);
            }
        }
    };
    ygridlines.addItemListener(il);

    // JFreeChart's Box Plots look awful when wide because the mean
    // circle is based on the width of the bar to the exclusion of all
    // else.  So I've restricted the width to be no more than 0.4, and 0.1
    // is the suggested default.

    final double INITIAL_WIDTH = 0.1;
    final double MAXIMUM_RATIONAL_WIDTH = 0.4;

    maximumWidthField = new NumberTextField(INITIAL_WIDTH, 2.0, 0) {
        public double newValue(double newValue) {
            if (newValue <= 0.0 || newValue > MAXIMUM_RATIONAL_WIDTH)
                newValue = currentValue;
            ((BoxAndWhiskerRenderer) (((CategoryPlot) (chart.getPlot())).getRenderer()))
                    .setMaximumBarWidth(newValue);
            //update();
            return newValue;
        }
    };
    list.addLabelled("Max Width", maximumWidthField);

    Box box = Box.createHorizontalBox();
    box.add(new JLabel(" Y"));
    box.add(ygridlines);
    box.add(Box.createGlue());
    list.add(new JLabel("Y Grid Lines"), ygridlines);

    mean = new JCheckBox();
    mean.setSelected(true);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot()))
                    .getRenderer());
            renderer.setMeanVisible(mean.isSelected());
        }
    };
    mean.addItemListener(il);

    median = new JCheckBox();
    median.setSelected(true);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot()))
                    .getRenderer());
            renderer.setMedianVisible(median.isSelected());
        }
    };
    median.addItemListener(il);

    list.add(new JLabel("Mean"), mean);
    list.add(new JLabel("Median"), median);

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

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

    final JCheckBox whiskersUseFillColorButton = new JCheckBox();
    whiskersUseFillColorButton.setSelected(false);
    whiskersUseFillColorButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot()))
                    .getRenderer());
            renderer.setUseOutlinePaintForWhiskers(!whiskersUseFillColorButton.isSelected());
        }
    });

    box = Box.createHorizontalBox();
    box.add(new JLabel(" Colored"));
    box.add(whiskersUseFillColorButton);
    box.add(Box.createGlue());
    list.add(new JLabel("Whiskers"), box);
}

From source file:net.sourceforge.entrainer.gui.socket.EntrainerSocketConnector.java

private void wireSliders() {
    entrainmentFrequency.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            setEntrainmentFrequencyValue();
            if (isActiveConnection() && !isEntrainerEntrainmentFrequencyMessage)
                sendEntrainmentFrequencyChange();
            isEntrainerEntrainmentFrequencyMessage = false;
        }/*from w w w  .  j av a 2  s .c  o  m*/
    });
    setEntrainmentFrequencyValue();

    amplitude.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            setAmplitudeValue();
            if (isActiveConnection() && !isEntrainerAmplitudeMessage)
                sendAmplitudeChange();
            isEntrainerAmplitudeMessage = false;
        }
    });
    setAmplitudeValue();

    frequency.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            setFrequencyValue();
            if (isActiveConnection() && !isEntrainerFrequencyMessage)
                sendFrequencyChange();
            isEntrainerFrequencyMessage = false;
        }
    });
    setFrequencyValue();

    pinkNoise.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            setPinkNoiseValue();
            if (isActiveConnection() && !isEntrainerPinkNoiseAmplitudeMessage)
                sendPinkNoiseChange();
            isEntrainerPinkNoiseAmplitudeMessage = false;
        }
    });
    setPinkNoiseValue();
}

From source file:io.github.jeremgamer.editor.panels.components.PanelsPanel.java

public PanelsPanel(JFrame frame, final PanelSave ps) {
    this.ps = ps;
    this.frame = frame;
    this.setSize(new Dimension(395, frame.getHeight() - 27 - 23));
    this.setLocation(300, 0);
    this.setBorder(BorderFactory.createTitledBorder("Edition du panneau"));

    JPanel content = new JPanel();
    JScrollPane scroll = new JScrollPane(content);
    scroll.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    scroll.setBorder(null);//w  w  w .j  a v a 2s .c  o  m
    content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
    scroll.setPreferredSize(new Dimension(382, frame.getHeight() - 27 - 46 - 20));

    JPanel namePanel = new JPanel();
    name.setPreferredSize(new Dimension(this.getWidth() - 280, 30));
    name.setEditable(false);
    namePanel.add(new JLabel("Nom :"));
    namePanel.add(name);
    namePanel.add(Box.createRigidArea(new Dimension(10, 1)));
    layout.addItem("Basique");
    layout.addItem("Bordures");
    layout.addItem("Ligne");
    layout.addItem("Colonne");
    layout.addItem("Grille");
    layout.addItem("Empil");
    layout.setPreferredSize(new Dimension(110, 30));
    layout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            cl.show(advanced, listContent[combo.getSelectedIndex()]);
            ps.set("layout", combo.getSelectedIndex());
            ActionPanel.updateLists();
        }

    });
    namePanel.add(new JLabel("Disposition :"));
    namePanel.add(layout);
    namePanel.setPreferredSize(new Dimension(365, 50));
    namePanel.setMaximumSize(new Dimension(365, 50));
    content.add(namePanel);

    advanced.setPreferredSize(new Dimension(365, 300));
    advanced.setMaximumSize(new Dimension(365, 300));
    advanced.add(ble, listContent[0]);
    advanced.add(brdle, listContent[1]);
    advanced.add(lle, listContent[2]);
    advanced.add(rle, listContent[3]);
    advanced.add(gle, listContent[4]);
    advanced.add(cle, listContent[5]);

    content.add(advanced);

    topBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.top", combo.getSelectedItem());
        }

    });
    leftBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.left", combo.getSelectedItem());
        }

    });
    centerBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.center", combo.getSelectedItem());
        }

    });
    rightBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.right", combo.getSelectedItem());
        }

    });
    bottomBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.bottom", combo.getSelectedItem());
        }

    });

    JPanel prefSize = new JPanel();
    prefSize.setPreferredSize(new Dimension(365, 110));
    prefSize.setMaximumSize(new Dimension(365, 110));
    prefSize.setBorder(BorderFactory.createTitledBorder("Taille prfre"));
    JPanel prefSizePanel = new JPanel();
    prefSizePanel.setLayout(new GridLayout(2, 4));
    prefSizePanel.setPreferredSize(new Dimension(300, 55));
    prefSizePanel.setMaximumSize(new Dimension(300, 55));
    prefSizePanel.add(prefSizeEnabled);
    prefSizePanel.add(new JLabel(""));
    prefSizePanel.add(new JLabel(""));
    prefSizePanel.add(new JLabel("(en pixels)"));
    prefSizePanel.add(new JLabel("Largeur :"));
    prefSizePanel.add(prefWidth);
    prefSizePanel.add(new JLabel("Hauteur :"));
    prefSizePanel.add(prefHeight);
    prefWidth.setEnabled(false);
    prefHeight.setEnabled(false);
    prefSizeEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JCheckBox check = (JCheckBox) event.getSource();
            ps.set("preferredSize", check.isSelected());
            prefWidth.setEnabled(check.isSelected());
            prefHeight.setEnabled(check.isSelected());
        }
    });
    prefWidth.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("preferredWidth", spinner.getValue());
        }
    });
    prefHeight.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("preferredHeight", spinner.getValue());
        }
    });
    prefSize.add(prefSizePanel);

    content.add(prefSize);

    JPanel insetsPanel = new JPanel();
    insetsPanel.setBorder(BorderFactory.createTitledBorder("carts"));
    insetsPanel.setPreferredSize(new Dimension(365, 100));
    insetsPanel.setMaximumSize(new Dimension(365, 100));

    JPanel insetsContent = new JPanel();
    insetsContent.setLayout(new BoxLayout(insetsContent, BoxLayout.PAGE_AXIS));

    JPanel insetInput = new JPanel();
    insetInput.setLayout(new GridLayout(2, 4));
    insetInput.add(insetsEnabled);
    insetInput.add(new JLabel(""));
    insetInput.add(new JLabel(""));
    insetInput.add(new JLabel("(en pixels)"));
    insetInput.add(new JLabel("Horizontaux :"));
    insetInput.add(insetHz);
    insetInput.add(new JLabel("Verticaux :"));
    insetInput.add(insetVt);

    insetsEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JCheckBox check = (JCheckBox) event.getSource();
            if (check.isSelected()) {
                insetHz.setEnabled(true);
                insetVt.setEnabled(true);
                ps.set("insets", true);
            } else {
                insetHz.setEnabled(true);
                insetVt.setEnabled(true);
                ps.set("insets", false);
            }
        }

    });

    insetHz.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("insets.horizontal", spinner.getValue());
        }
    });
    insetVt.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("insets.vertical", spinner.getValue());
        }
    });

    insetsContent.add(insetInput);
    insetsPanel.add(insetsContent);

    content.add(insetsPanel);

    JPanel web = new JPanel();
    web.setPreferredSize(new Dimension(365, 100));
    web.setMaximumSize(new Dimension(365, 100));
    web.setBorder(BorderFactory.createTitledBorder("Page Web"));

    JPanel webContent = new JPanel();
    webContent.setLayout(new BorderLayout());
    webContent.add(webEnabled, BorderLayout.NORTH);
    webEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox check = (JCheckBox) e.getSource();
            ps.set("web", check.isSelected());
            if (check.isSelected() == true) {
                layout.setSelectedIndex(0);
                layout.setEnabled(false);
                ble.removeAllComponents();
                ble.disableComponents();
                adress.setEnabled(true);
            } else {
                ble.enableComponents();
                layout.setEnabled(true);
                adress.setEnabled(false);
            }
        }
    });
    JPanel webInput = new JPanel();
    webInput.add(new JLabel("Adresse :"));
    adress.setPreferredSize(new Dimension(250, 30));
    CaretListener caretUpdate = new CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent e) {
            JTextField text = (JTextField) e.getSource();
            ps.set("web.adress", text.getText());
        }
    };
    adress.addCaretListener(caretUpdate);
    webInput.add(adress);
    webContent.add(webInput, BorderLayout.CENTER);

    web.add(webContent);

    JPanel background = new JPanel();
    BorderLayout bLayout = new BorderLayout();
    bLayout.setVgap(12);
    background.setLayout(bLayout);
    background.setBorder(BorderFactory.createTitledBorder("Couleur de fond"));
    background.setPreferredSize(new Dimension(365, 210));
    background.setMaximumSize(new Dimension(365, 210));
    cp.setPreferredSize(new Dimension(347, 145));
    cp.setMaximumSize(new Dimension(347, 145));
    opaque.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox check = (JCheckBox) e.getSource();
            ps.set("background.opaque", check.isSelected());
            cp.enableComponents(check.isSelected());
        }
    });
    background.add(opaque, BorderLayout.NORTH);
    background.add(cp, BorderLayout.CENTER);

    JPanel image = new JPanel();
    image.setBorder(BorderFactory.createTitledBorder("Image de fond"));
    image.setPreferredSize(new Dimension(365, 125));
    image.setMaximumSize(new Dimension(365, 125));
    image.setLayout(new BorderLayout());
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.setEnabled(false);
    remove.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            File img = new File(
                    "projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png");
            if (img.exists()) {
                img.delete();
            }
            browseImage.setEnabled(true);
        }

    });
    JPanel top = new JPanel();
    browseImage.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JButton button = (JButton) e.getSource();
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "background.png");
                nameBackground.setText(new File(path).getName());
                ps.set("background.image", new File(path).getName());
                button.setEnabled(false);
                size.setEnabled(true);
                size2.setEnabled(true);
                remove.setEnabled(true);
            }
        }

    });
    bg.add(size);
    bg.add(size2);
    JPanel sizePanel = new JPanel();
    sizePanel.setLayout(new BoxLayout(sizePanel, BoxLayout.PAGE_AXIS));
    size.setEnabled(false);
    size2.setEnabled(false);
    sizePanel.add(size);
    sizePanel.add(size2);
    size.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            ps.set("background.size", 0);
        }

    });
    size2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            ps.set("background.size", 1);
        }

    });
    top.add(browseImage);
    top.add(sizePanel);

    remove.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JButton button = (JButton) event.getSource();
            new File("projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png")
                    .delete();
            nameBackground.setText("");
            ps.set("background.image", "");
            button.setEnabled(false);
        }

    });
    nameBackground.setFont(new Font("Sans Serif", Font.PLAIN, 15));
    JPanel center = new JPanel(new BorderLayout());
    center.add(nameBackground, BorderLayout.CENTER);
    center.add(remove, BorderLayout.EAST);

    image.add(top, BorderLayout.NORTH);
    image.add(center, BorderLayout.CENTER);

    content.add(web);
    content.add(background);
    content.add(image);

    this.add(scroll);
}