📄 dialogfactory.java
字号:
/**
* Copyright (C) 2006, Laboratorio di Valutazione delle Prestazioni - Politecnico di Milano
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package jmt.gui.jmodel;
import jmt.gui.wizard.WizardPanel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* <p>Title: Parameter selection Dialog Factory</p>
* <p>Description: Creates a modal dialog box into main window that displays given
* panel. This class is used to enter imput parameters of the model.</p>
*
* @author Bertoli Marco
* Date: 2-giu-2005
* Time: 19.52.26
*/
public class DialogFactory {
// Dimensions
private static final int width = 720;
private static final int height = 520;
// Private variables
private static JDialog dialogFrame;
private static JFrame mainWindow;
private static void createDialog() {
// Creates modal dialog
dialogFrame = new JDialog(mainWindow, true);
dialogFrame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
Dimension scrDim = Toolkit.getDefaultToolkit().getScreenSize();
dialogFrame.setBounds((scrDim.width-width)/2,(scrDim.height-height)/2,width,height);
//dialogFrame.setResizable(false);
dialogFrame.getContentPane().setLayout(new BorderLayout());
//Adds button bar
JPanel buttonbar = new JPanel(new FlowLayout());
dialogFrame.getContentPane().add(buttonbar, BorderLayout.SOUTH);
// Adds Close button
JButton closebutton = new JButton();
closebutton.setText("Done");
closebutton.setToolTipText("Closes this window");
closebutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// If this contains wizard panels, calls lostFocus() method
for (int i=0; i<dialogFrame.getContentPane().getComponentCount(); i++) {
Component cmp = dialogFrame.getContentPane().getComponent(i);
if (cmp instanceof WizardPanel) {
((WizardPanel)cmp).lostFocus();
}
}
dialogFrame.dispose();
}
});
buttonbar.add(closebutton);
}
/**
* Returns modal dialog box showing given panel and with given title
* @param panel to be shown on the center area of this dialog
* @param title title of this dialog
*/
public static void getDialog(final JComponent panel, String title) {
createDialog();
// Adds input panel
dialogFrame.getContentPane().add(panel, BorderLayout.CENTER);
// Sets title
if (title != null)
dialogFrame.setTitle(title);
// If this is a wizard panel call gotFocus() method
if (panel instanceof WizardPanel) {
((WizardPanel)panel).gotFocus();
}
// Shows dialog
dialogFrame.show();
}
/**
* Sets owner frame for created dialogs
* @param f current main window
*/
public static void setOwner(JFrame f) {
mainWindow = f;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -