📄 retrievalframe.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) * http://www.juggle.at *//* * @author Mathias Lux, mathias@juggle.at * Date: Sep 23, 2002 * Time: 10:19:01 PM * To change template for new class use * */package at.lux.fotoretrieval;import at.lux.fotoretrieval.panels.*;import at.lux.fotoretrieval.dialogs.AboutDialog;import at.lux.fotoretrieval.dialogs.HelpDialog;import at.lux.fotoretrieval.retrievalengines.LuceneRetrievalEngine;import at.lux.fotoretrieval.lucene.IndexerThread;import at.lux.splash.SplashScreen;import at.lux.StatusBar;import org.jdom.Element;import javax.imageio.ImageIO;import javax.swing.*;import javax.swing.border.BevelBorder;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.util.Properties;import java.util.Vector;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;/** * Main class for retrieval ... */public class RetrievalFrame extends JFrame implements ActionListener, RetrievalOperations, StatusBar { public static final boolean DEBUG = false; public static final String CONFIGURATION_FILE = "emir.conf"; public static String BASE_DIRECTORY = "."; JPanel statusPanel; JProgressBar garbageBar; JLabel status; JTabbedPane tabs; private ContentBasedImageRetrievalPanel cbPanel; private GarbageTracker gTracker; private TextInputSearchPanel searchPanel; private XPathSearchPanel xpathInputPanel; private LuceneSearchPanel luceneInputPanel; private Properties props; private SemanticSearchPanel semanticSearchPanel; public RetrievalFrame() { super(); try { this.setIconImage(ImageIO.read(RetrievalFrame.class.getResource("data/find.gif"))); } catch (Exception e) { debug("Couldn't set Icon: " + e.toString() + " " + e.getMessage()); } init(); } private void init() { setTitle(RetrievalToolkit.PROGRAM_NAME + " " + RetrievalToolkit.PROGRAM_VERSION); // ---------------------------- // Setting Emir props // ---------------------------- props = new Properties(); File conf = new File("./" + CONFIGURATION_FILE); debug("./" + CONFIGURATION_FILE); if (conf.exists()) { try { props.load(new FileInputStream(conf)); } catch (IOException e) { } BASE_DIRECTORY = props.getProperty("basedir", "."); } else { props.setProperty("basedir", BASE_DIRECTORY); } // ---------------------------- // Setting Frame props // ---------------------------- int xwidth = Integer.parseInt(props.getProperty("xwidth", "640")); int ywidth = Integer.parseInt(props.getProperty("ywidth", "480")); setSize(xwidth, ywidth); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); int xloc = Integer.parseInt(props.getProperty("xloc", "" + ( (d.width - this.getWidth()) / 2))); int yloc = Integer.parseInt(props.getProperty("yloc", "" + ( (d.height - this.getHeight()) / 2))); setLocation(xloc, yloc); this.setJMenuBar(RetrievalToolkit.createRetrievalMenuBar(this)); // ---------------------------- // Setting Frame Listeners ... // ---------------------------- this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { exitApplikation(); } }); // ---------------------------- // Creating Components // ---------------------------- cbPanel = new ContentBasedImageRetrievalPanel(this); searchPanel = new TextInputSearchPanel(this); xpathInputPanel = new XPathSearchPanel(this); luceneInputPanel = new LuceneSearchPanel(this); semanticSearchPanel = new SemanticSearchPanel(this); statusPanel = new JPanel(new BorderLayout()); status = new JLabel(RetrievalToolkit.PROGRAM_NAME + " " + RetrievalToolkit.PROGRAM_VERSION); status.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); garbageBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 16); garbageBar.setStringPainted(true); garbageBar.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); garbageBar.setToolTipText("This bar shows how much memory is allocated by the VM and how much of it isalready in use.");// garbageBar.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); gTracker = new GarbageTracker(garbageBar); statusPanel.add(status, BorderLayout.CENTER); statusPanel.add(garbageBar, BorderLayout.EAST); tabs = new JTabbedPane(JTabbedPane.NORTH); tabs.add("Index", luceneInputPanel); tabs.add("Image", cbPanel); tabs.add("Keywords", searchPanel); tabs.add("XPath", xpathInputPanel); tabs.add("Semantics", semanticSearchPanel); this.getContentPane().add(tabs, BorderLayout.CENTER); this.getContentPane().add(statusPanel, BorderLayout.SOUTH); gTracker.start(); } public static void main(String[] args) { RetrievalFrame rf = new RetrievalFrame(); boolean showSplash = true; // get config file from splashscreen class File splashProps = new File(SplashScreen.LICENSE_ACCEPTED_FILENAME); // look if exists if (splashProps.exists()) { // load props try { Properties licenseAcceptedProps = new Properties(); licenseAcceptedProps.load(new FileInputStream(splashProps)); // if property is set we do not have to show the splashscreen: String tmp = licenseAcceptedProps.getProperty("license.accepted"); if (tmp != null && tmp.equals("true")) { showSplash = false; } } catch (IOException e) { System.err.println("Warn: Could not read license properties file."); } } if (showSplash) { // now show the splash screen if this has not been done before. SplashScreen splash = new SplashScreen(rf); splash.setVisible(true); } rf.setVisible(true); } /** * Overides method defined in Interface ActionListener */ public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("exit")) { exitApplikation(); } else if (e.getActionCommand().equals("index")) { createIndex(); } else if (e.getActionCommand().equals("closeTab")) { if (tabs.getSelectedIndex() > 2) { tabs.remove(tabs.getSelectedIndex()); } } else if (e.getActionCommand().equals("about")) { AboutDialog adialog = new AboutDialog(this); adialog.pack(); Dimension ss = Toolkit.getDefaultToolkit().getScreenSize(); adialog.setLocation((ss.width - adialog.getWidth()) / 2, (ss.height - adialog.getHeight()) / 2); adialog.setVisible(true); } else if (e.getActionCommand().equals("help")) { HelpDialog adialog = new HelpDialog(this); // adialog.pack(); Dimension ss = Toolkit.getDefaultToolkit().getScreenSize(); adialog.setLocation((ss.width - adialog.getWidth()) / 2, (ss.height - adialog.getHeight()) / 2); adialog.setVisible(true); } else { JOptionPane.showMessageDialog(this, "Not implemented yet!"); } } public void createIndex() { int answer = JOptionPane.showConfirmDialog(this, "Do you really want to create an index?"); if (answer==JOptionPane.OK_OPTION) { Thread indexer = new Thread(new IndexerThread(this, luceneInputPanel.getPath())); indexer.start(); } } /** * is called before program is exited. */ private void exitApplikation() { debug("Exiting applikation"); // ToDo: Save all props and user-vars props.setProperty("basedir", BASE_DIRECTORY); props.setProperty("xwidth", this.getWidth() + ""); props.setProperty("ywidth", this.getHeight() + ""); props.setProperty("xloc", this.getLocation().x + ""); props.setProperty("yloc", this.getLocation().y + ""); try { props.store(new FileOutputStream("./" + CONFIGURATION_FILE, false), "Emir configuration file (automatically generated)"); debug("Saved configuration to " + "./" + CONFIGURATION_FILE); } catch (IOException e) { debug("Couldn't store " + "./" + CONFIGURATION_FILE); } System.exit(0); } private void debug(String message) { if (RetrievalFrame.DEBUG) { System.out.println("[at.lux.fotoretrieval.RetrievalFrame] " + message); } } public void searchForImage(Element ColorLayoutDescriptor, String directory, boolean descendIntoSubdirs) { debug("Starting search for similar image"); JProgressBar pbar = new JProgressBar(JProgressBar.HORIZONTAL); pbar.setStringPainted(true); Thread t = new SimilarImageSearchThread(ColorLayoutDescriptor, directory, descendIntoSubdirs, this, pbar); t.start(); } public void searchForImage(String xPath, String directory, boolean descendIntoSubdirs) { debug("Starting search for keywords ... "); JProgressBar pbar = new JProgressBar(JProgressBar.HORIZONTAL); pbar.setStringPainted(true); Thread t = new SearchThroughXPathThread(xPath, directory, descendIntoSubdirs, this, pbar); t.start(); } public void searchForImageInIndex(String xPath, String directory, boolean descendIntoSubdirs) { debug("Starting search for keywords ... "); JProgressBar pbar = new JProgressBar(JProgressBar.HORIZONTAL); pbar.setStringPainted(true); Thread t = new SearchThroughLuceneThread(xPath, directory, descendIntoSubdirs, this, pbar); t.start(); } public void searchForImage(String xPath, Vector objects, String directory, boolean descendIntoSubdirs) { debug("Starting search for semantic description ... "); JProgressBar pbar = new JProgressBar(JProgressBar.HORIZONTAL); pbar.setStringPainted(true); Thread t = new SearchSemanticDescriptionThread(xPath, objects, directory, descendIntoSubdirs, this, pbar); t.start(); } public void setStatus(String message) { status.setText(message); } public void addResult(ResultsPanel rp) { tabs.add("Results", rp); tabs.setSelectedIndex(tabs.getTabCount() - 1); } public QualityConstraintPanel getQualityConstraints() { return searchPanel.getQualityConstraints(); } public void searchForSemanticsInIndex(String xPath, String directory, boolean descendIntoSubdirs) { debug("Starting search for semantic annotations ... "); JProgressBar pbar = new JProgressBar(JProgressBar.HORIZONTAL); pbar.setStringPainted(true); Thread t = new SearchSemanticInIndexThread(xPath, directory, descendIntoSubdirs, this, pbar); t.start(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -