⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optics_visualizer.java

📁 数据挖掘中聚类的算法
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 *    Copyright (C) 2004
 *    & Matthias Schubert (schubert@dbs.ifi.lmu.de)
 *    & Zhanna Melnikova-Albrecht (melnikov@cip.ifi.lmu.de)
 *    & Rainer Holzmann (holzmann@cip.ifi.lmu.de)
 */

package weka.clusterers.forOPTICSAndDBScan.OPTICS_GUI;

import weka.gui.LookAndFeel;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableColumn;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * <p>
 * OPTICS_Visualizer.java <br/>
 * Authors: Rainer Holzmann, Zhanna Melnikova-Albrecht <br/>
 * Date: Sep 12, 2004 <br/>
 * Time: 8:01:13 PM <br/>
 * $ Revision 1.4 $ <br/>
 * </p>
 *
 * @author Zhanna Melnikova-Albrecht (melnikov@cip.ifi.lmu.de)
 * @author Rainer Holzmann (holzmann@cip.ifi.lmu.de)
 * @version $Revision: 1.3 $
 */
public class OPTICS_Visualizer {

    /**
     * Holds the OPTICS clustering results
     */
    private SERObject serObject;

    /**
     * Main Window of the OPTICS-Visualizer
     */
    private JFrame frame;

    /**
     * Statistic-frame
     */
    private JFrame statisticsFrame;

    /**
     * Help-frame
     */
    private JFrame helpFrame;

    /**
     * Listener for menu- and toolBar actions
     */
    private FrameListener frameListener;

    /**
     * Holds the toolBar and its components
     */
    private JToolBar toolBar;
    private JButton toolBarButton_open;
    private JButton toolBarButton_save;
    private JButton toolBarButton_parameters;
    private JButton toolBarButton_help;
    private JButton toolBarButton_about;

    /**
     * Holds the default-menu and its components
     */
    private JMenuBar defaultMenuBar;
    private JMenuItem open;
    private JMenuItem save;
    private JMenuItem exit;
    private JMenuItem parameters;
    private JMenuItem help;
    private JMenuItem about;

    /**
     * Holds the tabbedPane and its components
     */
    private JTabbedPane tabbedPane;
    private JTable resultVectorTable;
    private GraphPanel graphPanel;
    private JScrollPane graphPanelScrollPane;

    /**
     * Holds the settingsPanel and its components
     */
    private JPanel settingsPanel;
    private JCheckBox showCoreDistances;
    private JCheckBox showReachabilityDistances;
    private int verValue = 30;
    private JSlider verticalSlider;
    private JButton coreDistanceColorButton;
    private JButton reachDistanceColorButton;
    private JButton graphBackgroundColorButton;
    private JButton resetColorButton;

    /**
     * FileChooser for saving- and open-actions
     */
    private JFileChooser jFileChooser;
    private String lastPath;

    // *****************************************************************************************************************
    // constructors
    // *****************************************************************************************************************

    public OPTICS_Visualizer(SERObject serObject, String title) {
        this.serObject = serObject;

        LookAndFeel.setLookAndFeel();
    
        frame = new JFrame(title);

        frame.addWindowListener(new WindowAdapter() {
            /**
             * Invoked when a window is in the process of being closed.
             * The close operation can be overridden at this point.
             */
            public void windowClosing(WindowEvent e) {
                frame.dispose();
            }
        });

        frame.getContentPane().setLayout(new BorderLayout());
        frame.setSize(new Dimension(800, 600));
        Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle windowRectangle = frame.getBounds();
        frame.setLocation((screenDimension.width - windowRectangle.width) / 2,
                (screenDimension.height - windowRectangle.height) / 2);

        frameListener = new FrameListener();
        jFileChooser = new JFileChooser();
        jFileChooser.setFileFilter(new SERFileFilter("ser", "Java Serialized Object File (*.ser)"));

        createGUI();
        frame.setVisible(true);
        frame.toFront();

    }

    // *****************************************************************************************************************
    // methods
    // *****************************************************************************************************************

    /**
     * Constructs the main-layout for the OPTICS-Visualizer
     */
    private void createGUI() {
        setMenuBar(constructDefaultMenuBar());

        frame.getContentPane().add(createToolBar(), BorderLayout.NORTH);
        frame.getContentPane().add(createTabbedPane(), BorderLayout.CENTER);
        frame.getContentPane().add(createSettingsPanel(), BorderLayout.SOUTH);
        disableSettingsPanel();
    }

