// DrawingInternalFrame.java
// DrawingInternalFrame is a JInternalFrame subclass for
// DeitelDrawing drawings.
package com.deitel.advjhtp1.drawing;
// Java core packages
import java.awt.*;
import java.awt.event.*;
import java.awt.dnd.*;
import java.io.*;
import java.util.*;
import java.util.List;
// Java extension packages
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
// Deitel packages
import com.deitel.advjhtp1.drawing.model.*;
import com.deitel.advjhtp1.drawing.model.shapes.*;
import com.deitel.advjhtp1.drawing.view.*;
import com.deitel.advjhtp1.drawing.controller.*;
public class DrawingInternalFrame extends JInternalFrame
implements Observer {
// offsets to stagger new windows
private static final int xOffset = 30;
private static final int yOffset = 30;
private static int openFrameCount = 0;
// MVC components
private DrawingModel drawingModel;
private DrawingView drawingView;
private MyShapeController myShapeController;
private DragAndDropController dragAndDropController;
private MyShapeControllerFactory shapeControllerFactory;
// file management properties
private JFileChooser fileChooser;
private String fileName;
private String absoluteFilePath;
private boolean saved = true;
private DrawingToolBar toolBar;
private ZoomDialog zoomDialog;
// Actions for save, zoom, move, etc.
private Action saveAction, saveAsAction, zoomAction,
moveAction, fillAction, gradientAction;
// DrawingInternalFrame constructor
public DrawingInternalFrame( String title )
{
super( title + " - " + ( ++openFrameCount ), true, true,
false, true );
setDefaultCloseOperation(
WindowConstants.DO_NOTHING_ON_CLOSE );
// create new DrawingModel
drawingModel = new DrawingModel();
// create new DrawingView for DrawingModel
drawingView = new DrawingView( drawingModel );
// register DrawingInternalFrame as a DrawingModel Observer
drawingModel.addObserver( this );
// MyShapeControllerFactory for creating MyShapeControllers
shapeControllerFactory =
MyShapeControllerFactory.getInstance();
// create DragAndDropController for drag and drop operations
dragAndDropController =
new DragAndDropController( drawingModel );
// get default DragSource for current platform
DragSource dragSource = DragSource.getDefaultDragSource();
// create DragGestureRecognizer to register
// DragAndDropController as DragGestureListener
dragSource.createDefaultDragGestureRecognizer( drawingView,
DnDConstants.ACTION_COPY_OR_MOVE,
dragAndDropController );
// enable drawingView to accept drop operations, using
// dragAndDropController as DropTargetListener
drawingView.setDropTarget( new DropTarget( drawingView,
DnDConstants.ACTION_COPY_OR_MOVE,
dragAndDropController ) );
// add drawingView to viewPanel, put viewPanel in
// JScrollPane and add JScrollPane to DrawingInternalFrame
JPanel viewPanel = new JPanel();
viewPanel.add( drawingView );
getContentPane().add( new JScrollPane( viewPanel ),
BorderLayout.CENTER );
// create fileChooser and set its FileFilter
fileChooser = new JFileChooser();
fileChooser.setFileFilter( new DrawingFileFilter() );
// show/hide ZoomDialog when frame activated/deactivated
addInternalFrameListener(
new InternalFrameAdapter() {
// when DrawingInternalFrame activated, make
// associated zoomDialog visible
public void internalFrameActivated(
InternalFrameEvent event )
{
if ( zoomDialog != null )
zoomDialog.setVisible( true );
}
// when DrawingInternalFrame is deactivated, make
// associated zoomDialog invisible
public void internalFrameDeactivated(
InternalFrameEvent event )
{
if ( zoomDialog != null )
zoomDialog.setVisible( false );
}
}
); // end call to addInternalFrameListener
// stagger each DrawingInternalFrame to prevent it from
// obscuring other InternalFrames
setLocation( xOffset * openFrameCount,
yOffset * openFrameCount );
// add new DrawingToolBar to NORTH area
toolBar = new DrawingToolBar();
getContentPane().add( toolBar, BorderLayout.NORTH );
// get name of first MyShape that shapeControllerFactory
// supports and create MyShapeController
String shapeName =
shapeControllerFactory.getSupportedShapes()[ 0 ];
setMyShapeController(
shapeControllerFactory.newMyShapeController(
drawingModel, shapeName ) );
// set DrawingInternalFrame size
setSize( 500, 320 );
} // end DrawingInternalFrame constructor
// get DrawingInternalFrame Save Action
public Action getSaveAction()
{
return saveAction;
}
// get DrawingInternalFrame Save As Action
public Action getSaveAsAction()
{
return saveAsAction;
}
// set Saved flag for current drawing and update frame
// title to indicate saved state to user
public void setSaved( boolean drawingSaved )
{
// set Saved property
saved = drawingSaved;
// get current DrawingInternalFrame title
String title = getTitle();
// if drawing is not saved and title does not end with
// an asterisk, add asterisk to title
if ( !title.endsWith( " *" ) && !isSaved() )
setTitle( title + " *" );
// if title ends with * and drawing has been saved,
// remove * from title
else
if ( title.endsWith( " *" ) && isSaved() )
setTitle( title.substring( 0,
title.length() - 2 ) );
// enable save actions if drawing not saved
getSaveAction().setEnabled( !isSaved() );
}
// return value of saved property
public boolean isSaved()
{
return saved;
}
// handle updates from DrawingModel
public void update( Observable observable, Object object )
{
// set saved property to false to indicate that
// DrawingModel has changed
setSaved( false );
}
// set fileName for current drawing
public void setFileName( String file )
{
fileName = file;
// update DrawingInternalFrame title
setTitle( fileName );
}
// get fileName for current drawing
public String getFileName()
{
return fileName;
}
// get full path (absoluteFilePath) for current drawing
public String getAbsoluteFilePath()
{
return absoluteFilePath;
}
// set full path (absoluteFilePath) for current drawing
public void setAbsoluteFilePath( String path )
{
absoluteFilePath = path;
}
// get DrawingModel for current drawing
public DrawingModel getModel()
{
return drawingModel;
}
// set JInternalFrame and ZoomDialog titles
public void setTitle( String title )
{
super.setTitle( title );
if ( zoomDialog != null )
zoomDialog.setTitle( title );
}
// set MyShapeController for handling user input
public void setMyShapeController(
MyShapeController controller )
{
// remove old MyShapeController
if ( myShapeController != nul
没有合适的资源?快使用搜索试试~ 我知道了~
adv-java-examples.rar_adv
共1769个文件
java:901个
jpg:325个
png:132个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 9 浏览量
2022-09-20
14:19:39
上传
评论
收藏 5.62MB RAR 举报
温馨提示
java的一些教程 大家看看,很有用的
资源推荐
资源详情
资源评论
收起资源包目录
adv-java-examples.rar_adv (1769个子文件)
policy.all 128B
policy.all 128B
policy.all 128B
policy.all 128B
policy.all 128B
policy.all 128B
policy.all 128B
policy.all 128B
policy.all 60B
compileRMI_IIOP.bat 726B
compileRMI_IIOP.bat 726B
compileIDL.bat 540B
compileIDL.bat 540B
compileIDL.bat 537B
compileIDL.bat 537B
compileIDL.bat 497B
compileIDL.bat 496B
startserver.bat 494B
startserver.bat 494B
stopserver.bat 493B
stopserver.bat 493B
compileIDL.bat 492B
compileIDL.bat 479B
compileIDL.bat 478B
compileIDL.bat 474B
startclient.bat 463B
startclient.bat 463B
compileIDL1.bat 433B
compileIDL2.bat 433B
compileIDL2.bat 416B
compileIDL1.bat 416B
startclient.bat 399B
startclient.bat 399B
startserver.bat 398B
startserver.bat 398B
startclient.bat 394B
startclient.bat 393B
startclient.bat 393B
startclient.bat 393B
startclient.bat 393B
startserver.bat 392B
startserver.bat 392B
startserver.bat 392B
startserver.bat 391B
startserver.bat 391B
startclient.bat 387B
startserver.bat 385B
startclient.bat 377B
startserver.bat 375B
startclient.bat 370B
startserver.bat 368B
createDatabase.bat 71B
createDatabase.bat 71B
createDatabase.bat 71B
createDatabase.bat 71B
createDatabase.bat 71B
createDatabase.bat 71B
jaas.config 173B
JNITintImage.cpp 5KB
JNIArrayWrapperImpl.cpp 3KB
JNIPIWrapperImpl.cpp 2KB
JNIPrintWrapperImpl.cpp 2KB
JNIStaticWrapperImpl.cpp 1KB
default.css 3KB
styles.css 2KB
styles.css 2KB
JNIMathLibrary.dll 240KB
JNIPrintMessage.dll 224KB
JNIPILibrary.dll 216KB
JNIArrayLibrary.dll 200KB
conditional.dtd 2KB
welcome.dtd 1KB
clients.dtd 339B
BEA_Bookstore.ear 371KB
Bookstore.ear 356KB
start.GIF 11KB
start.GIF 11KB
logotiny.gif 6KB
lookAndFeel.gif 3KB
portability.gif 2KB
softwareEngineering.gif 2KB
goodProgramming.gif 2KB
testingDebugging.gif 2KB
programmingError.gif 2KB
perf.gif 2KB
testingDebugging.gif 1KB
lookAndFeel.gif 1KB
Help24.gif 1KB
Help24.gif 1KB
Help24.gif 1KB
home.gif 1KB
home.gif 1KB
home.gif 1KB
home.gif 1KB
home.gif 1KB
home.gif 1KB
home.gif 1KB
home.gif 1KB
portability.gif 1KB
softwareEngineering.gif 1KB
共 1769 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
朱moyimi
- 粉丝: 61
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功