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

📄 optics_visualizer.java

📁 数据挖掘中聚类的算法
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                if (e.getActionCommand().equals("OK")) {
                    statisticsFrame.dispose();
                }
            }
        });
        okButtonPanel.add(okButton,
                new GridBagConstraints(0, 0, 1, 1, 1, 1,
                        GridBagConstraints.CENTER,
                        GridBagConstraints.NONE,
                        new Insets(5, 0, 5, 0), 0, 0));

        statisticsFrame.getContentPane().add(okButtonPanel, BorderLayout.SOUTH);
        statisticsFrame.setSize(new Dimension(500, 300));
        Rectangle frameDimension = frame.getBounds();
        Point p = frame.getLocation();
        Rectangle statisticsFrameDimension = statisticsFrame.getBounds();
        statisticsFrame.setLocation(((frameDimension.width - statisticsFrameDimension.width) / 2) + (int) p.getX(),
                ((frameDimension.height - statisticsFrameDimension.height) / 2) + (int) p.getY());
        statisticsFrame.setVisible(true);
        statisticsFrame.toFront();
    }

    /**
     * Shows a little frame with information about handling the OPTICS Visualizer
     */
    private void loadHelpFrame() {
        helpFrame = new JFrame("Help Topics");
        helpFrame.getContentPane().setLayout(new BorderLayout());

        JPanel helpPanel = new JPanel(new GridBagLayout());
        JTextArea helpTextArea = new JTextArea();
        helpTextArea.setEditable(false);
        helpTextArea.append(
                "OPTICS Visualizer Help\n"
                + "===========================================================\n\n"
                + "Open\n"
                + " - Open OPTICS-Session\n"
                + "   [Ctrl-O], File | Open\n\n"
                + "Save\n"
                + " - Save OPTICS-Session\n"
                + "   [Ctrl-S], File | Save\n\n"
                + "Exit\n"
                + " - Exit OPTICS Visualizer\n"
                + "   [Alt-F4], File | Exit\n\n"
                + "Parameters\n"
                + " - Show epsilon, MinPoints...\n"
                + "   [Ctrl-P], View | Parameters\n\n"
                + "Help Topics\n"
                + " - Show this frame\n"
                + "   [Ctrl-H], Help | Help Topics\n\n"
                + "About\n"
                + " - Copyright-Information\n"
                + "   [Ctrl-A], Help | About\n\n\n"
                + "Table-Pane:\n"
                + "-----------------------------------------------------------\n"
                + "The table represents the calculated clustering-order.\n"
                + "To save the table please select File | Save from the\n"
                + "menubar. Restart OPTICS with the -F option to obtain\n"
                + "an ASCII-formatted file of the clustering-order.\n\n"
                + "Graph-Pane:\n"
                + "-----------------------------------------------------------\n"
                + "The graph draws the plot of core- and reachability-\n"
                + "distances. By (de-)activating core- and reachability-\n"
                + "distances in the 'General Settings'-Panel you can\n"
                + "influence the visualization in detail. Simply use the\n"
                + "'Vertical Adjustment'-Slider to emphasize the plot of\n"
                + "distances. The 'Colors'-Panel lets you define different\n"
                + "colors of the graph background, core- and reachability-\n"
                + "distances. Click the 'Reset'-Button to restore the\n"
                + "defaults.\n"
        );
        final JScrollPane helpTextAreaScrollPane = new JScrollPane(helpTextArea,
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        helpTextAreaScrollPane.setBorder(BorderFactory.createEtchedBorder());
        helpPanel.add(helpTextAreaScrollPane,
                new GridBagConstraints(0, 0, 1, 1, 1, 1,
                        GridBagConstraints.CENTER,
                        GridBagConstraints.BOTH,
                        new Insets(5, 5, 7, 5), 0, 0));

        helpFrame.getContentPane().add(helpPanel, BorderLayout.CENTER);

        helpFrame.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) {
                helpFrame.dispose();
            }

            /**
             * Invoked when a window has been opened.
             */
            public void windowOpened(WindowEvent e) {
                helpTextAreaScrollPane.getVerticalScrollBar().setValue(0);
            }
        });

        JPanel closeButtonPanel = new JPanel(new GridBagLayout());

        JButton closeButton = new JButton("Close");
        closeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (e.getActionCommand().equals("Close")) {
                    helpFrame.dispose();
                }
            }
        });
        closeButtonPanel.add(closeButton,
                new GridBagConstraints(0, 0, 1, 1, 1, 1,
                        GridBagConstraints.CENTER,
                        GridBagConstraints.NONE,
                        new Insets(0, 0, 5, 0), 0, 0));

        helpFrame.getContentPane().add(closeButtonPanel, BorderLayout.SOUTH);
        helpFrame.setSize(new Dimension(480, 400));
        Rectangle frameDimension = frame.getBounds();
        Point p = frame.getLocation();
        Rectangle helpFrameDimension = helpFrame.getBounds();
        helpFrame.setLocation(((frameDimension.width - helpFrameDimension.width) / 2) + (int) p.getX(),
                ((frameDimension.height - helpFrameDimension.height) / 2) + (int) p.getY());
        helpFrame.setVisible(true);
        helpFrame.toFront();
    }

    // *****************************************************************************************************************
    // inner classes
    // *****************************************************************************************************************

    private class FrameListener implements ActionListener {
        /**
         * Invoked when an action occurs.
         */
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == parameters || e.getSource() == toolBarButton_parameters) {
                loadStatisticsFrame();
            }

            if (e.getSource() == about || e.getSource() == toolBarButton_about) {
                JOptionPane.showMessageDialog(frame,
                        "OPTICS Visualizer\n$ Rev 1.4 $\n\nCopyright (C) 2004 " +
                        "Rainer Holzmann, Zhanna Melnikova-Albrecht",
                        "About", JOptionPane.INFORMATION_MESSAGE);
            }

            if (e.getSource() == help || e.getSource() == toolBarButton_help) {
                loadHelpFrame();
            }

            if (e.getSource() == exit) {
                frame.dispose();
            }

            if (e.getSource() == open || e.getSource() == toolBarButton_open) {
                jFileChooser.setDialogTitle("Open OPTICS-Session");
                if (lastPath == null) {
                    lastPath = System.getProperty("user.dir");
                }
                jFileChooser.setCurrentDirectory(new File(lastPath));
                int ret = jFileChooser.showOpenDialog(frame);
                SERObject serObject_1 = null;
                if (ret == JFileChooser.APPROVE_OPTION) {
                    File f = jFileChooser.getSelectedFile();
                    try {
                        FileInputStream fs = new FileInputStream(f.getAbsolutePath());
                        ObjectInputStream is = new ObjectInputStream(fs);
                        serObject_1 = (SERObject) is.readObject();
                        is.close();
                    } catch (FileNotFoundException e1) {
                        JOptionPane.showMessageDialog(frame,
                                "File not found.",
                                "Error", JOptionPane.ERROR_MESSAGE);
                    } catch (ClassNotFoundException e1) {
                        JOptionPane.showMessageDialog(frame,
                                "OPTICS-Session could not be read.",
                                "Error", JOptionPane.ERROR_MESSAGE);
                    } catch (IOException e1) {
                        JOptionPane.showMessageDialog(frame,
                                "This file does not contain a valid OPTICS-Session.",
                                "Error", JOptionPane.ERROR_MESSAGE);
                    }
                    if (serObject_1 != null) {
                        int ret_1 = JOptionPane.showConfirmDialog(frame,
                                "Open OPTICS-Session in a new window?",
                                "Open", 1);
                        switch (ret_1) {
                            case 0:
                                new OPTICS_Visualizer(serObject_1, "OPTICS Visualizer - " + f.getName());
                                break;
                            case 1:
                                serObject = serObject_1;
                                resultVectorTable.setModel(new ResultVectorTableModel(serObject.getResultVector()));
                                tabbedPane.setTitleAt(1,
                                        "Graph - Epsilon: " + serObject.getEpsilon() +
                                        ", MinPoints: " + serObject.getMinPoints());
                                graphPanel.setResultVector(serObject.getResultVector());
                                graphPanel.adjustSize(serObject);
                                graphPanel.repaint();
                                break;
                            default:
                                break;
                        }
                    }
                }
            }

            if (e.getSource() == save || e.getSource() == toolBarButton_save) {
                jFileChooser.setDialogTitle("Save OPTICS-Session");

                GregorianCalendar gregorianCalendar = new GregorianCalendar();
                String timeStamp = gregorianCalendar.get(Calendar.DAY_OF_MONTH) + "-" +
                        (gregorianCalendar.get(Calendar.MONTH) + 1) +
                        "-" + gregorianCalendar.get(Calendar.YEAR) +
                        "--" + gregorianCalendar.get(Calendar.HOUR_OF_DAY) +
                        "-" + gregorianCalendar.get(Calendar.MINUTE) +
                        "-" + gregorianCalendar.get(Calendar.SECOND);
                String filename = "OPTICS_" + timeStamp + ".ser";

                File file = new File(filename);
                jFileChooser.setSelectedFile(file);
                if (lastPath == null) {
                    lastPath = System.getProperty("user.dir");
                }
                jFileChooser.setCurrentDirectory(new File(lastPath));

                int ret = jFileChooser.showSaveDialog(frame);
                if (ret == JFileChooser.APPROVE_OPTION) {
                    file = jFileChooser.getSelectedFile();
                    try {
                        FileOutputStream fs = new FileOutputStream(file.getAbsolutePath());
                        ObjectOutputStream os = new ObjectOutputStream(fs);
                        os.writeObject(serObject);
                        os.flush();
                        os.close();
                    } catch (IOException e1) {
                        JOptionPane.showMessageDialog(frame,
                                "OPTICS-Session could not be saved.",
                                "Error", JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        }
    }

    private class SettingsPanelListener implements ActionListener {
        /**
         * Invoked when an action occurs.
         */
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == coreDistanceColorButton) {
                Color c = getSelectedColor("Select 'Core-Distance' color");
                if (c != null) {
                    coreDistanceColorButton.setBackground(c);
                    graphPanel.setCoreDistanceColor(c);
                }
            }
            if (e.getSource() == reachDistanceColorButton) {
                Color c = getSelectedColor("Select 'Reachability-Distance' color");
                if (c != null) {
                    reachDistanceColorButton.setBackground(c);
                    graphPanel.setReachabilityDistanceColor(c);
                }
            }
            if (e.getSource() == graphBackgroundColorButton) {
                Color c = getSelectedColor("Select 'Graph Background' color");
                if (c != null) {
                    graphBackgroundColorButton.setBackground(c);
                    graphPanel.setBackground(c);
                }
            }
            if (e.getSource() == resetColorButton) {
                coreDistanceColorButton.setBackground(new Color(100, 100, 100));
                graphPanel.setCoreDistanceColor(new Color(100, 100, 100));
                reachDistanceColorButton.setBackground(Color.orange);
                graphPanel.setReachabilityDistanceColor(Color.orange);
                graphBackgroundColorButton.setBackground(new Color(255, 255, 179));
                graphPanel.setBackground(new Color(255, 255, 179));
                graphPanel.repaint();
            }
        }

        private Color getSelectedColor(String title) {
            Color c = JColorChooser.showDialog(frame, title, Color.black);
            return c;
        }
    }

}

⌨️ 快捷键说明

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