    /**
     * Creates the settings-panel
     * @return Settings-panel
     */
    private JComponent createSettingsPanel() {
        settingsPanel = new JPanel(new GridBagLayout());

        SettingsPanelListener panelListener = new SettingsPanelListener();

        JPanel setPanelLeft = new JPanel(new GridBagLayout());
        setPanelLeft.setBorder(BorderFactory.createTitledBorder(" General Settings "));

        JPanel checkBoxesPanel = new JPanel(new GridLayout(1, 2));
        showCoreDistances = new JCheckBox("Show Core-Distances");
        showCoreDistances.setSelected(true);
        showReachabilityDistances = new JCheckBox("Show Reachability-Distances");
        showReachabilityDistances.setSelected(true);
        showCoreDistances.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    graphPanel.setShowCoreDistances(true);
                    graphPanel.adjustSize(serObject);
                    graphPanel.repaint();
                } else if (e.getStateChange() == ItemEvent.DESELECTED) {
                    graphPanel.setShowCoreDistances(false);
                    graphPanel.adjustSize(serObject);
                    graphPanel.repaint();
                }
            }
        });
        showReachabilityDistances.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    graphPanel.setShowReachabilityDistances(true);
                    graphPanel.adjustSize(serObject);
                    graphPanel.repaint();
                } else if (e.getStateChange() == ItemEvent.DESELECTED) {
                    graphPanel.setShowReachabilityDistances(false);
                    graphPanel.adjustSize(serObject);
                    graphPanel.repaint();
                }
            }
        });

        checkBoxesPanel.add(showCoreDistances);
        checkBoxesPanel.add(showReachabilityDistances);

        JPanel verticalAdPanel = new JPanel(new BorderLayout());
        final JLabel verValueLabel = new JLabel("Vertical Adjustment: " + verValue);
        verticalAdPanel.add(verValueLabel, BorderLayout.NORTH);
        verticalSlider = new JSlider(JSlider.HORIZONTAL, 0, frame.getHeight(), verValue);
        verticalSlider.setMajorTickSpacing(100);
        verticalSlider.setMinorTickSpacing(10);
        verticalSlider.setPaintTicks(true);
        verticalSlider.setPaintLabels(true);
        verticalSlider.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                if (!verticalSlider.getValueIsAdjusting()) {
                    verValue = verticalSlider.getValue();
                    verValueLabel.setText("Vertical Adjustment: " + verValue);
                    graphPanel.setVerticalAdjustment(verValue);
                    graphPanel.repaint();
                }
            }
        });
        verticalAdPanel.add(verticalSlider, BorderLayout.CENTER);

        setPanelLeft.add(checkBoxesPanel,
                new GridBagConstraints(0, 0, 1, 1, 1, 1,
                        GridBagConstraints.CENTER,
                        GridBagConstraints.BOTH,
                        new Insets(5, 5, 5, 5), 0, 0));
        setPanelLeft.add(verticalAdPanel,
                new GridBagConstraints(0, 1, 1, 1, 1, 1,
                        GridBagConstraints.CENTER,
                        GridBagConstraints.BOTH,
                        new Insets(5, 5, 5, 5), 0, 0));

        settingsPanel.add(setPanelLeft,
                new GridBagConstraints(0, 0, 1, 1, 3, 1,
                        GridBagConstraints.CENTER,
                        GridBagConstraints.BOTH,
                        new Insets(5, 5, 5, 0), 0, 0));

        JPanel setPanelRight = new JPanel(new GridBagLayout());
        setPanelRight.setBorder(BorderFactory.createTitledBorder(" Colors "));

        JPanel colorsPanel = new JPanel(new GridLayout(4, 2, 10, 10));

        colorsPanel.add(new JLabel("Core-Distance: "));
        coreDistanceColorButton = new JButton();
        coreDistanceColorButton.setBackground(new Color(100, 100, 100));
        coreDistanceColorButton.addActionListener(panelListener);
        colorsPanel.add(coreDistanceColorButton);

        colorsPanel.add(new JLabel("Reachability-Distance: "));
        reachDistanceColorButton = new JButton();
        reachDistanceColorButton.setBackground(Color.orange);
        reachDistanceColorButton.addActionListener(panelListener);
        colorsPanel.add(reachDistanceColorButton);

        colorsPanel.add(new JLabel("Graph Background: "));
        graphBackgroundColorButton = new JButton();
        graphBackgroundColorButton.setBackground(new Color(255, 255, 179));
        graphBackgroundColorButton.addActionListener(panelListener);
        colorsPanel.add(graphBackgroundColorButton);

        colorsPanel.add(new JLabel());
        resetColorButton = new JButton("Reset");
        resetColorButton.addActionListener(panelListener);
        colorsPanel.add(resetColorButton);

        setPanelRight.add(colorsPanel,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -