📄 idrawpanel.java
字号:
}
cat.debug("URL: <" + urlString + ">");
if (urlString.length() > 0) {
String id = ""; // id to load mpeg7 data if needed
String fileId = "";
try {
//String urlPath = FileTools.getFilePath(urlString);
// get the filename without the ending ".jpg"
// Url is e.g: http://129.27.200.42:8082/cocoon/imb2/image.jsp?id=jr_test;IMB;1;T00:01:23:19F25
int start = urlString.indexOf('=');
String subString = urlString.substring(start + 1);
// remove eventuell ending stuff
start = subString.indexOf("\n");
if (start > 0) {
fileId = subString.substring(0, start);
} else
fileId = subString;
//fileId = urlString.substring(urlPath.length() - 1, urlString.length() - 4);
id = "";
} catch (Exception e) {
// make no furhter request on an failure
e.printStackTrace();
cat.error(e);
}
if (id.length() != 0) {
//MessageBox.displayMessage("", "");
//todo: add here the code to parse the mpeg7 file when retrieving a search result
//parseMpeg7Document(fileId);
}
} // end if get further metadata
} // endif got a valid image
// for debugging
//parseMpeg7Document("jr_test;IMB;1;");
//{ Must catch IOException and UnsupportedFlavorException
} catch (Exception e) {
cat.error(e);
e.printStackTrace();
}
}
/*private void parseMpeg7Document(String fileId) {
cat.debug("get MPEG7 file: <" + fileId + ">");
//http://129.27.200.42:8082/cocoon/imb2/query-xml-xml
//----- get the url from where to request the data
String relQueryPoint = config.getProperty("imbConfig/broker/webAccess/mpeg7Url", "",
"/cocoon/imb2/detail");
String webServerBaseUrl = config.getProperty("imbConfig/broker/webAccess/baseUrl", "",
"http://127.0.0.1:80");
String webUrl = webServerBaseUrl + relQueryPoint + "?id=" + fileId;
cat.debug("Complete url: <" + webUrl + ">");
// open an httprequest to that url
DownloadGuiThread thread = new DownloadGuiThread(webUrl);
thread.start(); // show message box and lock gui
//String result = thread.getResult();
//thread.close();
//thread = null;
String result = MiscTools.downloadTextFileFromHttp(webUrl, "");
thread.close(); // unlock gui
thread = null;
XmlTemplate temp = new XmlTemplate();
temp.setDocument(result);
Document doc = temp.getDocument(new Document(new Element("empty")));
//XMLTreeView view = new XMLTreeView(new JFrame(), true, doc);
//view.setSize(640, 480);
//view.setLocation(this.getLocation().x + 20, this.getLocation().y + 20);
//view.setVisible(true);
if (parentFrame != null) {
Controller controller = parentFrame.getController();
List dataList = controller.loadMpeg7FromXml(doc);
drawRepresentants(dataList);
}
//return "not implemented";
}*/
public BufferedImage getBackgroundImage() {
return backgroundImage;
}
public Rectangle getBackgroundImageSize() {
return backgroundImageSize;
}
public void setBackgroundImageSize(Rectangle backgroundImageSize) {
this.backgroundImageSize = backgroundImageSize;
}
public void setBackgroundImage(BufferedImage backgroundImage1) {
backgroundImage = java2dTools.getBrighterImage(backgroundImage1);
// backgroundImageSize is set in drawComponent
//backgroundImage = backgroundImage1;
cat.debug("set new brighter image as background");
//java2dTools.showImage(backgroundImage1);
validate();
repaint();
}
public void dragEnter(DropTargetDragEvent event) {
//cat.debug( "dtlistener dragEnter");
}
public void dragOver(DropTargetDragEvent event) {
//cat.debug( "dtlistener dragOver");
}
public void dropActionChanged(DropTargetDragEvent event) {
//cat.debug( "dtlistener dropActionChanged");
}
public void dragExit(DropTargetEvent event) {
//cat.debug( "dtlistener dragExit");
}
public String toString() {
return "nothing to report";
}
protected void finalize() throws Throwable {
super.finalize();
}
public void mouseClicked(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
//cat.debug("repain panel for " + parentFrame);
// draw the background image
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (backgroundImage != null) {
Graphics2D g2 = (Graphics2D) g;
//cat.debug("Drawing Background");
//g2.clearRect(0, 0, this.getWidth(), this.getHeight());
Rectangle boundary;
boundary = (Rectangle) java2dTools.fitToWindow(this.getBounds(),
new Rectangle(0, 0, backgroundImage.getWidth(), backgroundImage.getHeight()));
//cat.debug("Drawing " + boundary.toString());
backgroundImageSize = new Rectangle((int) boundary.getX(), (int) boundary.getY(),
(int) boundary.getWidth(), (int) boundary.getHeight());
g2.drawImage(backgroundImage, backgroundImageSize.x, backgroundImageSize.y,
backgroundImageSize.width, backgroundImageSize.height, Color.WHITE, null);
} else {
backgroundImageSize = null;
}
//java2dTools.showImage(backgroundImage);
}
/**
* remove a component from the drawpanel and reset the search-opeartor component correctly
*
* @param a_component
*/
public void removeIComponent(IComponent a_component) {
if (!isMathMode) {
remove(a_component);
return; //------------------ EXIT POINT -----------------------
}
List<IComponentStruct> comps = getIComponents();
int pos = getComponentPosition(comps, a_component);
assert(pos >= 0);
if (pos == 0) {
remove(a_component);
if (comps.size() > 1) {
remove(comps.get(1).getComponent());
}
} else {
IComponentStruct thisComponent = comps.get(pos);
assert(!thisComponent.isOperator()); // operators are deleted automatically
IComponentStruct perviousOperator = comps.get(pos - 1);
assert(perviousOperator.isOperator());
IComponentStruct lastComponent = comps.get(pos - 2);
assert(!lastComponent.isOperator());
IComponentStruct nextOperator = null;
if (pos < (comps.size() - 1)) {
nextOperator = comps.get(pos + 1);
assert(nextOperator.isOperator());
}
// delete component and its previous operator
remove(perviousOperator.getComponent());
remove(thisComponent.getComponent());
// set next operatro to the previous component if available
if (nextOperator != null) {
ILine op = (ILine) nextOperator.getComponent();
IComponent p1 = op.getParentComponent01();
IComponent p2 = op.getParentComponent02();
IComponent newP = lastComponent.getComponent();
if (newP == p1) {
p2 = newP;
} else {
p1 = newP;
}
op.setParentComponent01(p1);
op.setParentComponent02(p2);
}
}
layoutComponents(null);
}
private int getComponentPosition(List<IComponentStruct> comps, IComponent a_component) {
int pos = -1;
for (int i = 0; i < comps.size(); i++) {
IComponentStruct struct = comps.get(i);
if (struct.equals(a_component)) {
pos = i;
break;
}
}
return pos;
}
/**
* auto layout the componenst in the drawpanel
*/
public void layoutComponents(Dimension aDefaultDimension) {
double w = this.getWidth();
double h = this.getHeight();
if (w == 0) {
w = aDefaultDimension.getWidth();
h = aDefaultDimension.getHeight();
}
if (h > 100) {
h = 100;
}
double ch = h * .9;
double cw = (h / 4) * 3;
double lineMin = 50;
double posX = 10;
double posY = (h - ch) / 2;
List<IComponentStruct> comps = getIComponents();
for (int i = 0; i < comps.size(); i++) {
IComponentStruct struct = comps.get(i);
if (!struct.isOperator()) {
IComponent comp = struct.getComponent();
if (i > 0) { // works because first compnent is never a opertor
assert(!struct.isOperator());
posX += cw + lineMin;
}
double x = posX;
double y = posY;
comp.setComponentBounds((int) x, (int) y, (int) cw, (int) ch);
//System.out.println("Layout [x, ,y, w, h]: " + (int) x + ", " + (int) y + ", " + (int) cw + ", " + (int) ch);
}
}
Rectangle rect = this.getBounds();
rect.setSize((int) posX, (int) rect.getHeight());
this.setBounds(rect);
}
private List<IComponentStruct> getIComponents() {
List<IComponentStruct> returnValue = new ArrayList<IComponentStruct>();
Component[] comps = this.getComponents();
//comps = CollectionTools.revertArray(comps);
for (int counter = 0; counter < comps.length; counter++) {
boolean isOperator = (ILine.class.isInstance(comps[counter]));
IComponent comp = (IComponent) comps[counter];
returnValue.add(new IComponentStruct(comp, isOperator));
}
return returnValue;
}
/**
* if true, the panel is used to draw Mulmiedia objects and operator
* this means, when deleting objects, the previous operator (ILine) is removed too
*
* @return
*/
public boolean isMathMode() {
return isMathMode;
}
/**
* if true, the panel is used to draw Mulmiedia objects and operator
* this means, when deleting objects, the previous operator (ILine) is removed too
*/
public void setMathMode(boolean mathMode) {
isMathMode = mathMode;
}
/*public void paint(Graphics g) {
super.paint(g);
}*/
}
class IComponentStruct {
private IComponent component;
private boolean isOperator;
public IComponentStruct(IComponent component, boolean isOperator) {
setComponent(component);
setOperator(isOperator);
}
public boolean equals(IComponent a_component) {
boolean returnValue;
returnValue = (a_component == component);
return returnValue;
}
public IComponent getComponent() {
return component;
}
public void setComponent(IComponent component) {
this.component = component;
}
public boolean isOperator() {
return isOperator;
}
public void setOperator(boolean operator) {
isOperator = operator;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -