📄 cadpane.java
字号:
/**
* $Id:CADPane.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved. *
*/
package com.jfimagine.jfdraw.gui;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JPopupMenu;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.ActionEvent;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.BorderLayout;
import java.util.List;
import java.util.ArrayList;
import com.jfimagine.jfdraw.gui.ToolFactory;
import com.jfimagine.jfdraw.gui.resource.CADResource;
import com.jfimagine.jfdraw.gui.dialog.LibHelper;
import com.jfimagine.jfdraw.gui.dialog.LibDialog;
import com.jfimagine.jfdraw.action.FileAction;
import com.jfimagine.jfgraph.shape.base.ObjectList;
import com.jfimagine.jfgraph.shape.union.JFPage;
import com.jfimagine.jfgraph.shape.union.JFLayer;
import com.jfimagine.jfgraph.transfer.JFFileFilter;
import com.jfimagine.utils.log.*;
/**
* Main CAD class. A class used to create the main framework for jfdraw.
*
* @author CookieMaker
*
* @version $Revision: 1.3.0 $
*/
public class CADPane extends DrawAdapter implements ItemListener{
/**an internal log utility*/
private JFLogger m_logger=JFLogManager.getLogger(this.getClass());
/** A desktop for encapsulating internal frames.*/
private JDesktopPane m_desktop=new JDesktopPane();
/** A tool factory used to create menus and tool bars.*/
private ToolFactory m_toolFactory =new ToolFactory();
/** A popup menu for line/curve shape drawing.*/
private JPopupMenu m_lineMenu;
/** A popup menu for rectangle shape drawing.*/
private JPopupMenu m_rectMenu;
/** A popup menu for ellipse shape drawing.*/
private JPopupMenu m_ellipseMenu;
/** A popup menu for polygon shape drawing.*/
private JPopupMenu m_polygonMenu;
/** A popup menu for graph properties.*/
private JPopupMenu m_graphMenu;
/** Main tool bar for drawing.*/
private JToolBar m_toolBar;
/** Appended quick tool bar.*/
private JToolBar m_quickToolBar;
/** Constructor
*/
public CADPane() {
super(new BorderLayout());
//maximize window.
//Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//Lay out the content pane.
setPreferredSize(new Dimension(700,500));
setBackground(new Color(200,200,200));
//A tool bar container for two toolbars.
JPanel toolPanel =new JPanel();
toolPanel.setLayout(new BorderLayout());
//add tool bar
m_toolBar =createToolBar();
toolPanel.add(m_toolBar,BorderLayout.NORTH);
m_quickToolBar =m_toolFactory.createQuickToolBar(this,this);
toolPanel.add(m_quickToolBar,BorderLayout.CENTER);
add(toolPanel,BorderLayout.NORTH);
//add desktop
add(m_desktop, BorderLayout.CENTER);
//Make dragging a little faster but perhaps uglier.
m_desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
//create line/curve popup menu.
m_lineMenu = m_toolFactory.createLineMenu(this);
//create rectangle popup menu.
m_rectMenu = m_toolFactory.createRectangleMenu(this);
//create ellipse popup menu.
m_ellipseMenu = m_toolFactory.createEllipseMenu(this);
//create polygon popup menu.
m_polygonMenu = m_toolFactory.createPolygonMenu(this);
//create graph popup menu.
m_graphMenu = m_toolFactory.createGraphMenu(this,false);
}
/**
* Tell CADPane to open files.
*
* @param files A file list that to be opened.
*
*/
public void openFiles(String files[]){
/*demo
LibDialog libDialog =LibDialog.getInstance(this);
if (files.length>0){
FileAction action =new FileAction(this);
for (int i=0; i<files.length; i++){
String fileName =files[i];
if (fileName!=null && fileName.length()>0){
//load regular JFD or JFX JFDraw files
if (fileName.endsWith(JFFileFilter.FILEEXT_DRAW) ||
fileName.endsWith(JFFileFilter.FILEEXT_DRAW_XML)){
openFile(fileName);
//load libraries in library/template dialog
}else if (fileName.endsWith(JFFileFilter.FILEEXT_DRAW_LIBRARY)){
libDialog.getLibraryPanel().loadLibrary(fileName);
//load templates in library/template dialog
}else if (fileName.endsWith(JFFileFilter.FILEEXT_DRAW_TEMPLATE)){
libDialog.getTemplatePanel().loadLibrary(fileName);
}
}
}
}
//*/
}
/** Create menu bar.
*/
public JMenuBar createMenuBar(){
return m_toolFactory.createMenuBar(this);
}
/** Create tool bar.
*/
public JToolBar createToolBar(){
return m_toolFactory.createToolBar(this);
}
/** getter for desktop
* @return Current desktop pane.
*/
public JDesktopPane getDesktop(){
return m_desktop;
}
/** get the main tool bar object.
* @return main toolbar.
*/
public JToolBar getToolBar(){
return m_toolBar;
}
/** getter for line menu.
* @return The line menu.
*/
public JPopupMenu getLineMenu(){
return m_lineMenu;
}
/** getter for rectangle menu.
* @return The rectangle menu.
*/
public JPopupMenu getRectangleMenu(){
return m_rectMenu;
}
/** getter for ellipse menu.
* @return The ellipse menu.
*/
public JPopupMenu getEllipseMenu(){
return m_ellipseMenu;
}
/** getter for polygon menu.
* @return The polygon menu.
*/
public JPopupMenu getPolygonMenu(){
return m_polygonMenu;
}
/** getter for graph menu.
* @return The graph menu.
*/
public JPopupMenu getGraphMenu(){
return m_graphMenu;
}
/** set the current ruler is under metric or english
* @param isMetric True if metric, false english.
*/
public void setIsMetric(boolean isMetric){
m_toolFactory.setIsMetricRuler(isMetric);
}
/** set current layer name
* @param layerName Current layername
*/
public void setLayerName(String layerName){
m_toolFactory.setLayerName(layerName);
}
/**
* Invoked when an item has been selected or deselected.
*/
public void itemStateChanged(ItemEvent e){
m_toolFactory.fireItemStateChanged(this,e);
}
/** Process actions from menus/buttons.
*
* @param e An action event sent by menus/buttons.
*
*/
public void actionPerformed(ActionEvent e) {
if (!m_toolFactory.fireAction(this,e)){
super.actionPerformed(e);
}
}
/** Notify object selected, tell to do some changes in the drawing framework.
*
* @param objList A new selected object list.
*
*/
public void notifyObjectSelected(ObjectList objList) {
m_toolFactory.notifyObjectSelected(objList);
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*
* @param files A file list that to be opened while jfdraw startup.
*/
public static void createAndShowGUI(String files[]) {
//an inner class for closing windows businesses.
class CloseWindowAdapter extends WindowAdapter{
CADPane pane;
public CloseWindowAdapter(CADPane pane){
this.pane =pane;
}
public void windowClosing(WindowEvent e){
pane.closeAllWindows();
System.exit(0);
}
}
//Make sure we have nice window decorations.
//JFrame.setDefaultLookAndFeelDecorated(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -