📄 drawsketchframe.java
字号:
/*
* This file is part of Caliph & Emir.
*
* Caliph & Emir is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Caliph & Emir is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Caliph & Emir; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright statement:
* --------------------
* (c) 2005 by Werner Klieber (werner@klieber.info)
* http://caliph-emir.sourceforge.net
*/
package at.wklieber.gui;
import at.lux.fotoannotation.AnnotationFrame;
import at.lux.imageanalysis.ColorLayout;
import at.wklieber.Settings;
import at.wklieber.mpeg7.Mpeg7;
import at.wklieber.gui.data.IComponentData;
import at.wklieber.tools.*;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
public class DrawSketchFrame
extends JPanel
implements IComponentReceivedInterface {
private static Category log = Logger.getLogger(DrawSketchFrame.class.getName());
private static Console console = Console.getReference();
protected static Java2dTools java2dTools = Java2dTools.getReference();
private static Settings cfg = Settings.getReference();
public static final String DEFAULT_WINDOW_TITLE = "Specify Colors";
// ----------------------------- static stuff end ----------------------------------
JPanel mainPanel = null; // This panel covers the complete drawing Frame
JPanel mainFrame = null; // the main panel to draw (This panel)
private JFrame parentFrame = null; // an instance is passed within the constructor
Container toolbarWrapper = null;
IDrawPanel drawPanel = null;
JMenuBar menuBar = null;
JPanel statusPanel = null;
JPanel buttonPanel = null;
JToolBar toolBar = null;
MenuTools menuTool = null;
private JLabel statusBar;
private java.util.List<IComponentData> iComponentList = null; // List of IComponent
private BufferedImage image = null; // the (background) image to fill with meta data
private BufferedImage sketchImage = null; // the image just containing the drawed components (shapes, ...)
private static int COLOR_LAYOUT_Y = 64;
private static int COLOR_LAYOUT_C = 64;
private AnnotationFrame annotationsFrame;
public DrawSketchFrame(JFrame parentFrame1, java.util.List iComponentList1) {
super();
init(parentFrame1, null, null, iComponentList1);
}
public DrawSketchFrame(AnnotationFrame parentFrame1, Container toolbar, java.util.List iComponentList1) {
super();
annotationsFrame = parentFrame1;
BufferedImage image1 = parentFrame1.getImage();
init(null, image1, toolbar, iComponentList1);
}
private void init(JFrame parentFrame1, BufferedImage image1, Container toolbar, java.util.List iComponentList1) {
parentFrame = parentFrame1;
image = image1;
mainFrame = this;
clear();
Container mainContainer = mainFrame;
if (mainPanel != null) {
mainPanel.removeAll();
}
// initialize all member-menu Panels
mainPanel = new JPanel(); // This panel covers the complete Frame
drawPanel = new IDrawPanel(this);
menuBar = new JMenuBar();
statusPanel = new JPanel();
buttonPanel = new JPanel();
if (toolbar == null) {
toolbarWrapper = new Container();
LayoutManager mgr = new FlowLayout(FlowLayout.LEADING);
toolbarWrapper.setLayout(mgr);
} else {
toolbarWrapper = toolbar;
}
//------------------------ add Elements ---------------------------
String iconLocation = cfg.getIconsDir();
menuTool = new MenuTools(this, menuBar, toolbarWrapper, iconLocation);
setMenuEntries();
ActionListener drawShapeAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
actionDrawShape(e);
}
};
menuTool.addPopupMenuEntry("Draw &Shape", "Draw a shape", "", drawShapeAction);
//------------------------ define the Drawpanel ---------------------------
drawPanel.setIgnoreRepaint(false);
drawPanel.setPreferredSize(new Dimension(600, 500));
drawPanel.setToolTipText("");
drawPanel.setBackground(Color.white);
drawPanel.setBorder(BorderFactory.createLineBorder(Color.black));
drawPanel.setLayout(null);
//--------------- link all panels to the frame
mainPanel.setLayout(new BorderLayout());
// Set this instance as the application's menu bar
// add a wrapper for menubar and toolbar
if (annotationsFrame != null) {
mainContainer.add(toolbarWrapper, BorderLayout.NORTH);
mainPanel.add(drawPanel, BorderLayout.CENTER);
mainContainer.add(mainPanel, BorderLayout.CENTER);
}
mainPanel.validate();
mainPanel.repaint();
this.setVisible(true);
clear();
if (parentFrame != null) {
parentFrame.setEnabled(false);
log.debug("hide parent frame");
//parentFrame.hide();
} else
log.debug("parent frame is null");
//drawIComponents();
setIComponents(iComponentList1);
//test();
}
private void drawIComponents() {
// draw components, if available
for (Iterator<IComponentData> it = iComponentList.iterator(); it.hasNext();) {
IComponentData obj = it.next();
/*if (!(obj instanceof IComponent)) {
log.error("got draw-list with invalid object-type: \"" + obj.getClass().getName() + "\". Need elements of type ICompontent");
continue;
}*/
IComponent icomp;
icomp = obj.getIComponent(this.drawPanel);
//icomp = (IComponent) obj;
IComponent clone;
clone = (IComponent) icomp.clone();
clone.setDrawPanel(this.drawPanel);
clone.setMoveable(true);
clone.setResizeable(true);
clone.setDoDnd(false);
addNewComponent(clone);
}
}
public void setIComponents(java.util.List<IComponentData> iComponentList1) {
iComponentList = iComponentList1;
if (iComponentList == null) iComponentList = new ArrayList();
drawIComponents();
}
/**
* empty all data
*/
public void clear() {
//iComponentDataList = new Vector();
if (annotationsFrame != null) {
image = annotationsFrame.getImage();
}
// System.out.println("Setting beackgroundimage: " + image);
if (drawPanel != null) {
drawPanel.removeAll();
drawPanel.setBackgroundImage(image);
}
repaint();
}
private Component buildBottomPanel() {
statusBar = new JLabel(" Idle...");
statusBar.setBorder(BorderFactory.createLoweredBevelBorder());
return statusBar;
}
// not tested
public void setImage(BufferedImage image) {
this.image = image;
clear();
}
// inserts the menu and toolbar stuff
private void setMenuEntries() {
menuTool.readMenuFromConfigFile("shapeBar", MenuTools.TYPE_MENUBAR);
}
public String toString() {
return "DrawSketchFrame";
}
// --------- actions for the Buttons ----------------------
public void actionDominantColor(ActionEvent e) {
try {
if (image == null) { // load one image from file
String file = FileTools.showOpenDialog(cfg.getDataDir(), "jpg", "JPEG Image", true, null);
//log.debug("Analyse file: " + file);
if (file == null) {
return;
}
image = javax.imageio.ImageIO.read(new File(file));
drawPanel.setBackgroundImage(image);
}
ColorBlockExtractor colorBlocks = new ColorBlockExtractor(image, false);
BufferedImage colorReducedImage = colorBlocks.getQuantizedImage();
IColorRectangle[] components = java2dTools.getDominantColor(colorReducedImage, drawPanel);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -