📄 globalsettingdialog.java
字号:
/**
* $Id:GlobalSettingDialog.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved. *
*/
package com.jfimagine.jfdraw.gui.dialog;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Container;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.ImageIcon;
import javax.swing.ListCellRenderer;
import javax.swing.JList;
import javax.swing.JColorChooser;
import com.jfimagine.jfgraph.shape.union.JFPage;
import com.jfimagine.jfdraw.gui.ToolFactory;
import com.jfimagine.jfdraw.gui.resource.CADResource;
import com.jfimagine.jfdraw.gui.GUIConst;
import com.jfimagine.jfdraw.gui.GlobalSettings;
import com.jfimagine.jfgraph.shape.base.ShapeConst;
/**
* GlobalSettingDialog class. A class is used to place global settings.
*
* @author CookieMaker
*
* @version $Revision: 1.1.1 $
*/
public class GlobalSettingDialog extends JDialog
implements ActionListener {
private static GlobalSettingDialog m_dialog;
private static GlobalSettings m_settings;
private JComboBox measureCombo;
private static boolean m_modified =false;
String [] measureItems = {
CADResource.getString("label.globalsetting.measure.english"),
CADResource.getString("label.globalsetting.measure.metric")
};
//export/print with grid, or ruler.
private JCheckBox exportWithGridCheck;
private JCheckBox exportWithRulerCheck;
/**
* Open an page setting modifier window, to modify the line format.
*
* @param modalFrame Determines which frame the dialog depends on; it should be
* a component in the dialog's controlling frame.
*
* @param settings A global settings variable.
* @return True if modified page, false otherwise.
*/
public static boolean newGlobalSetting(Frame modalFrame,GlobalSettings settings) {
return newGlobalSetting(modalFrame,null,settings);
}
/**
* Open an page setting modifier window, to modify the line format.
*
* @param modalFrame Determines which frame the dialog depends on; it should be
* a component in the dialog's controlling frame.
*
* @param refComp This should be null if you want the dialog
* to come up with its left corner in the center of the screen;
* otherwise, it should be the component on top of which the
* dialog should appear.
*
* @param settings A global settings variable.
*
* @return True if modified page, false otherwise.
*/
public static boolean newGlobalSetting(Frame modalFrame,Component refComp,GlobalSettings settings) {
return showDialog(modalFrame,refComp,settings);
}
/**
* Set up and show the dialog. The first Component argument
* determines which frame the dialog depends on; it should be
* a component in the dialog's controlling frame. The second
* Component argument should be null if you want the dialog
* to come up with its left corner in the center of the screen;
* otherwise, it should be the component on top of which the
* dialog should appear.
*/
private static boolean showDialog(Component frameComp,
Component locationComp,
GlobalSettings settings) {
Frame frame = JOptionPane.getFrameForComponent(frameComp);
m_dialog = new GlobalSettingDialog(frame,
locationComp,
CADResource.getString("dialog.globalsetting"),
settings);
m_modified =false;
m_dialog.setVisible(true);
return m_modified;
}
private GlobalSettingDialog(Frame frame,
Component locationComp,
String title,
GlobalSettings settings) {
super(frame, title, true);
setResizable(false);
m_settings =settings;
//Create and initialize the buttons.
JButton cancelButton = new JButton(CADResource.getString("button.cancel"));
cancelButton.setFont(GUIConst.FONT_BUTTON);
cancelButton.addActionListener(this);
//
final JButton confirmButton = new JButton(CADResource.getString("button.confirm"));
confirmButton.setFont(GUIConst.FONT_BUTTON);
confirmButton.setActionCommand("Confirm");
confirmButton.addActionListener(this);
getRootPane().setDefaultButton(confirmButton);
//main part of the dialog
JLabel measureLabel =new JLabel(CADResource.getString("label.globalsetting.measure"));
measureLabel.setFont(GUIConst.FONT_LABEL);
measureLabel.setPreferredSize(new Dimension(60,25));
measureCombo =new JComboBox(measureItems);
measureCombo.setFont(GUIConst.FONT_LABEL);
measureCombo.setPreferredSize(new Dimension(20,25));
measureCombo.setEditable(false);
switch (settings.getMeasure()){
case ShapeConst.MEASURE_ENGLISH:
measureCombo.setSelectedIndex(0);
break;
case ShapeConst.MEASURE_METRIC:
measureCombo.setSelectedIndex(1);
break;
}
//export/print with grid , or ruler checkboxes.
exportWithGridCheck =new JCheckBox(CADResource.getString("label.globalsetting.exportWithGrid"));
exportWithGridCheck.setFont(GUIConst.FONT_LABEL);
exportWithGridCheck.setSelected(settings.isExportWithGrid());
exportWithGridCheck.setAlignmentX(LEFT_ALIGNMENT);
exportWithRulerCheck =new JCheckBox(CADResource.getString("label.globalsetting.exportWithRuler"));
exportWithRulerCheck.setFont(GUIConst.FONT_LABEL);
exportWithRulerCheck.setSelected(settings.isExportWithRuler());
exportWithRulerCheck.setAlignmentX(LEFT_ALIGNMENT);
//add items to measureContainer.
JPanel measureContainer =new JPanel();
measureContainer.setLayout(new BoxLayout(measureContainer,BoxLayout.X_AXIS));
measureContainer.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
measureContainer.add(measureLabel);
measureContainer.add(Box.createRigidArea(new Dimension(5,0)));
measureContainer.add(measureCombo);
measureContainer.setAlignmentX(LEFT_ALIGNMENT);
//add items to container.
JPanel container =new JPanel();
container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS));
container.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
container.add(measureContainer);
container.add(Box.createRigidArea(new Dimension(0,5)));
container.add(exportWithGridCheck);
container.add(Box.createRigidArea(new Dimension(0,5)));
container.add(exportWithRulerCheck);
//Lay out the buttons from left to right.
JPanel buttonPane = new JPanel();
//buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
//buttonPane.add(Box.createHorizontalGlue());
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPane.add(confirmButton);
buttonPane.add(Box.createRigidArea(new Dimension(15, 0)));
buttonPane.add(cancelButton);
//Put everything together, using the content pane's BorderLayout.
Container contentPane = getContentPane();
contentPane.add(container, BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.SOUTH);
pack();
setLocationRelativeTo(locationComp);
}
//Handle clicks on the Set and Cancel buttons.
public void actionPerformed(ActionEvent e) {
if ("Confirm".equals(e.getActionCommand())) {
switch (measureCombo.getSelectedIndex()){
case 0:
m_settings.setMeasure(ShapeConst.MEASURE_ENGLISH);
break;
case 1:
m_settings.setMeasure(ShapeConst.MEASURE_METRIC);
break;
}
m_settings.setExportWithGrid(exportWithGridCheck.isSelected());
m_settings.setExportWithRuler(exportWithRulerCheck.isSelected());
m_modified =true;
m_dialog.setVisible(false);
}else{
m_modified =false;
m_dialog.setVisible(false);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -