⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 semanticobjectrepresentation.java

📁 图像检索的代码b
💻 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) 2002-2004 by Mathias Lux (mathias@juggle.at) and the Know-Center Graz
 * Inffeldgasse 21a, 8010 Graz, Austria
 * http://www.know-center.at
 */

package at.know.center.wv_wr.imb.objectcatalog.semanticscreator;

import org.jdom.Element;

import java.awt.*;
import java.awt.geom.RoundRectangle2D;
/**
 * This file is part of Caliph & Emir.
 * @author Mathias Lux, mathias@juggle.at
 */
public class SemanticObjectRepresentation {
    public static int WIDTH = 100;
    public static int HEIGHT = 50;
    private boolean marked = false;
    private Point p;
    private String label;
    private Element node;

    private boolean highlighted = false;

    public static final Color COLOR_BOX_FILL = new Color(205, 255, 153);
    public static final Color COLOR_BOX_FILL_HIGHLIGHT = Color.red;

    public SemanticObjectRepresentation(Point p, String l) {
        this.p = p;
        this.label = l;
        node = new Element("SemanticBase");
        node.addContent(new Element("Label").addContent(new Element("Name").setText(l)));
    }

    public SemanticObjectRepresentation(Point p, Element n) {
        this.p = p;
        this.label = n.getChild("Label", n.getNamespace()).getChildText("Name", n.getNamespace()).trim();
        this.node = n;
    }

    /**
     * fillcolor not supported any more
     * @param p
     * @param l
     * @param fillColor
     */
    public SemanticObjectRepresentation(Point p, String l, Color fillColor) {
        this.p = p;
        this.label = l;
//        SemanticObjectRepresentation.COLOR_BOX_FILL = COLOR_BOX_FILL;
        // this.r = new Rectangle(p.x,  p.y, 20, 10);
        // this.
    }

    public Element getNode() {
        return node;
    }

    public void drawObject(Graphics2D g2) {
        if (!marked) {
            if (highlighted) {
                g2.setColor(Color.blue);
//                g2.fillOval(p.x, p.y, WIDTH, HEIGHT);
//                g2.fillRect(p.x, p.y, WIDTH, HEIGHT);
                g2.fill(new RoundRectangle2D.Double(p.x, p.y, WIDTH, HEIGHT, 12,12));
                g2.setColor(COLOR_BOX_FILL);
//                g2.fillOval(p.x + 4, p.y + 4, WIDTH - 8, HEIGHT - 8);
//                g2.fillRect(p.x + 4, p.y + 4, WIDTH - 8, HEIGHT - 8);
                g2.fill(new RoundRectangle2D.Double(p.x + 4, p.y + 4, WIDTH - 8, HEIGHT - 8, 12, 12));
            } else {
                g2.setColor(COLOR_BOX_FILL);
                g2.fill(new RoundRectangle2D.Double(p.x, p.y, WIDTH, HEIGHT, 12, 12));
//                g2.fillRect(p.x, p.y, WIDTH, HEIGHT);
                g2.setColor(Color.black);
                g2.draw(new RoundRectangle2D.Double(p.x, p.y, WIDTH, HEIGHT, 12, 12));
//                g2.drawRect(p.x, p.y, WIDTH, HEIGHT);
            }
        } else {
            if (highlighted) {
                g2.setColor(Color.blue);
//                g2.fillRect(p.x, p.y, WIDTH, HEIGHT);
                g2.fill(new RoundRectangle2D.Double(p.x, p.y, WIDTH, HEIGHT, 12,12));
                g2.setColor(COLOR_BOX_FILL_HIGHLIGHT);
//                g2.fillRect(p.x + 4, p.y + 4, WIDTH - 8, HEIGHT - 8);
                g2.fill(new RoundRectangle2D.Double(p.x + 4, p.y + 4, WIDTH - 8, HEIGHT - 8, 12, 12));
            } else {
                g2.setColor(COLOR_BOX_FILL_HIGHLIGHT);
//                g2.fillRect(p.x, p.y, WIDTH, HEIGHT);
                g2.fill(new RoundRectangle2D.Double(p.x, p.y, WIDTH, HEIGHT, 12, 12));
                g2.setColor(Color.black);
                g2.draw(new RoundRectangle2D.Double(p.x, p.y, WIDTH, HEIGHT, 12, 12));
//                g2.drawRect(p.x, p.y, WIDTH, HEIGHT);
            }
        }
        g2.setColor(Color.black);
        int width = g2.getFontMetrics().stringWidth(label);
        // Falls der String zu lang ist wird er gesplittet ...
        if (width > WIDTH) {
            String l1, l2;
            int center1, center, half;
            half = label.length() >> 1;
            center1 = label.indexOf(' ', half);
            center = label.lastIndexOf(' ', half);
            if (Math.abs(half - center1) < Math.abs(half - center))
                center = center1;
            if (center > 0) {
                l1 = label.substring(0, center);
                l2 = label.substring(center + 1);
                width = g2.getFontMetrics().stringWidth(label);
                width = g2.getFontMetrics().stringWidth(l1);
                int height = g2.getFontMetrics().getFont().getSize();
                g2.drawString(l1, (p.x + (WIDTH >> 1)) - (width >> 1), (p.y + (HEIGHT >> 1)) - 2);
                width = g2.getFontMetrics().stringWidth(l2);
                g2.drawString(l2, (p.x + (WIDTH >> 1)) - (width >> 1), (p.y + (HEIGHT >> 1)) + height + 2);
            } else {
                int height = g2.getFontMetrics().getFont().getSize();
                g2.drawString(label, (p.x + (WIDTH >> 1)) - (width >> 1), (p.y + (HEIGHT >> 1)) + (height >> 1));
            }
        } else {
            int height = g2.getFontMetrics().getFont().getSize();
            g2.drawString(label, (p.x + (WIDTH >> 1)) - (width >> 1), (p.y + (HEIGHT >> 1)) + (height >> 1));
        }
    }

    public Rectangle getR() {
        return new Rectangle(p.x, p.y, WIDTH, HEIGHT);
    }

    public void setP(Point p) {
        this.p = p;
    }

    public void setLabel(String l) {
        this.label = l;
    }

    public String getLabel() {
        return label;
    }

    public Point getP() {
        return p;
    }

    public Color getFillColor() {
        return COLOR_BOX_FILL;
    }

    /**
     * not supported any more
     * @param fillColor
     */
    public void setFillColor(Color fillColor) {
//        this.COLOR_BOX_FILL = COLOR_BOX_FILL;
    }

    public boolean isHighlighted() {
        return highlighted;
    }

    public void setHighlighted(boolean highlighted) {
        this.highlighted = highlighted;
    }

    public boolean checkIfInside(Point check) {
        if (check.x <= (p.x + WIDTH) && check.x >= p.x && check.y >= p.y && check.y <= (p.y + HEIGHT)) {
            highlighted = true;
        } else {
            highlighted = false;
        }
        return highlighted;
    }

    public boolean isMarked() {
        return marked;
    }

    public void setMarked(boolean marked) {
        this.marked = marked;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -