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

📄 viewschedulepanel.java

📁 The program is used for Classroom Scheduling for tutors and students. It contain gui tools for mana
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        selectivePanel.add(showAll, gbc);
        selectivePanel.add(showRoom, gbc);
        selectivePanel.add(showProfessor, gbc);
        
        // pick a room
        gbc.ipady = 10;		// vertical spaces
        
        JLabel label = new JLabel("Choose a classroom:");
        selectivePanel.add(label, gbc);
        gbc.ipady = 0;		// vertical spaces
        selectivePanel.add(roomCB, gbc);
        
        // pick a prof
        gbc.ipady = 2;		// vertical spaces
        label = new JLabel("Choose a professor:");
        selectivePanel.add(label, gbc);
        gbc.ipady = 0;		// vertical spaces
        selectivePanel.add(professorCB, gbc);
    }
    
    private void makeTableChartPanel(JPanel tableChartPanel) {
        titledBorder = BorderFactory.createTitledBorder(border, " View As ");
        tableChartPanel.setBorder(titledBorder);
        
        tableChartPanel.setLayout(new GridBagLayout());
        gbc = startingGBC();
        
        tableChartPanel.add(tableButton, gbc);
        tableChartPanel.add(chartButton, gbc);
    }
    
    private void makePrintPanel(JPanel printPanel) {
        titledBorder = BorderFactory.createTitledBorder(border, " Print ");
        printPanel.setBorder(titledBorder);
        
        printPanel.setLayout(new GridBagLayout());
        gbc = startingGBC();
        
        gbc.insets = new Insets(5,8,5,8);
        printPanel.add(printView, gbc);
        printPanel.add(printAll, gbc);
    }
    
    
    // These constraints are used for interior panels that are generally
    // using a vertical layout.  The constratins object needs to be modified
    // to allow for different sized components to be added, ie, change the weightx
    
    protected static GridBagConstraints startingGBC() {
        GridBagConstraints gbc = new GridBagConstraints();
        
        gbc.weightx = 0.0;
        gbc.gridheight = 1;
        gbc.ipady = 0;		// vertical spaces  was 2
        gbc.ipadx = 0;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        
        return gbc;
    }
    
    private void addToolTips() {
        
        
    }
    
    private void addListeners() {
        ListenToWhatToShow whatToShowListener = new ListenToWhatToShow();
        
        tableButton.addActionListener(whatToShowListener);
        chartButton.addActionListener(whatToShowListener);
        showAll.addActionListener(whatToShowListener);
        showRoom.addActionListener(whatToShowListener);
        showProfessor.addActionListener(whatToShowListener);
        roomCB.addActionListener(whatToShowListener);
        professorCB.addActionListener(whatToShowListener);
        printView.addActionListener(whatToShowListener);
        printAll.addActionListener(whatToShowListener);
    }
    
    // this is a helper for the actionListener
    
    private void printTheView(Pageable toPrint, boolean confirm) {
        
        PrinterJob printJob = PrinterJob.getPrinterJob();  // Get a printing object
        printJob.setPageable(toPrint);    // The schedule is printable
        
        if (confirm) {
            if (printJob.printDialog())   // Display print dialog
            {                                        // If true is returned...
                try {
                    printJob.print();                // then print
                }
                catch(PrinterException pe) {
                    System.out.println(pe);
                    JOptionPane.showMessageDialog(ClassroomScheduler.getFrame(),
                    "Error printing a schedule.",
                    "Unknown Printer Error",
                    JOptionPane.ERROR_MESSAGE);
                }
            }
        } else {
            try {
                printJob.print();                // then print
            }
            catch(PrinterException pe) {
                System.out.println(pe);
                JOptionPane.showMessageDialog(ClassroomScheduler.getFrame(),
                "Error printing a schedule.", "Unknown Printer Error",
                JOptionPane.ERROR_MESSAGE);
            }
        }
    }
    
    class ListenToWhatToShow implements ActionListener {
        
        public void actionPerformed(ActionEvent ae) {
            if (ae.getActionCommand() == "Table") {
                cardLayout.show(leftPanel,"Table");
                showAll.setEnabled(true);
                showAll.setSelected(true);
                roomCB.setEnabled(false);
                professorCB.setEnabled(false);
                printAll.setEnabled(false);
            }
            
            if (ae.getActionCommand() == "Time Chart") {
                cardLayout.show(leftPanel, "Chart");
                showAll.setEnabled(false);
                
                // select the room radio button in second panel
                showRoom.setSelected(true);
                roomCB.setEnabled(true);
                professorCB.setEnabled(false);
                viewGraphSched.setViewRoom((Classroom) (roomCB.getSelectedItem()));
                printAll.setEnabled(true);
            }
            
            if (ae.getActionCommand() == "All") {
                roomCB.setEnabled(false);
                professorCB.setEnabled(false);
            }
            
            if (ae.getActionCommand() == "Room") {
                roomCB.setEnabled(true);
                professorCB.setEnabled(false);
            }
            
            if (ae.getActionCommand() == "Professor") {
                roomCB.setEnabled(false);
                professorCB.setEnabled(true);
            }
            
            // if its a graphical view
            if (chartButton.isSelected()) {
                if (ae.getActionCommand() == "Professor")
                    viewGraphSched.setViewProf((Professor) (professorCB.getSelectedItem()));
                if (ae.getActionCommand() == "Room")
                    viewGraphSched.setViewRoom((Classroom) (roomCB.getSelectedItem()));
                if (ae.getSource() == roomCB)
                    viewGraphSched.setViewRoom((Classroom) (roomCB.getSelectedItem()));
                if (ae.getSource() == professorCB)
                    viewGraphSched.setViewProf((Professor) (professorCB.getSelectedItem()));
            }
            
            if (ae.getActionCommand() == " Print This View ") {
                if (chartButton.isSelected()) {
                    printTheView(viewGraphSched, true);
                } else {
                    printTheView(schedule, true);
                }
            }
            
            if (ae.getActionCommand() == " Print All Similar Views ") {
                if (!chartButton.isSelected())  // only for charts
                    return;
                
                if (showRoom.isSelected()) {
                    System.out.println("Print all the rooms");
                    
                    Iterator it = schedule.getClassrooms().iterator();
                    while (it.hasNext()) {
                        viewGraphSched.setViewRoom((Classroom)(it.next()));
                        printTheView(viewGraphSched, false);
                        
                    }
                    
                }
                
                if (showProfessor.isSelected()) {
                    System.out.println("Print all the full time profs");
                    
                    Iterator it = schedule.getProfessors().iterator();
                    while (it.hasNext()) {
                        Professor p = (Professor)(it.next());
                        if ( p.getStatus() == Professor.FULL_TIME) {
                            viewGraphSched.setViewProf(p);
                            printTheView(viewGraphSched, false);
                        }
                    }
                    
                }
                
            }
        }
    }
}

⌨️ 快捷键说明

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