📄 drawadapter.java
字号:
/**
* $Id:DrawAdapter.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved. *
*/
package com.jfimagine.jfdraw.gui;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.BoxLayout;
import javax.swing.JScrollPane;
import javax.swing.BorderFactory;
import javax.swing.JDesktopPane;
import java.awt.LayoutManager;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import com.jfimagine.jfgraph.event.GraphEvent;
import com.jfimagine.jfgraph.event.GraphEventListener;
import com.jfimagine.jfdraw.gui.DrawCanvas;
import com.jfimagine.jfdraw.gui.GlobalSettings;
import com.jfimagine.jfdraw.action.ActionDispatcher;
import java.awt.print.PageFormat;
import com.jfimagine.jfgraph.shape.decorate.JFPageFormat;
import com.jfimagine.jfgraph.shape.base.ObjectList;
/**
* Draw adapter class. A drawing base class.
*
* @author CookieMaker
*
* @version $Revision: 1.3.0 $
*/
public abstract class DrawAdapter extends JPanel implements ActionListener{
/** An event dispatcher for event processing.*/
private ActionDispatcher m_actionDispatcher =new ActionDispatcher(this);
/**
* Creates a new DrawAdapter with the specified layout manager and buffering
* strategy.
*
* @param layout the LayoutManager to use
* @param isDoubleBuffered a boolean, true for double-buffering, which
* uses additional memory space to achieve fast, flicker-free
* updates
*/
public DrawAdapter(LayoutManager layout, boolean isDoubleBuffered) {
super(layout,isDoubleBuffered);
}
/**
* Create a new buffered DrawAdapter with the specified layout manager
*
* @param layout the LayoutManager to use
*/
public DrawAdapter(LayoutManager layout) {
super(layout);
}
/**
* Creates a new <code>DrawAdapter</code> with <code>FlowLayout</code>
* and the specified buffering strategy.
* If <code>isDoubleBuffered</code> is true, the <code>DrawAdapter</code>
* will use a double buffer.
*
* @param isDoubleBuffered a boolean, true for double-buffering, which
* uses additional memory space to achieve fast, flicker-free
* updates
*/
public DrawAdapter(boolean isDoubleBuffered) {
super(isDoubleBuffered);
}
/**
* Creates a new <code>DrawAdapter</code> with a double buffer
* and a flow layout.
*/
public DrawAdapter() {
super();
//load global settings
GlobalSettings.getInstance();
}
/** Process actions from menus/buttons.
*
* @param e An action event sent by menus/buttons.
*
*/
public void actionPerformed(ActionEvent e) {
m_actionDispatcher.fireAction(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) {
//do nothing here
}
/** process actions from menus/buttons
*
* @param cmd A string command
*/
public void fireAction(String cmd){
m_actionDispatcher.fireAction(cmd,null);
}
/** get current Drawing Canvas
* @return Current drawing canvas.
*/
public DrawCanvas getDrawCanvas(){
return null;
}
/**
* close all sub windows if this adapter contains internal frames.
*/
public void closeAllWindows(){
}
/** Focus window by title
* @param title A specified window title.
*/
public void focusWindowByTitle(String title){
}
/** set default frame parameters, e.g. LayerName, isMetricRuler, etc.
* If this Draw Adapter pane includes internal frames, here we'll call this
* default parameters setter as soon as the frame is created.
*/
public void setDefaultFrameParameters(){
}
/** set current layer name of current drawing page.
* @param layerName Current layername
*/
public void setLayerName(String layerName){
}
/** getter for desktop
* @return Current desktop pane.
*/
public JDesktopPane getDesktop(){
return null;
}
/** set ruler as metric or english measurement.
* @param isMetric True if is metric, false english.
*/
public void setIsMetric(boolean isMetric){
}
/** get if ruler is a metric one.
* @return True if is metric, false english.
*/
public boolean getIsMetric(){
return false;
}
/** new file operation.*/
public void newFile(){
}
/** open a specified file
* @param fileName A spcified file name
*/
public boolean openFile(String fileName){
return true;
}
/** Save current page to a specified file.
* @param fileName A file to be saved into.
*/
public boolean saveFile(String fileName){
return true;
}
/** get the file name of current opened page.
* @return the file name
*/
public String getFileName(){
return "";
}
/** set the file name of current opened page.
* @param fileName A new file name
*/
public void setFileName(String fileName){
}
// Create the listener list
protected javax.swing.event.EventListenerList listenerList =
new javax.swing.event.EventListenerList();
// This methods allows classes to register for GraphEvents
public void addGraphEventListener(GraphEventListener listener) {
listenerList.add(GraphEventListener.class, listener);
}
// This methods allows classes to unregister for GraphEvents
public void removeGraphEventListener(GraphEventListener listener) {
listenerList.remove(GraphEventListener.class, listener);
}
// This private class is used to fire GraphEvents
public void fireGraphEvent(GraphEvent evt) {
//1. process internal event listener list
Object[] listeners = listenerList.getListenerList();
// Each listener occupies two elements - the first is the listener class
// and the second is the listener instance
for (int i=0; i<listeners.length; i+=2) {
if (listeners[i]==GraphEventListener.class) {
((GraphEventListener)listeners[i+1]).graphChanged(evt);
}
}
//2. process subclassed event listener
if (this instanceof GraphEventListener){
((GraphEventListener)this).graphChanged(evt);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -