📄 mainframe.java
字号:
/** * Copyright 2004 Carlos Silva A. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */package jgantt.view;import java.awt.BorderLayout;import java.awt.Dimension;import java.io.File;import java.util.Hashtable;import javax.swing.JFrame;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import jgantt.MenuBuilder;import jgantt.Messages;import jgantt.model.IOManager;import jgantt.model.Project;import jgantt.model.ProjectChange;import jgantt.model.ProjectListener;import jgantt.view.adapters.ProjectViewModel;import jgantt.view.adapters.ProjectViewModelChange;import jgantt.view.adapters.ProjectViewModelListener;/** * MainFrame, ventana principal * <p> * $Date: 2005/08/19 15:51:08 $ * </p> * * @version $Revision: 1.43 $ * @author Carlos Silva */public class MainFrame extends JFrame implements ProjectListener, ProjectViewModelListener { private static final long serialVersionUID = 1L; String WND_TITLE = Messages.getString("MainFrame.title"); // / Main display GanttDisplay ganttDisplay; // / ViewModel ProjectViewModel pvModel = null; /** * Acceso a los menues segun su nombre. Relaciona el string del commando con * el JMenuItem */ protected Hashtable menues = new Hashtable(); /** * Crea una ventana para editar un proyecto nuevo */ public MainFrame() { this(IOManager.createEmptyProject(), null); } /** * Crea una ventana para editar un proyecto existente almacenado en un * archivo. Crear el display y asigna los listener. */ public MainFrame(Project project, File file) { super(""); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pvModel = new ProjectViewModel(project, file); ganttDisplay = new GanttDisplay(pvModel); GanttActionListener mainListener = pvModel.getMainActionListener(); mainListener.setup(this, ganttDisplay); getContentPane().add(ganttDisplay, BorderLayout.CENTER); JMenuBar menuBar = MenuBuilder.buildMenuBar(mainListener, "menubar", menues); setJMenuBar(menuBar); // TODO Agregar ultimos archivos abiertos. updateUndoRedo(); pvModel.addListener(this); project.addListener(this); setSize(new Dimension(850, 500)); } /** * Obtiene una referencia al menu que representa un comando * * @param cmd * @return */ public JMenuItem getMenuItemForCommand(String cmd) { return (JMenuItem) menues.get(cmd); } /** * Cuando hay un nuevo proyecto cargado... se debe reasignar el listener * * @see jgantt.view.adapters.ProjectViewModelListener#viewModelChanged(jgantt.view.adapters.ProjectViewModelChange) */ public void viewModelChanged(ProjectViewModelChange c) { if (c.getId() == ProjectViewModelChange.NEW_PROJECT_LOADED) c.getProjectViewModel().getProject().addListener(this); } /** * Cuando cambia el proyecto se debe habilitar/deshabilitar undo y redo * * @see jgantt.model.ProjectListener#projectChanged(jgantt.model.ProjectChange) */ public void projectChanged(ProjectChange c) { updateUndoRedo(); } /** * Habilita o deshabilita los menues de undo y redo */ void updateUndoRedo() { Project project = pvModel.getProject(); JMenuItem undoItem = getMenuItemForCommand(GanttActionListener.CMD_EDIT_UNDO); undoItem.setEnabled(!project.isUndoEmpty()); updWindowTitle(); JMenuItem redoItem = getMenuItemForCommand(GanttActionListener.CMD_EDIT_REDO); redoItem.setEnabled(!project.isRedoEmpty()); } /** * Cambia el titulo de la ventana */ public void updWindowTitle() { String fn; if (pvModel.getFile() != null) fn = pvModel.getFile().getName(); else fn = "(not saved)"; String t = pvModel.getProject().getName() + " - " + fn + " - " + WND_TITLE; if (!pvModel.getProject().isUndoEmpty()) t = t + " * "; if (!t.equals(getTitle())) setTitle(t); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -