📄 bsmapeditimagepanel.java
字号:
package edu.ou.kmi.buddyspace.plugins.maps.editor;
/*
* BSMapEditImagePanel.java
*
* Project: BuddySpace
* (C) Copyright Knowledge Media Institute 2002
*
*
* Created on 16 August 2002, 17:54
*/
//import java.util.*;
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.border.*;
import edu.ou.kmi.buddyspace.utils.*;
import edu.ou.kmi.buddyspace.plugins.maps.xml.*;
/**
* <code>BSMapEditImagePanel</code> is a panel displaying given image in given scale.
*
* @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
*/
public class BSMapEditImagePanel extends ImagePanel {
private boolean setSizeForTag = false;
private ImgTag tag = null;
private LayerTag layerTag = null;
private boolean editable;
/** Constructor */
public BSMapEditImagePanel(Image image, float scale, JComponent mainPanel,
int imgWidth, int imgHeight,
ImgTag tag, LayerTag layerTag, boolean editable) {
super(image, scale, mainPanel, imgWidth, imgHeight);
this.tag = tag;
this.layerTag = layerTag;
this.editable = editable;
if (imgWidth == 0 || imgHeight == 0) setSizeForTag = true;
if (setSizeForTag) {
tag.setWidth(Integer.toString(image.getWidth(this)));
tag.setHeight(Integer.toString(image.getHeight(this)));
setScale(scale, image.getWidth(this), image.getHeight(this));
//maybeResizeParent();
refresh();
}
}
/** Called when included image updated */
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
boolean result = super.imageUpdate(img, infoflags, x, y, width, height);
if (image == img) {
if ((infoflags & ImageObserver.WIDTH) != 0) {
//this.width = Math.round(width * scale);
this.width = Math.round(image.getWidth(this) * scale);
setSize(width, height);
maybeResizeParent();
if (setSizeForTag)
tag.setWidth(Integer.toString(image.getWidth(this)));
refresh();
}
if ((infoflags & ImageObserver.HEIGHT) != 0) {
//this.height = Math.round(height * scale);
this.height = Math.round(image.getHeight(this) * scale);
setSize(this.width, this.height);
maybeResizeParent();
if (setSizeForTag)
tag.setHeight(Integer.toString(image.getHeight(this)));
refresh();
}
}
return result;
}
/** Changes size of parent if cannot fit in */
public void maybeResizeParent() {
int x = getX() + width;
int y = getY() + height;
Dimension d = mainPanel.getPreferredSize();
int px = (int) d.getWidth();
int py = (int) d.getHeight();
if (px < x || py < y) {
x = (x > px)? x : px;
y = (y > py)? y : py;
mainPanel.setPreferredSize(new Dimension(x, y));
}
refresh();
}
/** Returns if the label is editable */
public boolean isEditable() {
return editable;
}
/** Returns img's tag */
public ImgTag getTag() {
return tag;
}
/** Returns label's layer tag */
public LayerTag getLayerTag() {
return layerTag;
}
/** Displays the label as (un)selected */
public void setAsSelected(boolean selected) {
setBorder(selected? new LineBorder(Color.yellow, 2) : null);
}
/** Displays the label as (un)edited */
public void setAsEdited(boolean edited) {
setBorder(edited? new LineBorder(Color.green, 2) : null);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -