The gui currently does nothing else than providing a search window that sends the search string to the browser The gui is started when YaCy is started with the option -g or --gui, like ./startYACY.sh -g The gui will primary be used to provide a 'real' macintosh version that can be started and operated like any other macintosh application. A special mac application wrapper will follow. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7021 6c8d7289-2bf4-0310-a012-ef5d649a1542pull/1/head
parent
d88b9606d1
commit
ec72387165
@ -0,0 +1,135 @@
|
||||
/**
|
||||
* InfoPage
|
||||
* Copyright 2010 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
* First released 05.08.2010 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2010-06-16 17:11:21 +0200 (Mi, 16 Jun 2010) $
|
||||
* $LastChangedRevision: 6922 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.LayoutManager;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.ActionMap;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.InputMap;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
import net.yacy.gui.framework.Browser;
|
||||
import net.yacy.gui.framework.Layout;
|
||||
import net.yacy.gui.framework.Switchboard;
|
||||
|
||||
public class InfoPage implements Layout {
|
||||
|
||||
private static final String COMMIT_ACTION = "commit";
|
||||
|
||||
private static final int width = 500;
|
||||
private static final int height = 600;
|
||||
private static final int textHeight = 18;
|
||||
|
||||
final String host;
|
||||
final int port;
|
||||
JTextComponent SearchBox;
|
||||
|
||||
public InfoPage(String host, int port) {
|
||||
this.host = host; this.port = port;
|
||||
}
|
||||
|
||||
|
||||
private class CommitAction extends AbstractAction {
|
||||
private static final long serialVersionUID = 3630229455629476865L;
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
//int pos = SearchBox.getSelectionEnd();
|
||||
Browser.openBrowser("http://" + host + ":" + port + "/yacysearch.html?display=0&verify=true&contentdom=text&nav=all&maximumRecords=10&startRecord=0&resource=global&urlmaskfilter=.*&prefermaskfilter=&indexof=off&meanCount=5&query=" + SearchBox.getText().replace(' ', '+'));
|
||||
SearchBox.setText("");
|
||||
//SearchBox..insert(" ", pos);
|
||||
//SearchBox.setCaretPosition(pos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public LayoutManager getPage(JComponent context, DocumentListener listener) {
|
||||
GroupLayout page = new GroupLayout(context);
|
||||
|
||||
//String[] fnames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
|
||||
//for (String fname: fnames) System.out.println("font: " + fname);
|
||||
|
||||
Font font = Font.decode("SansSerif");
|
||||
if (font != null) font = font.deriveFont((float) 14.0);
|
||||
//if (font != null) font = font.deriveFont(Font.BOLD);
|
||||
|
||||
SearchBox = new JTextField();
|
||||
SearchBox.setText("search...");
|
||||
SearchBox.setCaretPosition(0);
|
||||
SearchBox.moveCaretPosition(9);
|
||||
SearchBox.setFont(font.deriveFont((float) 14.0).deriveFont(Font.BOLD));
|
||||
SearchBox.setSize(width + 4, textHeight);
|
||||
SearchBox.setBorder(BorderFactory.createEmptyBorder());
|
||||
SearchBox.setBackground(Color.decode("#EEEEDD"));
|
||||
SearchBox.getDocument().addDocumentListener(listener);
|
||||
InputMap im = SearchBox.getInputMap();
|
||||
ActionMap am = SearchBox.getActionMap();
|
||||
im.put(KeyStroke.getKeyStroke("ENTER"), COMMIT_ACTION);
|
||||
am.put(COMMIT_ACTION, new CommitAction());
|
||||
|
||||
Switchboard.InfoBox = new JTextField();
|
||||
Switchboard.InfoBox.setBorder(BorderFactory.createTitledBorder(""));
|
||||
Switchboard.InfoBox.setSize(width, textHeight);
|
||||
Switchboard.InfoBox.setBorder(BorderFactory.createEmptyBorder());
|
||||
Switchboard.InfoBox.setBackground(Color.decode("#EEEEDD"));
|
||||
Switchboard.InfoBox.setText("search window initialized");
|
||||
Switchboard.InfoBox.setFont(font.deriveFont((float) 11.0));
|
||||
|
||||
// make the scroll pane that contains the search result
|
||||
JComponent mainText = new JEditorPane();
|
||||
mainText.setPreferredSize(new java.awt.Dimension(480, 590));
|
||||
((JEditorPane) mainText).setText("This is a very early test for a YaCy search gui.\nYou may enter a search term and press enter.");
|
||||
//page.add(new splashCanvas());
|
||||
|
||||
//SplashScreen splash = SplashScreen.getSplashScreen();
|
||||
//Graphics2D g2 = splash.createGraphics();
|
||||
//splash.update();
|
||||
|
||||
JScrollPane pane = new JScrollPane();
|
||||
pane.setViewportView(mainText);
|
||||
|
||||
// combine search box and scroll pane
|
||||
page.setVerticalGroup(page.createSequentialGroup()
|
||||
.addComponent(SearchBox, GroupLayout.PREFERRED_SIZE, textHeight + 4, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(pane, 0, height, Short.MAX_VALUE) // height
|
||||
.addComponent(Switchboard.InfoBox, GroupLayout.PREFERRED_SIZE, textHeight, GroupLayout.PREFERRED_SIZE)
|
||||
);
|
||||
page.setHorizontalGroup(page.createSequentialGroup()
|
||||
.addGroup(page.createParallelGroup()
|
||||
.addComponent(SearchBox, GroupLayout.Alignment.LEADING, 0, width, Short.MAX_VALUE) // width
|
||||
.addComponent(pane, GroupLayout.Alignment.LEADING, 0, width, Short.MAX_VALUE)
|
||||
.addComponent(Switchboard.InfoBox, GroupLayout.Alignment.TRAILING, 0, width, Short.MAX_VALUE)));
|
||||
return page;
|
||||
}
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
/**
|
||||
* YaCyApp
|
||||
* Copyright 2010 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
* First released 05.08.2010 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2010-06-16 17:11:21 +0200 (Mi, 16 Jun 2010) $
|
||||
* $LastChangedRevision: 6922 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.gui;
|
||||
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import net.yacy.gui.framework.Application;
|
||||
import net.yacy.gui.framework.Operation;
|
||||
import net.yacy.gui.framework.Switchboard;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class YaCyApp {
|
||||
|
||||
public static Logger log = Logger.getLogger(YaCyApp.class);
|
||||
private static JFrame app;
|
||||
private static Operation operation;
|
||||
private static BufferedImage splashImg = null;
|
||||
private static File splashFile = null;
|
||||
static {
|
||||
try {
|
||||
javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
if (splashFile != null) splashImg = ImageIO.read(splashFile);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public class splashCanvas extends Canvas {
|
||||
private static final long serialVersionUID = -8823028472678019008L;
|
||||
ImageObserver obs;
|
||||
public splashCanvas(ImageObserver obs) { this.obs = obs; }
|
||||
public void paint(Graphics g) {
|
||||
if (splashImg != null) g.drawImage(splashImg, 0, 0, obs);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Op implements Operation {
|
||||
|
||||
JFrame app;
|
||||
final String host;
|
||||
final int port;
|
||||
|
||||
public Op(JFrame app, String host, int port) {
|
||||
this.app = app;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void closeAndExit() {
|
||||
if (app != null) app.setVisible(false); // fake closing
|
||||
//Browser.openBrowser("http://" + host + ":" + port + "/Steering.html?shutdown=");
|
||||
de.anomic.search.Switchboard.getSwitchboard().terminate(100, "shutdown request from gui");
|
||||
Switchboard.shutdown();
|
||||
//System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void start(String host, int port) {
|
||||
|
||||
Switchboard.startInfoUpdater();
|
||||
operation = new Op(app, host, port);
|
||||
|
||||
final List<JMenu> menues = new ArrayList<JMenu>();
|
||||
|
||||
// the file menu
|
||||
JMenu FileMenu = new JMenu("File");
|
||||
JMenuItem OpenItem = new JMenuItem("Open");
|
||||
OpenItem.setEnabled(false);
|
||||
JMenuItem QuitItem = new JMenuItem("Quit");
|
||||
QuitItem.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
operation.closeAndExit();
|
||||
}
|
||||
});
|
||||
FileMenu.add(OpenItem);
|
||||
FileMenu.add(QuitItem);
|
||||
menues.add(FileMenu);
|
||||
|
||||
// the edit menu
|
||||
JMenu EditMenu = new JMenu("Edit");
|
||||
JMenuItem CutItem = new JMenuItem("Cut");
|
||||
CutItem.setEnabled(false);
|
||||
JMenuItem CopyItem = new JMenuItem("Copy");
|
||||
CopyItem.setEnabled(false);
|
||||
JMenuItem PasteItem = new JMenuItem("Paste");
|
||||
PasteItem.setEnabled(false);
|
||||
EditMenu.add(CutItem);
|
||||
EditMenu.add(CopyItem);
|
||||
EditMenu.add(PasteItem);
|
||||
menues.add(EditMenu);
|
||||
|
||||
// registering shutdown hook
|
||||
log.info("Registering Shutdown Hook");
|
||||
Switchboard.addShutdownHook(Thread.currentThread());
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
app = new Application("YaCy GUI", operation, menues, new InfoPage("localhost", 8080));
|
||||
app.setLocationRelativeTo(null);
|
||||
app.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
if (args.length > 0) Switchboard.load(new File(args[0]));
|
||||
start("localhost", 8080);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Application
|
||||
* Copyright 2010 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
* First released 05.08.2010 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2010-06-16 17:11:21 +0200 (Mi, 16 Jun 2010) $
|
||||
* $LastChangedRevision: 6922 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.gui.framework;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
|
||||
import javax.swing.WindowConstants;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
|
||||
public class Application extends JFrame implements DocumentListener {
|
||||
|
||||
private static final long serialVersionUID = 1753502658600073141L;
|
||||
|
||||
public Application(String windowName, final Operation operation, List<JMenu> menues, Layout pageprovider) {
|
||||
super(windowName);
|
||||
|
||||
try {
|
||||
getContentPane().setLayout(pageprovider.getPage((JComponent) getContentPane(), this));
|
||||
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
operation.closeAndExit();
|
||||
}
|
||||
});
|
||||
this.addWindowStateListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
operation.closeAndExit();
|
||||
}
|
||||
});
|
||||
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
|
||||
// make menus
|
||||
JMenuBar mainMenu = new JMenuBar();
|
||||
setJMenuBar(mainMenu);
|
||||
for (JMenu menu: menues) mainMenu.add(menu);
|
||||
|
||||
pack();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,156 @@
|
||||
/**
|
||||
* Browser
|
||||
* Copyright 2010 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
* First released 05.08.2010 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2010-06-16 17:11:21 +0200 (Mi, 16 Jun 2010) $
|
||||
* $LastChangedRevision: 6922 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.gui.framework;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.yacy.kelondro.logging.Log;
|
||||
|
||||
public class Browser {
|
||||
|
||||
// constants for system identification
|
||||
public static final int systemMacOSC = 0; // 'classic' Mac OS 7.6.1/8.*/9.*
|
||||
public static final int systemMacOSX = 1; // all Mac OS X
|
||||
public static final int systemUnix = 2; // all Unix/Linux type systems
|
||||
public static final int systemWindows = 3; // all Windows 95/98/NT/2K/XP
|
||||
public static final int systemUnknown = -1; // any other system
|
||||
|
||||
// constants for file type identification (Mac only)
|
||||
public static final String blankTypeString = "____";
|
||||
|
||||
// system-identification statics
|
||||
public static final int systemOS;
|
||||
public static final boolean isMacArchitecture;
|
||||
public static final boolean isUnixFS;
|
||||
public static final boolean canExecUnix;
|
||||
public static final boolean isWindows;
|
||||
public static final boolean isWin32;
|
||||
|
||||
// calculated system constants
|
||||
public static int maxPathLength = 65535;
|
||||
|
||||
// Macintosh-specific statics
|
||||
private static Class<?> macMRJFileUtils = null;
|
||||
private static Method macOpenURL = null;
|
||||
|
||||
// static initialization
|
||||
static {
|
||||
// check operation system type
|
||||
final Properties sysprop = System.getProperties();
|
||||
final String sysname = sysprop.getProperty("os.name","").toLowerCase();
|
||||
if (sysname.startsWith("mac os x")) systemOS = systemMacOSX;
|
||||
else if (sysname.startsWith("mac os")) systemOS = systemMacOSC;
|
||||
else if (sysname.startsWith("windows")) systemOS = systemWindows;
|
||||
else if ((sysname.startsWith("linux")) || (sysname.startsWith("unix"))) systemOS = systemUnix;
|
||||
else systemOS = systemUnknown;
|
||||
|
||||
isMacArchitecture = ((systemOS == systemMacOSC) || (systemOS == systemMacOSX));
|
||||
isUnixFS = ((systemOS == systemMacOSX) || (systemOS == systemUnix));
|
||||
canExecUnix = ((isUnixFS) || (!((systemOS == systemMacOSC) || (systemOS == systemWindows))));
|
||||
isWindows = (systemOS == systemWindows);
|
||||
isWin32 = (isWindows && System.getProperty("os.arch", "").contains("x86"));
|
||||
|
||||
// set up the MRJ Methods through reflection
|
||||
if (isMacArchitecture) try {
|
||||
macMRJFileUtils = Class.forName("com.apple.mrj.MRJFileUtils");
|
||||
macOpenURL = macMRJFileUtils.getMethod("openURL", new Class[] {Class.forName("java.lang.String")});
|
||||
final byte[] nullb = new byte[4];
|
||||
for (int i = 0; i < 4; i++) nullb[i] = 0;
|
||||
} catch (final Exception e) {
|
||||
//Log.logException(e);
|
||||
macMRJFileUtils = null;
|
||||
}
|
||||
|
||||
// set up maximum path length according to system
|
||||
if (isWindows) maxPathLength = 255; else maxPathLength = 65535;
|
||||
}
|
||||
|
||||
|
||||
public static void openBrowser(final String url) {
|
||||
openBrowser(url, "firefox");
|
||||
}
|
||||
|
||||
public static void openBrowser(final String url, final String app) {
|
||||
try {
|
||||
String cmd;
|
||||
Process p;
|
||||
if (systemOS != systemUnknown) {
|
||||
if (systemOS == systemMacOSC) {
|
||||
if ((isMacArchitecture) && (macMRJFileUtils != null)) {
|
||||
macOpenURL.invoke(null, new Object[] {url});
|
||||
}
|
||||
} else if (systemOS == systemMacOSX) {
|
||||
p = Runtime.getRuntime().exec(new String[] {"/usr/bin/osascript", "-e", "open location \"" + url + "\""});
|
||||
p.waitFor();
|
||||
if (p.exitValue() != 0) throw new RuntimeException("EXEC ERROR: " + errorResponse(p));
|
||||
} else if (systemOS == systemUnix) {
|
||||
cmd = app + " -remote openURL(" + url + ")";
|
||||
p = Runtime.getRuntime().exec(cmd);
|
||||
p.waitFor();
|
||||
if (p.exitValue() != 0) {
|
||||
cmd = app + " " + url;
|
||||
p = Runtime.getRuntime().exec(cmd);
|
||||
// no error checking, because it blocks until firefox is closed
|
||||
}
|
||||
} else if (systemOS == systemWindows) {
|
||||
// see forum at http://forum.java.sun.com/thread.jsp?forum=57&thread=233364&message=838441
|
||||
if (System.getProperty("os.name").contains("2000")) cmd = "rundll32 url.dll,FileProtocolHandler " + url;
|
||||
else cmd = "rundll32 url.dll,FileProtocolHandler \"" + url + "\"";
|
||||
//cmd = "cmd.exe /c start javascript:document.location='" + url + "'";
|
||||
p = Runtime.getRuntime().exec(cmd);
|
||||
p.waitFor();
|
||||
if (p.exitValue() != 0) throw new RuntimeException("EXEC ERROR: " + errorResponse(p));
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
System.err.println("ERROR "+ e.getClass() +" in openBrowser(): "+ e.getMessage());
|
||||
// browser could not be started automatically, tell user to do it
|
||||
System.out.println("please start your browser and open the following location: " + url);
|
||||
}
|
||||
}
|
||||
|
||||
private static String errorResponse(final Process p) {
|
||||
final BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
||||
String line, error = "";
|
||||
try {
|
||||
while ((line = err.readLine()) != null) {
|
||||
error = line + "\n";
|
||||
}
|
||||
return error;
|
||||
} catch (final IOException e) {
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
err.close();
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Layout
|
||||
* Copyright 2010 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
* First released 05.08.2010 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2010-06-16 17:11:21 +0200 (Mi, 16 Jun 2010) $
|
||||
* $LastChangedRevision: 6922 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.gui.framework;
|
||||
|
||||
import java.awt.LayoutManager;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
public interface Layout {
|
||||
|
||||
public LayoutManager getPage(JComponent context, DocumentListener listener);
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Operation
|
||||
* Copyright 2010 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
* First released 05.08.2010 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2010-06-16 17:11:21 +0200 (Mi, 16 Jun 2010) $
|
||||
* $LastChangedRevision: 6922 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.gui.framework;
|
||||
|
||||
public interface Operation {
|
||||
|
||||
public void closeAndExit();
|
||||
}
|
@ -0,0 +1,239 @@
|
||||
/**
|
||||
* Switchboard
|
||||
* Copyright 2010 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
* First released 05.08.2010 at http://yacy.net
|
||||
*
|
||||
* $LastChangedDate: 2010-06-16 17:11:21 +0200 (Mi, 16 Jun 2010) $
|
||||
* $LastChangedRevision: 6922 $
|
||||
* $LastChangedBy: orbiter $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.gui.framework;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* a static class that holds application-wide parameters
|
||||
* very useful because global settings need not be passed
|
||||
* to all classes and methods
|
||||
*
|
||||
* @author m.christen
|
||||
*
|
||||
*/
|
||||
public class Switchboard {
|
||||
|
||||
/**
|
||||
* the shallrun variable is used
|
||||
* by all application parts to see if they must terminate
|
||||
*/
|
||||
private static boolean shallrun = true;
|
||||
|
||||
/**
|
||||
* a global properties object
|
||||
*/
|
||||
private static Properties properties = new Properties();
|
||||
|
||||
public static Logger log = Logger.getLogger(Switchboard.class);
|
||||
|
||||
|
||||
public static void startInfoUpdater() {
|
||||
new InfoUpdater(2000).start();
|
||||
}
|
||||
|
||||
public static void addShutdownHook(Thread mainThread) {
|
||||
// registering shutdown hook
|
||||
final Runtime run = Runtime.getRuntime();
|
||||
run.addShutdownHook(new shutdownHookThread(mainThread));
|
||||
}
|
||||
|
||||
public static JTextComponent InfoBox = null;
|
||||
private static String InfoBoxMessage = "";
|
||||
private static long InfoBoxMessageUntil = 0;
|
||||
|
||||
public static void info(String infoString, long infoTime) {
|
||||
InfoBoxMessage = infoString;
|
||||
InfoBoxMessageUntil = System.currentTimeMillis() + infoTime;
|
||||
}
|
||||
|
||||
public static class InfoUpdater extends Thread {
|
||||
long steptime;
|
||||
public InfoUpdater(long steptime) {
|
||||
this.steptime = steptime;
|
||||
}
|
||||
public void run() {
|
||||
while (shallrun) {
|
||||
if (InfoBox != null) {
|
||||
if (System.currentTimeMillis() < InfoBoxMessageUntil) {
|
||||
InfoBox.setText(InfoBoxMessage);
|
||||
}
|
||||
}
|
||||
try {Thread.sleep(steptime);} catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is a helper class whose instance is started, when the java virtual
|
||||
* machine shuts down. Signals the plasmaSwitchboard to shut down.
|
||||
*/
|
||||
public static class shutdownHookThread extends Thread {
|
||||
private final Thread mainThread;
|
||||
|
||||
public shutdownHookThread(final Thread mainThread) {
|
||||
super();
|
||||
this.mainThread = mainThread;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
if (shallrun()) {
|
||||
log.info("Shutdown via shutdown hook.");
|
||||
|
||||
// send a shutdown signal to the switchboard
|
||||
log.info("Signaling shutdown to the switchboard.");
|
||||
shutdown();
|
||||
|
||||
// waiting for the main thread to finish execution
|
||||
log.info("Waiting for main thread to finish.");
|
||||
if (this.mainThread != null && this.mainThread.isAlive()) {
|
||||
this.mainThread.join();
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
log.info("Unexpected error. " + e.getClass().getName(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test if the application shall run
|
||||
* @return true if the application shall run
|
||||
*/
|
||||
public static boolean shallrun() {
|
||||
return shallrun;
|
||||
}
|
||||
|
||||
/**
|
||||
* set a termination signal.
|
||||
* this is not reversible.
|
||||
*/
|
||||
public static void shutdown() {
|
||||
shallrun = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize the properties with the content of a file
|
||||
* @param propFile
|
||||
*/
|
||||
public static void load(File propFile) {
|
||||
try {
|
||||
properties.load(new FileInputStream(propFile));
|
||||
} catch (FileNotFoundException e1) {
|
||||
log.info("error: file dispatcher.properties does not exist. Exit");
|
||||
System.exit(-1);
|
||||
} catch (IOException e1) {
|
||||
log.info("error: file dispatcher.properties cannot be readed. Exit");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* access to the properties object
|
||||
* @param key
|
||||
* @return the property value or null if the property does not exist
|
||||
*/
|
||||
public static String get(String key) {
|
||||
return properties.getProperty(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* access to the properties object
|
||||
* @param key
|
||||
* @param dflt
|
||||
* @return
|
||||
*/
|
||||
public static String get(String key, String dflt) {
|
||||
return properties.getProperty(key, dflt);
|
||||
}
|
||||
|
||||
/**
|
||||
* convenience access to integer values in properties
|
||||
* @param key
|
||||
* @param dflt
|
||||
* @return
|
||||
*/
|
||||
public static int getInt(String key, int dflt) {
|
||||
if (!properties.containsKey(key)) return dflt;
|
||||
return Integer.parseInt(properties.getProperty(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* convenience access to boolean values in properties
|
||||
* @param key
|
||||
* @param dflt
|
||||
* @return
|
||||
*/
|
||||
public static boolean getBool(String key, boolean dflt) {
|
||||
if (!properties.containsKey(key)) return dflt;
|
||||
String s = properties.getProperty(key);
|
||||
return s.equals("true") || s.equals("1");
|
||||
}
|
||||
|
||||
public static File getFile(String key) {
|
||||
String s = properties.getProperty(key);
|
||||
if (s == null) return null;
|
||||
s.replace("/", File.separator);
|
||||
return new File(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* set a property
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public static void set(String key, String value) {
|
||||
properties.setProperty(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* convenience method to set a integer property
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public static void set(String key, int value) {
|
||||
properties.setProperty(key, Integer.toString(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* convenience method to set a boolean property
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public static void set(String key, boolean value) {
|
||||
properties.setProperty(key, (value) ? "true" : "false");
|
||||
}
|
||||
}
|
Loading…
Reference in new issue