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

📄 designingpanel.java

📁 SWING的界面UI包 SWING的界面UI包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            menuBar = new JMenuBar();
            menuFile = getMenuFile();
            menuBar.add(menuFile);
            menuEdit = getMenuEdit();
            menuBar.add(menuEdit);
            menuHelp = getMenuHelp();
            menuBar.add(menuHelp);
        }
        return menuBar;
    }

    private JMenu getMenuEdit() {
        if (menuEdit == null) {
            menuEdit = new JMenu("Edit");
            boolean first = true;
            Action[] actions = designer.getActions();
            for (Action action : actions) {
                if (action instanceof ActionCategory) {
                    if (first) {
                        first = false;
                    } else {
                        menuEdit.addSeparator();
                    }
                    Action[] subs = ((ActionCategory) action).getSubActions();
                    for (Action sub : subs) {
                        menuEdit.add(sub);
                    }
                } else {
                    menuEdit.add(action);
                }
            }
        }
        return menuEdit;
    }
    private Action newFileAction;

    private Action getNewFileAction() {
        if (newFileAction == null) {
            newFileAction = new NewFileAction(this);
        }
        return newFileAction;
    }
    private Action openFileAction;

    private Action getOpenFileAction() {
        if (openFileAction == null) {
            openFileAction = new OpenFileAction(this);
        }
        return openFileAction;
    }
    private Action saveFileAction;

    private Action getSaveFileAction() {
        if (saveFileAction == null) {
            saveFileAction = new SaveFileAction(this);
        }
        return saveFileAction;
    }
    private Action saveAsFileAction;

    private Action getSaveAsFileAction() {
        if (saveAsFileAction == null) {
            saveAsFileAction = new SaveAsFileAction(this);
        }
        return saveAsFileAction;
    }

    private Action[] getFileActions() {

        return new Action[]{getNewFileAction(), getOpenFileAction(), getSaveFileAction(), getSaveAsFileAction()};
    }

    private JMenu getMenuFile() {
        if (menuFile == null) {
            menuFile = new JMenu();
            menuFile.setText("File");

            for (Action action : getFileActions()) {
                menuFile.add(action);
            }
            menuFile.addSeparator();
            menuFile.add(new ExitAction(this));
        }
        return menuFile;
    }

    private JMenu getMenuHelp() {
        if (menuHelp == null) {
            menuHelp = new JMenu();
            menuHelp.setText("Help");
            menuHelp.add(new AboutAction(this));
        }
        return menuHelp;
    }

    void newPanel() {
        Item item=Util.getDefaultGuiType();
        new NewFileWorker(this, null, (String)item.getValue(), item).execute();
    }

    public CodeSeed getSeed() {
        return seed;
    }

    private JTabbedPane getOutlineTab() {
        if (outlineTab == null) {
            outlineTab = new JTabbedPane();
            outlineTab.setTabPlacement(JTabbedPane.BOTTOM);
            spGuiPanel = getSpGuiPanel();
            outlineTab.addTab("GUI Designer", spGuiPanel);
            spSourceCode = getSpSourceCode();
            outlineTab.addTab("Source Code", spSourceCode);
            outlineTab.addChangeListener(new ChangeListener() {

                        @Override
                public void stateChanged(ChangeEvent e) {
                            outlineStateChanged(e);
                        }
                    });
        }
        return outlineTab;
    }

    private void outlineStateChanged(ChangeEvent e) {
        if (dirty) {
            int index = outlineTab.getSelectedIndex();
            if (index == 0) {
                seed.setSourceCode(txtSource.getText());
                SourceParser worker = new SourceParser(this);
                worker.execute();
            } else {
                new SourceWorker(this).execute();
            }
        }
    }

    public boolean isDesigningGUI() {
        return outlineTab.getSelectedIndex() == 0;
    }

    private JPanel getGuiDsgPanel() {
        if (guiDsgPanel == null) {
            guiDsgPanel = new JPanel(new BorderLayout());
            outlineTab = getOutlineTab();
            guiDsgPanel.add(outlineTab, BorderLayout.CENTER);
            designerTools = getDesignerTools();
            guiDsgPanel.add(designerTools, BorderLayout.NORTH);
        }
        return guiDsgPanel;
    }

    private JPanel getSpGuiPanel() {
        if (spGuiPanel == null) {
            spGuiPanel = new JPanel(new DesigningPanelLayout());
            spOverall = getSpOverall();
            spGuiPanel.add(spOverall);
        }
        return spGuiPanel;
    }

    private JScrollPane getSpSourceCode() {
        if (spSourceCode == null) {
            spSourceCode = new JScrollPane();
            txtSource = getTxtSource();
            spSourceCode.setViewportView(txtSource);
        }
        return spSourceCode;
    }

    public JTextArea getTxtSource() {
        if (txtSource == null) {
            txtSource = new JTextArea();
            txtSource.setFont(new Font("DialogInput", 0, 12));
            txtSource.setTabSize(4);
            txtSource.getDocument().addDocumentListener(new DocumentListener() {

                        @Override
                public void insertUpdate(DocumentEvent e) {
                            if (!dirty) {
                                setDirty(true);
                            }
                        }

                        @Override
                public void removeUpdate(DocumentEvent e) {
                            if (!dirty) {
                                setDirty(true);
                            }
                        }

                        @Override
                public void changedUpdate(DocumentEvent e) {
                            if (!dirty) {
                                setDirty(true);
                            }
                        }
                    });
        }
        return txtSource;
    }

    private void paletteActionPerformed(java.awt.event.ActionEvent evt) {
        if (designer.isAddingMode()) {
            designer.stopAddingState();
        }
        BeanInfoToggleButton tb = (BeanInfoToggleButton) evt.getSource();
        if (tb.isSelected()) {
            designer.startAddingState(tb.getBeanInfo());
        }
    }

    private class DesigningPanelLayout implements LayoutManager {

        public void addLayoutComponent(String name, Component comp) {
        }

        public void removeLayoutComponent(Component comp) {
        }

        public Dimension preferredLayoutSize(Container parent) {
            return new Dimension(100, 100);
        }

        public Dimension minimumLayoutSize(Container parent) {
            return new Dimension(0, 0);
        }

        public void layoutContainer(Container parent) {
            int w = parent.getWidth();
            int h = parent.getHeight();
            spOverall.setBounds(0, 0, w, h);
            int dl = (int) (overallRatio * w);
            spOverall.setDividerLocation(dl);
            dl = (int) (overallRatio * w * toolkitRatio);
            spToolkit.setDividerLocation(dl);
            dl = (int) (middleRatio * h);
            spMiddle.setDividerLocation(dl);
            SwingUtilities.updateComponentTreeUI(spOverall);

            spOverall.setDividerSize(5);
            spOverall.setBorder(null);
            ((BasicSplitPaneUI) spOverall.getUI()).getDivider().setBorder(null);
            spToolkit.setDividerSize(5);
            spToolkit.setBorder(null);
            ((BasicSplitPaneUI) spToolkit.getUI()).getDivider().setBorder(null);
            spMiddle.setDividerSize(5);
            spMiddle.setBorder(null);
            ((BasicSplitPaneUI) spMiddle.getUI()).getDivider().setBorder(null);
            spDesigner.setBorder(null);
            spDesigner.getViewport().setBorder(null);
        }
    }
    private SwingDesigner designer;
    private JToolBar designerTools;
    private JPanel dsgPanel;
    private ComponentPalette palette;
    private TreePalette rightPalette;
    private LoggingPanel logger;
    private JSplitPane spOverall;
    private JSplitPane spToolkit;
    private JSplitPane spMiddle;
    private JTabbedPane outlineTab;
    private JScrollPane spSourceCode;
    private JTextArea txtSource;
    private JPanel guiDsgPanel;
    private JPanel spGuiPanel;
    private JMenuBar menuBar;
    private JMenu menuFile;
    private JMenu menuHelp;
    private JScrollPane spDesigner;
    private JPanel cardPanel;
    private ProgressPanel pPanel;
    private JMenu menuEdit;
}

⌨️ 快捷键说明

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