📄 objectpalette.java
字号:
public void actionChooseColor(ActionEvent e) {
if (currentDisplay == PANEL_COLOR)
return;
if (colorArray.length == 0) {
colorArray = new IRectangle[12];
colorArray[0] = new IColorRectangle(drawPanel, Color.BLACK, Color.WHITE, "Black");
colorArray[1] = new IColorRectangle(drawPanel, Color.DARK_GRAY, Color.WHITE, "Dark gray");
colorArray[2] = new IColorRectangle(drawPanel, Color.LIGHT_GRAY, Color.WHITE, "Light gray");
colorArray[3] = new IColorRectangle(drawPanel, Color.BLUE, Color.WHITE, "Blue");
colorArray[4] = new IColorRectangle(drawPanel, Color.MAGENTA, Color.WHITE, "Magenta");
colorArray[5] = new IColorRectangle(drawPanel, Color.GREEN, Color.WHITE, "Green");
colorArray[6] = new IColorRectangle(drawPanel, Color.CYAN, Color.WHITE, "Cyan");
colorArray[7] = new IColorRectangle(drawPanel, Color.ORANGE, Color.WHITE, "Orange");
colorArray[8] = new IColorRectangle(drawPanel, Color.PINK, Color.WHITE, "Pink");
colorArray[9] = new IColorRectangle(drawPanel, Color.RED, Color.WHITE, "Red");
colorArray[10] = new IColorRectangle(drawPanel, Color.YELLOW, Color.WHITE, "Yellow");
colorArray[11] = new IColorRectangle(drawPanel, Color.WHITE, Color.WHITE, "White");
}
//drawPanel.removeAll();
currentDisplay = PANEL_COLOR;
drawComponents();
validateTree();
repaint();
//System.out.println("comp: " + colorArray[0].getSize());
}
public void actionChooseShape(ActionEvent e) {
if (currentDisplay == PANEL_SHAPE)
return;
if (shapeArray.length == 0) {
//shapeArray = new IShape[0];
//colorArray[0] = new IColorRectangle(drawPanel, Color.BLACK, Color.WHITE);
IAccessFile config = cfg.getConfigAccess();
java.util.List shapeElements = config.getProperties("imbConfig/userInterface/shapes/*");
shapeArray = new IShape[shapeElements.size()];
int counter = 0;
for (Iterator it = shapeElements.iterator(); it.hasNext(); counter++) {
Element elem = (Element) it.next();
String name = elem.getName();
cat.debug("Shape Name: " + name);
String[] shapePoints = config.getProperties("imbConfig/userInterface/shapes/" + elem.getName(), "point", new String[0]);
IComponentData data = new IComponentData(new IShape());
data.setDotList(mpeg7Convert.stringArray2PointList(shapePoints));
data.setBoundary(new Rectangle(0, 0, elementWidth, elementHeigh));
data.setName(elem.getName());
IShape iShape = new IShape(drawPanel, data);
iShape.setDrawDots(false);
iShape.setResizeable(false);
iShape.setMoveable(false);
iShape.setDoDnd(true);
shapeArray[counter] = iShape;
}
} // end if
//drawPanel.removeAll();
currentDisplay = PANEL_SHAPE;
drawComponents();
validateTree();
repaint();
}
private void updateStatusBar(String text) {
statusBar.setText(text);
statusBar.repaint();
}
protected IComponent[] getImagesFromDirectory(String directory1) {
return getImagesFromDirectory(directory1, true);
}
protected IComponent[] getImagesFromDirectory(final String directory1, boolean doGetBaseAutomatic1) {
//cat.debug("Dir:" + directory1);
String[] fileArray = getImagesNamesFromDirectory(directory1, doGetBaseAutomatic1);
final String[] files = fileArray;
final IComponent[] iArray = new IRectangle[files.length];
final ObjectPalette thisClass = this;
//imageArray = iArray;
Runnable doWorkRunnable = new Runnable() {
public void run() {
for (int i = 0; i < files.length; i++) {
//cat.debug("file: " + files[i]);
updateStatusBar("read image " + (i + 1) + "/" + files.length + " (" + files[i] + ")");
String fileName = FileTools.resolvePath(directory1 + files[i], false);
iArray[i] = new IImageComponent(drawPanel, fileName);
// this class as listener
if (parentMouseListener != null) {
iArray[i].addMouseListener(parentMouseListener);
}
drawPanel.validate();
mainFrame.repaint();
}
updateStatusBar("Idle...");
}
};
//SwingUtilities.invokeLater(doWorkRunnable);
Thread thread = new Thread(doWorkRunnable);
thread.start();
drawPanel.validate();
mainFrame.repaint();
return iArray;
}
/**
* @param directory1
* @param doGetBaseAutomatic1
* @return a STring array with all image names in the given directory
*/
private String[] getImagesNamesFromDirectory(String directory1, boolean doGetBaseAutomatic1) {
cat.debug("Dir:" + directory1);
String[] returnValue = new String[0];
try {
String[] fileArray = new String[0];
/* if (doGetBaseAutomatic1 && cfg.isStartedAsJarFile()) {
String archive = cfg.getBaseFile();
archive = archive.substring(0, archive.length() - 2);
String dir = directory1.substring(archive.length() + 2);
//cat.debug("Load from Jar: " + archive + ", dir: " + dir);
fileArray = UnzipTools.getFileList(archive, dir, true);
//cat.debug("GO:" + fileArray.length);
for (int i = 0; i < fileArray.length; i++) {
cat.debug(fileArray[i]);
}
} else {*/
//fileArray = FileTools.fileList(directory1, "*.jpg");
if (FileTools.exists(directory1)) {
fileArray = FileTools.fileList(new FileParserSettings(directory1, "*.jpg"));
}
//cat.debug("GO:" + fileArray.length);
//}
returnValue = fileArray;
} catch (Exception e) {
e.printStackTrace();
cat.error(e);
}
return returnValue;
}
private String[] getImagesNamesFromDirectory(String directory1) {
return getImagesNamesFromDirectory(directory1, true);
}
/*public void actionChooseImage(ActionEvent e) {
if (currentDisplay == PANEL_IMAGE)
return;
currentDisplay = PANEL_IMAGE;
if (imageArray.length == 0) {
String location = cfg.getImageDir();
imageArray = getImagesFromDirectory(location);
String[] files = FileTools.fileList(location, "*.jpg");
imageArray = new IRectangle[files.length];
for(int i = 0; i < files.length; i++) {
cat.debug("file: " + files[i]);
}
imageArray = new IRectangle[2];
String fileName = FileTools.resolvePath(location + "batman.jpg", false);
imageArray[0] = new IImageComponent(drawPanel, fileName);
fileName = FileTools.resolvePath(location + "lara croft.jpg", false);
imageArray[1] = new IImageComponent(drawPanel, fileName);
}
//drawPanel.removeAll();
drawComponents();
validateTree();
repaint();
}*/
/* public void actionChooseRepresentant(ActionEvent e) {
if (currentDisplay == PANEL_REPRESENTANT)
return;
currentDisplay = PANEL_REPRESENTANT;
if (representantArray.length == 0) {
String location = cfg.getResentantImageDir();
String fileName;
representantArray = new IRepresentant[5];
IRepresentant representant;
fileName = FileTools.resolvePath(location + "camera_movement.jpg", false);
representant = new IRepresentant(drawPanel, IRepresentant.TYPE_CAMERA_MOTION);
representant.setName("Camera Movement");
representant.setEditable(false);
representantArray[0] = representant;
fileName = FileTools.resolvePath(location + "sketch.jpg", false);
representant = new IRepresentant(drawPanel, IRepresentant.TYPE_SKETCH);
representant.setName("Sketch");
representant.setEditable(false);
representantArray[1] = representant;
fileName = FileTools.resolvePath(location + "semantik.jpg", false);
representant = new IRepresentant(drawPanel, IRepresentant.TYPE_SEMANTIC_DESCRIPTION);
representant.setName("Semantic");
representant.setEditable(false);
representantArray[2] = representant;
fileName = FileTools.resolvePath(location + "text.jpg", false);
representant = new IRepresentant(drawPanel, IRepresentant.TYPE_TEXT_DESCRIPTION);
representant.setName("Text");
representant.setEditable(false);
representantArray[3] = representant;
fileName = FileTools.resolvePath(location + "audio.jpg", false);
representant = new IRepresentant(drawPanel, IRepresentant.TYPE_SOUND_FILE);
representant.setName("Audio");
representant.setEditable(false);
representantArray[4] = representant;
}
drawComponents();
validateTree();
repaint();
}*/
protected void addOtherComponent(IComponent component1) {
drawPanel.add(component1);
component1.addMouseListener(component1);
component1.addMouseMotionListener(component1);
component1.revalidate();
}
public void clearComponents() {
drawPanel.removeAll();
}
/*public void setIComponents(IComponent[] componentArray1) {
imageArray = componentArray1;
drawComponents();
}*/
// called to reorganize the drawing Elements
private void drawComponents() {
clearComponents();
// get the component array that has to be drawn
IComponent[] componentArray1 = new IComponent[0];
switch (currentDisplay) {
case PANEL_COLOR:
componentArray1 = colorArray;
break;
case PANEL_SHAPE:
componentArray1 = shapeArray;
break;
case PANEL_IMAGE:
componentArray1 = imageArray;
break;
case PANEL_IMAGE_LIST:
componentArray1 = imageListArray;
break;
case PANEL_REPRESENTANT:
componentArray1 = representantArray;
break;
}
// estimate all needed sizes
int textHeigh = 20;
int componentWidth = elementWidth;
int componentHeigh = elementHeigh - textHeigh;
int maxColums = (drawPanel.getWidth() / (elementWidth + gap));
maxColums = 2;
int row = 0;
int column = 0;
try {
for (int i = 0; i < componentArray1.length; i++) {
//cat.debug("Add new image nr. " + i + ", name " + imageArray[i].toString());
//ImageComponent imageComponent = new ImageComponent((JPanel) mainContainer, imageList[i]);
//System.out.println("Added: " + imageComponent.toString());
IComponent component = componentArray1[i];
if (component == null) {
//cat.debug("null:" + i);
continue;
}
int x = gap + (column * (elementWidth + gap));
int y = gap + (row * (elementHeigh + gap));
int w = componentWidth;
int h = componentHeigh;
component.setDrawBorder(true);
component.setComponentBounds(x, y, w, h);
component.setSize(w, h);
addOtherComponent(component);
// draw the label
String labelText = component.getName();
//labelText = "Hello";
JLabel label = new JLabel(labelText);
label.setBounds(x, (y + componentHeigh),
componentWidth, textHeigh);
label.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
drawPanel.add(label);
//cat.debug("comp: " + component.getComponentBounds().toString() + "; Label: " + label.toString());
if (column < (maxColums - 1)) {
column++;
} else {
column = 0;
row++;
}
} // end for
validate();
} catch (Exception e) {
cat.error(e);
e.printStackTrace();
}
}
public void paint(Graphics g) {
//Graphics2D g2 = (Graphics2D) g;
drawComponents(); // we have to paint ourself
super.paint(g);
validate();
} // end method paint
/**
* set a mouselistenr for mouseEvents on the IComponents
*
* @param mouseListner
*/
public void setListenerForIComponentMouseMovement(MouseListener mouseListner) {
parentMouseListener = mouseListner;
}
} // end class
// data needed to store images and titles for one entry in the image list combo
class ImageListStruct {
private IComponent[] images;
private String title;
public ImageListStruct(IComponent[] images, String title) {
this.images = images;
this.title = title;
}
public IComponent[] getImages() {
return images;
}
public void setImages(IComponent[] images) {
this.images = images;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -