📄 drawframe.java
字号:
/**
* $Id:DrawFrame.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved. *
*/
package com.jfimagine.jfdraw.gui;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.JInternalFrame;
import javax.swing.JSplitPane;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import com.jfimagine.jfdraw.gui.DrawAdapter;
import com.jfimagine.jfdraw.gui.DrawWidget;
import com.jfimagine.jfdraw.gui.DrawPane;
import com.jfimagine.jfdraw.gui.resource.CADResource;
import com.jfimagine.jfdraw.gui.GlobalSettings;
import com.jfimagine.jfdraw.action.FileAction;
import com.jfimagine.jfgraph.shape.union.JFPage;
import com.jfimagine.jfgraph.transfer.JFFileFilter;
import com.jfimagine.utils.commonutil.CommonUtil;
/**
* Drawing Frame class. A main drawing frame inside CADMain. This is
* an internal frame so can be multi-generated.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class DrawFrame extends JInternalFrame { //implements MouseListener,MouseMotionListener{
//An internal frame count for calculating how many frames have been spawned.
static int m_openFrameCount = 0;
//Initial position for this new internal frame.
static final int m_xOffset = 30, m_yOffset = 30;
/** A DrawAdapter Pane reference to dispatch events */
private DrawAdapter m_pane;
/** A split pane to place glance view, control view and main drawing pane */
private JSplitPane m_splitPane;
/** A draw widget for glance view and control view*/
private DrawWidget m_drawWidget;
/** A draw pane for the main drawing pane*/
private DrawPane m_drawPane;
/** if the title of this frame is named*/
private boolean m_titleNamed =false;
/** current title of this frame*/
private String m_currentTitle ="";
public DrawFrame(DrawAdapter pane,String title) {
super("",
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
if (title==null || title.equals("")){
title =CADResource.getString("label.frame.untitled")+'-'+ (++m_openFrameCount);
}else{
m_titleNamed =true;
}
m_currentTitle =title;
super.setTitle(m_currentTitle);
//set a reference for main CAD Pane.
this.m_pane =pane;
//draw pane for the main drawing pane
m_drawPane =new DrawPane();
//m_drawPane.setParentDrawFrame(this);
getContentPane().add(m_drawPane);
/*
// draw widget for glance view and control view
m_drawWidget =new DrawWidget();
//Create a split pane with sub view controls in it.
m_splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,m_drawWidget,m_drawPane);
m_splitPane.setOneTouchExpandable(true);
m_splitPane.setDividerLocation(150);
getContentPane().add(m_splitPane);
*/
//...Create the GUI and put it in the window...
//...Then set the window size or call pack...
setSize(300,300);
//Set the window's location.
setLocation(m_xOffset*m_openFrameCount, m_yOffset*m_openFrameCount);
addInternalFrameListener(new InternalFrameAdapter(){
public void internalFrameActivated(InternalFrameEvent e){
//set layerName.
m_pane.setLayerName(m_drawPane.getDrawCanvas().getDrawPage().getCurrentLayer().getName());
//set isMetricRuler
m_pane.setIsMetric(m_drawPane.getIsMetric());
DrawCanvas canvas =m_pane.getDrawCanvas();
if (canvas!=null)
canvas.requestFocus();
}
public void internalFrameClosing(InternalFrameEvent e){
DrawCanvas drawCanvas =m_drawPane.getDrawCanvas();
JFPage page =drawCanvas.getDrawPage();
if (page.isModified()){
int n = JOptionPane.showConfirmDialog(
null,
CADResource.getString("drawframe.savemodified")+"\n\""+getCurrentTitle()+"\"",
CADResource.getString("sys.warn"),
JOptionPane.YES_NO_OPTION);
if (n==JOptionPane.YES_OPTION){
String fileName =drawCanvas.getFileName();
if (fileName!=null && !fileName.equals("")){
if (CommonUtil.isURLFile(fileName))
fileName ="";
}
if (fileName==null || fileName.equals("")){
fileName =FileAction.getOutputFileName(m_pane,JFFileFilter.FILEEXT_DRAW,JFFileFilter.FILEDESC_DRAW);
}
if (fileName!=null && !fileName.equals("")){
if (fileName.endsWith(JFFileFilter.FILEEXT_DRAW)){
//binary JFDraw file
page.saveToBinary(fileName);
}else{
//xml JFDraw file.
page.saveToXML(fileName);
}
}
}
}
if (!isTitleNamed()){
m_openFrameCount--;
if (m_openFrameCount<0) m_openFrameCount=0;
}
}
});
GlobalSettings settings =GlobalSettings.getInstance();
m_drawPane.setIsMetric(settings.isMetric());
}
/** Set the title of this frame.
* @param title A new title.
*/
public void setTitle(String title){
if (title==null) title="";
m_currentTitle =title;
setDisplayTitle(title);
m_drawPane.getDrawCanvas().setFileName(title);
if (!m_titleNamed){
m_titleNamed =true;
m_openFrameCount--;
if (m_openFrameCount<0) m_openFrameCount=0;
}
}
/** Set the display title of this frame.
* @param title A new title.
*/
public void setDisplayTitle(String title){
super.setTitle(title);
}
/** if the title of this frame is named*/
public boolean isTitleNamed(){
return m_titleNamed;
}
/** current title of this frame*/
public String getCurrentTitle(){
//sometimes m_currentTitle is not equal to super.getTitle(),
//cause the super title will be appended other infomations.
return m_currentTitle;
}
/** get current draw pane for the main drawing pane
* @return the draw pane.
*/
public DrawPane getDrawPane(){
return m_drawPane;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -