Importing release version 322 from old repos
This commit is contained in:
398
src/jalopy.format.convention.xml
Normal file
398
src/jalopy.format.convention.xml
Normal file
@@ -0,0 +1,398 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<jalopy>
|
||||
<general>
|
||||
<compliance>
|
||||
<version>1</version>
|
||||
</compliance>
|
||||
<style>
|
||||
<description>Jalopy convention definitions for the JavaEVA project</description>
|
||||
<name>JavaEVA convention</name>
|
||||
</style>
|
||||
</general>
|
||||
<inspector>
|
||||
<enable>false</enable>
|
||||
<naming>
|
||||
<classes>
|
||||
<abstract>[A-Z][a-zA-Z0-9]+</abstract>
|
||||
<general>[A-Z][a-zA-Z0-9]+</general>
|
||||
</classes>
|
||||
<fields>
|
||||
<default>[a-z][\w]+</default>
|
||||
<defaultStatic>[a-z][\w]+</defaultStatic>
|
||||
<defaultStaticFinal>[a-zA-Z][\w]+</defaultStaticFinal>
|
||||
<private>[a-z][\w]+</private>
|
||||
<privateStatic>[a-z][\w]+</privateStatic>
|
||||
<privateStaticFinal>[a-zA-Z][\w]+</privateStaticFinal>
|
||||
<protected>[a-z][\w]+</protected>
|
||||
<protectedStatic>[a-z][\w]+</protectedStatic>
|
||||
<protectedStaticFinal>[a-zA-Z][\w]+</protectedStaticFinal>
|
||||
<public>[a-z][\w]+</public>
|
||||
<publicStatic>[a-z][\w]+</publicStatic>
|
||||
<publicStaticFinal>[a-zA-Z][\w]+</publicStaticFinal>
|
||||
</fields>
|
||||
<interfaces>[A-Z][a-zA-Z0-9]+</interfaces>
|
||||
<labels>\w+</labels>
|
||||
<methods>
|
||||
<default>[a-z][\w]+</default>
|
||||
<defaultStatic>[a-z][\w]+</defaultStatic>
|
||||
<defaultStaticFinal>[a-z][\w]+</defaultStaticFinal>
|
||||
<private>[a-z][\w]+</private>
|
||||
<privateStatic>[a-z][\w]+</privateStatic>
|
||||
<privateStaticFinal>[a-z][\w]+</privateStaticFinal>
|
||||
<protected>[a-z][\w]+</protected>
|
||||
<protectedStatic>[a-z][\w]+</protectedStatic>
|
||||
<protectedStaticFinal>[a-z][\w]+</protectedStaticFinal>
|
||||
<public>[a-z][\w]+</public>
|
||||
<publicStatic>[a-z][\w]+</publicStatic>
|
||||
<publicStaticFinal>[a-z][\w]+</publicStaticFinal>
|
||||
</methods>
|
||||
<packages>[a-z]+(?:\.[a-z]+)*</packages>
|
||||
<parameters>
|
||||
<default>[a-z][\w]+</default>
|
||||
<final>[a-z][\w]+</final>
|
||||
</parameters>
|
||||
<variables>[a-z][\w]*</variables>
|
||||
</naming>
|
||||
<tips>
|
||||
<adhereToNamingConvention>false</adhereToNamingConvention>
|
||||
<alwaysOverrideEquals>false</alwaysOverrideEquals>
|
||||
<alwaysOverrideHashCode>false</alwaysOverrideHashCode>
|
||||
<avoidThreadGroups>false</avoidThreadGroups>
|
||||
<declareCollectionComment>false</declareCollectionComment>
|
||||
<dontIgnoreExceptions>false</dontIgnoreExceptions>
|
||||
<dontSubstituteObjectEquals>false</dontSubstituteObjectEquals>
|
||||
<neverDeclareException>false</neverDeclareException>
|
||||
<neverDeclareThrowable>false</neverDeclareThrowable>
|
||||
<neverInvokeWaitOutsideLoop>false</neverInvokeWaitOutsideLoop>
|
||||
<neverReturnZeroArrays>false</neverReturnZeroArrays>
|
||||
<neverUseEmptyFinally>false</neverUseEmptyFinally>
|
||||
<obeyContractEquals>false</obeyContractEquals>
|
||||
<overrideToString>false</overrideToString>
|
||||
<referToObjectsByInterface>false</referToObjectsByInterface>
|
||||
<replaceStructureWithClass>false</replaceStructureWithClass>
|
||||
<stringLiterallI18n>false</stringLiterallI18n>
|
||||
<useInterfaceOnlyForTypes>false</useInterfaceOnlyForTypes>
|
||||
<wrongCollectionComment>false</wrongCollectionComment>
|
||||
</tips>
|
||||
</inspector>
|
||||
<internal>
|
||||
<version>6</version>
|
||||
</internal>
|
||||
<messages>
|
||||
<priority>
|
||||
<general>30000</general>
|
||||
<parser>30000</parser>
|
||||
<parserJavadoc>30000</parserJavadoc>
|
||||
<printer>30000</printer>
|
||||
<printerJavadoc>30000</printerJavadoc>
|
||||
<transform>30000</transform>
|
||||
</priority>
|
||||
<showErrorStackTrace>true</showErrorStackTrace>
|
||||
</messages>
|
||||
<misc>
|
||||
<threadCount>1</threadCount>
|
||||
</misc>
|
||||
<printer>
|
||||
<alignment>
|
||||
<methodCallChain>true</methodCallChain>
|
||||
<parameterMethodDeclaration>false</parameterMethodDeclaration>
|
||||
<ternaryOperator>true</ternaryOperator>
|
||||
<variableAssignment>false</variableAssignment>
|
||||
<variableIdentifier>false</variableIdentifier>
|
||||
</alignment>
|
||||
<backup>
|
||||
<directory>bak</directory>
|
||||
<level>0</level>
|
||||
</backup>
|
||||
<blanklines>
|
||||
<after>
|
||||
<block>1</block>
|
||||
<braceLeft>1</braceLeft>
|
||||
<class>1</class>
|
||||
<declaration>0</declaration>
|
||||
<footer>1</footer>
|
||||
<header>0</header>
|
||||
<interface>1</interface>
|
||||
<lastImport>2</lastImport>
|
||||
<method>1</method>
|
||||
<package>1</package>
|
||||
</after>
|
||||
<before>
|
||||
<block>1</block>
|
||||
<braceRight>0</braceRight>
|
||||
<caseBlock>1</caseBlock>
|
||||
<comment>
|
||||
<javadoc>1</javadoc>
|
||||
<multiline>1</multiline>
|
||||
<singleline>1</singleline>
|
||||
</comment>
|
||||
<controlStatement>1</controlStatement>
|
||||
<declaration>1</declaration>
|
||||
<footer>0</footer>
|
||||
<header>0</header>
|
||||
</before>
|
||||
<keepUpTo>1</keepUpTo>
|
||||
</blanklines>
|
||||
<braces>
|
||||
<empty>
|
||||
<cuddle>false</cuddle>
|
||||
<insertStatement>false</insertStatement>
|
||||
</empty>
|
||||
<insert>
|
||||
<dowhile>true</dowhile>
|
||||
<for>true</for>
|
||||
<ifelse>true</ifelse>
|
||||
<while>true</while>
|
||||
</insert>
|
||||
<remove>
|
||||
<block>true</block>
|
||||
<dowhile>false</dowhile>
|
||||
<for>false</for>
|
||||
<ifelse>false</ifelse>
|
||||
<while>false</while>
|
||||
</remove>
|
||||
<treatDifferent>
|
||||
<methodClass>false</methodClass>
|
||||
<methodClassIfWrapped>false</methodClassIfWrapped>
|
||||
</treatDifferent>
|
||||
</braces>
|
||||
<chunks>
|
||||
<blanklines>true</blanklines>
|
||||
<comments>true</comments>
|
||||
</chunks>
|
||||
<comments>
|
||||
<format>
|
||||
<multiline>false</multiline>
|
||||
</format>
|
||||
<javadoc>
|
||||
<check>
|
||||
<innerclass>false</innerclass>
|
||||
<tags>false</tags>
|
||||
<throwsTags>false</throwsTags>
|
||||
</check>
|
||||
<fieldsShort>true</fieldsShort>
|
||||
<generate>
|
||||
<class>1</class>
|
||||
<constructor>0</constructor>
|
||||
<field>0</field>
|
||||
<method>0</method>
|
||||
</generate>
|
||||
<parseComments>false</parseComments>
|
||||
<tags>
|
||||
<in-line />
|
||||
<standard />
|
||||
</tags>
|
||||
<templates>
|
||||
<method>
|
||||
<bottom> */</bottom>
|
||||
<exception> * @throws $exceptionType$ DOCUMENT ME!</exception>
|
||||
<param> * @param $paramType$ DOCUMENT ME!</param>
|
||||
<return> * @return DOCUMENT ME!</return>
|
||||
<top>/**| * DOCUMENT ME!</top>
|
||||
</method>
|
||||
</templates>
|
||||
</javadoc>
|
||||
<remove>
|
||||
<javadoc>false</javadoc>
|
||||
<multiline>false</multiline>
|
||||
<singleline>false</singleline>
|
||||
</remove>
|
||||
<separator>
|
||||
<fillCharacter>/</fillCharacter>
|
||||
<insert>true</insert>
|
||||
<insertRecursive>false</insertRecursive>
|
||||
<text>
|
||||
<class>Inner Classes</class>
|
||||
<constructor>Constructors</constructor>
|
||||
<field>Instance fields</field>
|
||||
<initializer>Instance initializers</initializer>
|
||||
<interface>Inner Interfaces</interface>
|
||||
<method>Methods</method>
|
||||
<static>Static fields/initializers</static>
|
||||
</text>
|
||||
</separator>
|
||||
</comments>
|
||||
<environment />
|
||||
<footer>
|
||||
<keys />
|
||||
<smartMode>5</smartMode>
|
||||
<text>///////////////////////////////////////////////////////////////////////////////
|
||||
// END OF FILE.
|
||||
///////////////////////////////////////////////////////////////////////////////</text>
|
||||
<use>true</use>
|
||||
</footer>
|
||||
|
||||
<!-- header should not used, because there are some LGPL sources and other authors -->
|
||||
<header>
|
||||
<keys>JavaEVA header</keys>
|
||||
<smartMode>5</smartMode>
|
||||
<text>///////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: $RCSfile$
|
||||
// Language: Java
|
||||
// Compiler: JDK 1.4
|
||||
// Authors: Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
// Version: $Revision: 10 $
|
||||
// $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
// $Author: streiche $
|
||||
//
|
||||
// Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
|
||||
///////////////////////////////////////////////////////////////////////////////</text>
|
||||
<use>false</use>
|
||||
</header>
|
||||
<history>
|
||||
<policy>disabled</policy>
|
||||
</history>
|
||||
<imports>
|
||||
<grouping>
|
||||
<defaultDepth>3</defaultDepth>
|
||||
<packages>*:1|gnu:2|java:2|javax:2|org:2|com:2|net:2|joelib:2</packages>
|
||||
</grouping>
|
||||
<policy>expand</policy>
|
||||
<sort>true</sort>
|
||||
</imports>
|
||||
|
||||
<indentation>
|
||||
<caseFromSwitch>false</caseFromSwitch>
|
||||
<continuation>
|
||||
<block>true</block>
|
||||
<operator>false</operator>
|
||||
</continuation>
|
||||
<firstColumnComments>true</firstColumnComments>
|
||||
<label>false</label>
|
||||
<policy>
|
||||
<deep>false</deep>
|
||||
</policy>
|
||||
<sizes>
|
||||
<braceCuddled>1</braceCuddled>
|
||||
<braceLeft>0</braceLeft>
|
||||
<braceRight>0</braceRight>
|
||||
<braceRightAfter>1</braceRightAfter>
|
||||
<continuation>4</continuation>
|
||||
<deep>55</deep>
|
||||
<extends>-1</extends>
|
||||
<general>4</general>
|
||||
<implements>-1</implements>
|
||||
<leading>0</leading>
|
||||
<tabs>8</tabs>
|
||||
<throws>-1</throws>
|
||||
<trailingComment>1</trailingComment>
|
||||
</sizes>
|
||||
<tabs>
|
||||
<enable>false</enable>
|
||||
<onlyLeading>false</onlyLeading>
|
||||
</tabs>
|
||||
</indentation>
|
||||
<misc>
|
||||
<arrayBracketsAfterIdent>false</arrayBracketsAfterIdent>
|
||||
<forceFormatting>true</forceFormatting>
|
||||
<insertExpressionParentheses>true</insertExpressionParentheses>
|
||||
<insertLoggingConditional>true</insertLoggingConditional>
|
||||
<insertTrailingNewline>true</insertTrailingNewline>
|
||||
<insertUID>false</insertUID>
|
||||
</misc>
|
||||
<sorting>
|
||||
<declaration>
|
||||
<class>false</class>
|
||||
<constructor>true</constructor>
|
||||
<enable>false</enable>
|
||||
<interface>false</interface>
|
||||
<method>false</method>
|
||||
<order>static|field|initializer|constructor|method|interface|class</order>
|
||||
<variable>true</variable>
|
||||
</declaration>
|
||||
<modifier>
|
||||
<enable>false</enable>
|
||||
<order>public|protected|private|abstract|static|final|synchronized|transient|volatile|native|strictfp</order>
|
||||
</modifier>
|
||||
</sorting>
|
||||
|
||||
<whitespace>
|
||||
<after>
|
||||
<comma>true</comma>
|
||||
<semicolon>true</semicolon>
|
||||
<typeCast>true</typeCast>
|
||||
</after>
|
||||
<before>
|
||||
<braces>false</braces>
|
||||
<brackets>false</brackets>
|
||||
<bracketsTypes>false</bracketsTypes>
|
||||
<caseColon>false</caseColon>
|
||||
<operator>
|
||||
<not>false</not>
|
||||
</operator>
|
||||
<parentheses>
|
||||
<methodCall>false</methodCall>
|
||||
<methodDeclaration>false</methodDeclaration>
|
||||
<statement>true</statement>
|
||||
</parentheses>
|
||||
</before>
|
||||
<padding>
|
||||
<braces>false</braces>
|
||||
<brackets>false</brackets>
|
||||
<operator>
|
||||
<assignment>true</assignment>
|
||||
<bitwise>true</bitwise>
|
||||
<logical>true</logical>
|
||||
<mathematical>true</mathematical>
|
||||
<relational>true</relational>
|
||||
<shift>true</shift>
|
||||
</operator>
|
||||
<parenthesis>false</parenthesis>
|
||||
<typeCast>false</typeCast>
|
||||
</padding>
|
||||
</whitespace>
|
||||
<wrapping>
|
||||
<always>
|
||||
<after>
|
||||
<arrayElement>0</arrayElement>
|
||||
<braceRight>true</braceRight>
|
||||
<extendsTypes>false</extendsTypes>
|
||||
<implementsTypes>false</implementsTypes>
|
||||
<label>true</label>
|
||||
<methodCallChained>false</methodCallChained>
|
||||
<ternaryOperator>
|
||||
<first>false</first>
|
||||
<second>false</second>
|
||||
</ternaryOperator>
|
||||
<throwsTypes>false</throwsTypes>
|
||||
</after>
|
||||
<before>
|
||||
<braceLeft>false</braceLeft>
|
||||
<extends>false</extends>
|
||||
<implements>false</implements>
|
||||
<throws>false</throws>
|
||||
</before>
|
||||
<parameter>
|
||||
<methodCall>false</methodCall>
|
||||
<methodCallNested>false</methodCallNested>
|
||||
<methodDeclaration>false</methodDeclaration>
|
||||
</parameter>
|
||||
</always>
|
||||
<general>
|
||||
<beforeOperator>false</beforeOperator>
|
||||
<enable>true</enable>
|
||||
<lineLength>80</lineLength>
|
||||
</general>
|
||||
<ondemand>
|
||||
<after>
|
||||
<assignment>false</assignment>
|
||||
<leftParenthesis>false</leftParenthesis>
|
||||
<parameter>false</parameter>
|
||||
<types>
|
||||
<extends>false</extends>
|
||||
<implements>false</implements>
|
||||
<throws>false</throws>
|
||||
</types>
|
||||
</after>
|
||||
<before>
|
||||
<rightParenthesis>false</rightParenthesis>
|
||||
</before>
|
||||
<groupingParentheses>false</groupingParentheses>
|
||||
</ondemand>
|
||||
</wrapping>
|
||||
</printer>
|
||||
</jalopy>
|
||||
|
||||
<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
END OF FILE
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
|
||||
35
src/javaeva/client/AppExitAction.java
Normal file
35
src/javaeva/client/AppExitAction.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package javaeva.client;
|
||||
|
||||
import javaeva.gui.ExtAction;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 12.05.2003
|
||||
* Time: 18:28:54
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class AppExitAction extends ExtAction implements WindowListener{
|
||||
public AppExitAction(String s, String toolTip, KeyStroke key){
|
||||
super(s, toolTip, key);
|
||||
}
|
||||
private void exit(){
|
||||
System.exit(1);
|
||||
}
|
||||
public void actionPerformed(ActionEvent e){exit();}
|
||||
public void windowOpened(WindowEvent e){}
|
||||
public void windowClosed(WindowEvent e){}
|
||||
public void windowIconified(WindowEvent e){ }
|
||||
public void windowDeiconified(WindowEvent e){ }
|
||||
public void windowActivated(WindowEvent e){ }
|
||||
public void windowDeactivated(WindowEvent e){ }
|
||||
public void windowClosing(WindowEvent e){exit();}
|
||||
}
|
||||
726
src/javaeva/client/EvAClient.java
Normal file
726
src/javaeva/client/EvAClient.java
Normal file
@@ -0,0 +1,726 @@
|
||||
package javaeva.client;
|
||||
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 322 $
|
||||
* $Date: 2007-12-11 17:24:07 +0100 (Tue, 11 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Event;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.Serializable;
|
||||
import java.util.Properties;
|
||||
|
||||
import javaeva.gui.ExtAction;
|
||||
import javaeva.gui.JEFrame;
|
||||
import javaeva.gui.JEFrameRegister;
|
||||
import javaeva.gui.JExtMenu;
|
||||
import javaeva.gui.JTabbedModuleFrame;
|
||||
import javaeva.gui.LogPanel;
|
||||
import javaeva.server.EvAServer;
|
||||
import javaeva.server.modules.ModuleAdapter;
|
||||
import javaeva.tools.EVAERROR;
|
||||
import javaeva.tools.EVAHELP;
|
||||
import javaeva.tools.Serializer;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JRadioButtonMenuItem;
|
||||
import javax.swing.JWindow;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import javax.swing.event.MenuEvent;
|
||||
import javax.swing.event.MenuListener;
|
||||
|
||||
import wsi.ra.jproxy.RemoteStateListener;
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
|
||||
/**
|
||||
/////////////////////////////////
|
||||
// -Xrunhprof:cpu=samples
|
||||
/////////////////////////////////////////////////
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class EvAClient implements RemoteStateListener, Serializable {
|
||||
public static final String EVA_PROPERTY_FILE = "resources/JavaEvA.props";
|
||||
private static Properties EVA_PROPERTIES;
|
||||
public static final String iconLocation = "resources/images/JavaEvAIcon_3.gif";
|
||||
|
||||
public static boolean TRACE = false;
|
||||
private static String m_ProductName = "JavaEvA";
|
||||
// private int PREFERRED_WIDTH = 680;
|
||||
// private int PREFERRED_HEIGHT = 550;
|
||||
private JWindow m_splashScreen;
|
||||
public JEFrame m_Frame;
|
||||
|
||||
private EvAComAdapter m_ComAdapter;
|
||||
// private JExtDesktopPane m_Desktop;
|
||||
private transient JMenuBar m_barMenu;
|
||||
private transient JExtMenu m_mnuAbout;
|
||||
private transient JExtMenu m_mnuSelHosts;
|
||||
private transient JExtMenu m_mnuModule;
|
||||
private transient JExtMenu m_mnuWindow;
|
||||
private transient JExtMenu m_mnuOptions;
|
||||
private transient JProgressBar m_ProgressBar;
|
||||
|
||||
// public ArrayList m_ModulGUIContainer = new ArrayList();
|
||||
// LogPanel
|
||||
private LogPanel m_LogPanel;
|
||||
|
||||
// Module:
|
||||
private ExtAction m_actModuleLoad;
|
||||
// GUI:
|
||||
|
||||
// Hosts:
|
||||
private ExtAction m_actHost;
|
||||
private ExtAction m_actAvailableHost;
|
||||
private ExtAction m_actKillHost;
|
||||
private ExtAction m_actKillAllHosts;
|
||||
// private ArrayList m_ModuleAdapterList = new ArrayList();
|
||||
// About:
|
||||
private ExtAction m_actAbout;
|
||||
|
||||
// private JPanel m_panelTool;
|
||||
// private FrameCloseListener m_frameCloseListener;
|
||||
// private JFileChooser m_FileChooser;
|
||||
|
||||
// if not null, the module is loaded automatically and no other can be selected
|
||||
private String useDefaultModule = null;//"Genetic_Optimization";
|
||||
private boolean showLoadModules = false;
|
||||
private boolean localMode = false;
|
||||
// This variable says whether, if running locally, a local server should be addressed by RMI.
|
||||
// False should be preferred here to avoid overhead
|
||||
private boolean useLocalRMI = false;
|
||||
// measuring optimization runtime
|
||||
private long startTime = 0;
|
||||
// remember the module in use
|
||||
private transient String currentModule = null;
|
||||
|
||||
public static String getProperty(String key) {
|
||||
String myVal = EVA_PROPERTIES.getProperty(key);
|
||||
return myVal;
|
||||
}
|
||||
|
||||
public static Properties getProperties() {
|
||||
return EVA_PROPERTIES;
|
||||
}
|
||||
|
||||
public static void setProperty(String key, String value) {
|
||||
EVA_PROPERTIES.setProperty(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Statically loading Properties.
|
||||
*/
|
||||
static {
|
||||
try {
|
||||
EVA_PROPERTIES = BasicResourceLoader.readProperties(EVA_PROPERTY_FILE);
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Could not read the configuration file "+ EVA_PROPERTY_FILE);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of GUI of JavaEva.
|
||||
* Works as client for the JavaEva server.
|
||||
*
|
||||
*/
|
||||
public EvAClient(String hostName) {
|
||||
createSplashScreen();
|
||||
currentModule = null;
|
||||
|
||||
m_ComAdapter = EvAComAdapter.getInstance();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (m_splashScreen != null) m_splashScreen.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
//init();
|
||||
try {
|
||||
Thread.sleep(6000);
|
||||
} catch (Exception e) {
|
||||
System.out.println("error" + e.getMessage());
|
||||
}
|
||||
if (m_splashScreen != null) m_splashScreen.setVisible(false);
|
||||
m_splashScreen = null;
|
||||
}
|
||||
});
|
||||
init(hostName);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void init(String hostName) {
|
||||
//EVA_EDITOR_PROPERTIES
|
||||
useDefaultModule = getProperty("DefaultModule");
|
||||
|
||||
if (useDefaultModule != null) {
|
||||
useDefaultModule = useDefaultModule.trim();
|
||||
if (useDefaultModule.length() < 1) useDefaultModule = null;
|
||||
}
|
||||
|
||||
|
||||
m_Frame = new JEFrame();
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(iconLocation);
|
||||
try {
|
||||
m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find JavaEvA icon, please move rescoure folder to working directory!");
|
||||
}
|
||||
m_Frame.setTitle("JavaEvA workbench");
|
||||
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error" + e.getMessage());
|
||||
}
|
||||
|
||||
m_Frame.getContentPane().setLayout(new BorderLayout());
|
||||
m_LogPanel = new LogPanel();
|
||||
m_Frame.getContentPane().add(m_LogPanel, BorderLayout.CENTER);
|
||||
m_ProgressBar = new JProgressBar();
|
||||
m_Frame.getContentPane().add(m_ProgressBar, BorderLayout.SOUTH);
|
||||
|
||||
if (getProperty("ShowModules") != null) showLoadModules = true;
|
||||
else showLoadModules = false; // may be set to true again if default module couldnt be loaded
|
||||
|
||||
createActions();
|
||||
|
||||
if (useDefaultModule != null) {
|
||||
loadModuleFromServer(useDefaultModule);//loadSpecificModule
|
||||
}
|
||||
|
||||
buildMenu();
|
||||
|
||||
m_Frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.out.println("Closing JavaEvA Client. Bye!");
|
||||
System.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
if (m_ComAdapter != null) {
|
||||
if (hostName != null) selectHost(hostName);
|
||||
m_ComAdapter.setLogPanel(m_LogPanel);
|
||||
logMessage("Selected Host: " + m_ComAdapter.getHostName());
|
||||
}
|
||||
// m_mnuModule.setText("Select module");
|
||||
// m_mnuModule.repaint();
|
||||
|
||||
m_LogPanel.logMessage("Class path is: " + System.getProperty("java.class.path","."));
|
||||
|
||||
if (!(m_Frame.isVisible())) {
|
||||
m_Frame.pack();
|
||||
m_Frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the JavaEvA splash screen.
|
||||
*/
|
||||
public void createSplashScreen() {
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation("resources/images/JavaEvaSplashScreen.png");
|
||||
try {
|
||||
ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
JLabel splashLabel = new JLabel(ii);
|
||||
m_splashScreen = new JWindow();
|
||||
m_splashScreen.getContentPane().add(splashLabel);
|
||||
m_splashScreen.pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
//splashScreen.setSize(screenSize);
|
||||
m_splashScreen.setLocation(screenSize.width / 2 - m_splashScreen.getSize().width / 2, screenSize.height / 2 - m_splashScreen.getSize().height / 2);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.err.println("Could not find JavaEvA splash screen, please move rescoure folder to working directory!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The one and only main of the client programm.
|
||||
*
|
||||
* @param args command line parameters
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
if (TRACE) {
|
||||
System.out.println(EVAHELP.getSystemPropertyString());
|
||||
}
|
||||
EvAClient Client = new EvAClient((args.length == 1) ? args[0] : null);
|
||||
}
|
||||
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// public void addInternalFrame(JInternalFrame newFrame) {
|
||||
// m_Desktop.add(newFrame);
|
||||
// newFrame.toFront();
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void createActions() {
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Module:
|
||||
/////////////////////////////////////////////////////////////
|
||||
m_actModuleLoad = new ExtAction("&Load", "Load Module",
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK)) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
loadModuleFromServer(null);
|
||||
}
|
||||
};
|
||||
|
||||
m_actAbout = new ExtAction("&About...", "Product Information",
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
logMessage(e.getActionCommand());
|
||||
showAboutDialog();
|
||||
}
|
||||
};
|
||||
m_actHost = new ExtAction("&List of all servers", "All servers in list",
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
logMessage(e.getActionCommand());
|
||||
selectAvailableHost(m_ComAdapter.getHostNameList());
|
||||
}
|
||||
};
|
||||
m_actAvailableHost = new ExtAction("Available &Server", "Available server",
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK)) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
logMessage(e.getActionCommand());
|
||||
showPleaseWaitDialog();
|
||||
Thread xx = new Thread() {
|
||||
public void run() {
|
||||
selectAvailableHost(m_ComAdapter.getAvailableHostNameList());
|
||||
}
|
||||
};
|
||||
xx.start();
|
||||
}
|
||||
};
|
||||
m_actKillHost = new ExtAction("&Kill server", "Kill server process on selected host",
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK)) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
logMessage(e.getActionCommand());
|
||||
showPleaseWaitDialog();
|
||||
Thread xx = new Thread() {
|
||||
public void run() {
|
||||
selectAvailableHostToKill(m_ComAdapter.getAvailableHostNameList());
|
||||
}
|
||||
};
|
||||
xx.start();
|
||||
}
|
||||
};
|
||||
m_actKillAllHosts = new ExtAction("Kill &all server", "Kill all server",
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK)) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
logMessage(e.getActionCommand());
|
||||
showPleaseWaitDialog();
|
||||
Thread xx = new Thread() {
|
||||
public void run() {
|
||||
selectAllAvailableHostToKill(m_ComAdapter.getAvailableHostNameList());
|
||||
}
|
||||
};
|
||||
xx.start();
|
||||
}
|
||||
};
|
||||
/* m_actStartServerManager = new ExtAction("Start &Server Manager", "Start &Server Manager",
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK)){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
m_LogPanel.logMessage(e.getActionCommand());
|
||||
ServerStartFrame sm = new ServerStartFrame(m_ComAdapter.getHostNameList());
|
||||
}
|
||||
};
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void buildMenu() {
|
||||
m_barMenu = new JMenuBar();
|
||||
m_Frame.setJMenuBar(m_barMenu);
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
JExtMenu mnuLookAndFeel = new JExtMenu("&Look and Feel");
|
||||
ButtonGroup grpLookAndFeel = new ButtonGroup();
|
||||
UIManager.LookAndFeelInfo laf[] = UIManager.getInstalledLookAndFeels();
|
||||
// if (TRACE) {
|
||||
// for (int i=0;i<3;i++)
|
||||
// System.out.println(laf[i].getName());
|
||||
// System.out.println ("->"+UIManager.getLookAndFeel().getClass().getName());
|
||||
// }
|
||||
|
||||
String LAF = Serializer.loadString("LookAndFeel.ser");
|
||||
|
||||
boolean lafSelected = false;
|
||||
for (int i = 0; i < laf.length; i++) {
|
||||
JRadioButtonMenuItem mnuItem = new JRadioButtonMenuItem(laf[i].getName());
|
||||
mnuItem.setActionCommand(laf[i].getClassName());
|
||||
if (!lafSelected && laf[i].getClassName().equals(UIManager.getLookAndFeel().getClass().getName())) {
|
||||
// if (!lafSelected && laf[i].getClassName().equals(UIManager.getSystemLookAndFeelClassName())) {
|
||||
// if (LAF==null) {// do this only if no older selection one could be loaded
|
||||
// LAF = laf[i].getClassName(); // set for later selection
|
||||
// } // this causes problems with my gnome!
|
||||
if (LAF == null) {
|
||||
lafSelected = true;
|
||||
mnuItem.setSelected(true);
|
||||
}
|
||||
}
|
||||
mnuItem.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(e.getActionCommand());
|
||||
SwingUtilities.updateComponentTreeUI(m_Frame);
|
||||
// hier noch reinhacken dass alle frame geupdated werden.
|
||||
m_Frame.pack();
|
||||
// m_Frame.setSize(new Dimension(900, 700));
|
||||
// m_Frame.setVisible(true);
|
||||
Serializer.storeString("LookAndFeel.ser", e.getActionCommand());
|
||||
} catch (ClassNotFoundException exc) {} catch (InstantiationException exc) {} catch (UnsupportedLookAndFeelException exc) {} catch (
|
||||
IllegalAccessException exc) {}
|
||||
}
|
||||
});
|
||||
mnuLookAndFeel.add(mnuItem);
|
||||
grpLookAndFeel.add(mnuItem);
|
||||
}
|
||||
if (LAF != null) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(LAF);
|
||||
SwingUtilities.updateComponentTreeUI(m_Frame);
|
||||
m_Frame.pack();
|
||||
// m_Frame.setSize(new Dimension(900, 700));
|
||||
// m_Frame.setVisible(true);
|
||||
} catch (ClassNotFoundException exc) {} catch (InstantiationException exc) {} catch (UnsupportedLookAndFeelException exc) {} catch (
|
||||
IllegalAccessException exc) {}
|
||||
}
|
||||
m_mnuModule = new JExtMenu("Select &module");
|
||||
m_mnuModule.add(m_actModuleLoad);
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
m_mnuWindow = new JExtMenu("&Window");
|
||||
m_mnuWindow.addMenuListener(new MenuListener() {
|
||||
public void menuSelected(MenuEvent e) {
|
||||
// System.out.println("Selected");
|
||||
m_mnuWindow.removeAll();
|
||||
Object[] framelist = JEFrameRegister.getFrameList();
|
||||
for (int i = 0; i < framelist.length; i++) {
|
||||
JMenuItem act = new JMenuItem((i + 1) + ". " + ((JEFrame) framelist[i]).getTitle());
|
||||
final JFrame x = ((JEFrame) framelist[i]);
|
||||
act.addActionListener((new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
x.setExtendedState(JFrame.NORMAL);
|
||||
x.toFront();
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
m_mnuWindow.add(act);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void menuCanceled(MenuEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void menuDeselected(MenuEvent e) {
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
m_mnuSelHosts = new JExtMenu("&Select Hosts");
|
||||
m_mnuSelHosts.setToolTipText("Select a host for the server application");
|
||||
//if (EvAClient.LITE_VERSION == false)
|
||||
m_mnuSelHosts.add(m_actHost);
|
||||
m_mnuSelHosts.add(m_actAvailableHost);
|
||||
m_mnuSelHosts.addSeparator();
|
||||
m_mnuSelHosts.add(m_actKillHost);
|
||||
m_mnuSelHosts.add(m_actKillAllHosts);
|
||||
// m_mnuOptions.add(m_actStartServerManager);
|
||||
////////////////////////////////////////////////////////////////
|
||||
m_mnuAbout = new JExtMenu("&About");
|
||||
m_mnuAbout.add(m_actAbout);
|
||||
//////////////////////////////////////////////////////////////
|
||||
// m_barMenu.add(m_Desktop.getWindowMenu());
|
||||
|
||||
m_mnuOptions = new JExtMenu("&Options");
|
||||
m_mnuOptions.add(mnuLookAndFeel);
|
||||
m_mnuOptions.add(m_mnuSelHosts);
|
||||
//m_barMenu.add(m_mnuSelHosts);
|
||||
// this is accessible if no default module is given
|
||||
if (showLoadModules) {
|
||||
m_barMenu.add(m_mnuModule);
|
||||
}
|
||||
|
||||
m_barMenu.add(m_mnuOptions);
|
||||
m_barMenu.add(m_mnuWindow);
|
||||
m_barMenu.add(m_mnuAbout);
|
||||
|
||||
}
|
||||
|
||||
protected void logMessage(String msg) {
|
||||
if (TRACE || m_LogPanel == null) System.out.println(msg);
|
||||
if (m_LogPanel != null) m_LogPanel.logMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void loadModuleFromServer(String selectedModule) {
|
||||
if (m_ComAdapter.getHostName() == null) {
|
||||
System.err.println("error in loadModuleFromServer!");
|
||||
return;
|
||||
}
|
||||
if (m_ComAdapter.getHostName().equals("localhost")) {
|
||||
localMode = true;
|
||||
if (useLocalRMI) {
|
||||
EvAServer Server = new EvAServer(true, false);
|
||||
m_ComAdapter.setLocalRMIServer(Server.getRMIServer());
|
||||
logMessage("Local EvAServer started");
|
||||
m_ComAdapter.setRunLocally(false); // this is not quite true but should have the desired effect
|
||||
} else {
|
||||
logMessage("Working locally");
|
||||
m_ComAdapter.setLocalRMIServer(null);
|
||||
m_ComAdapter.setRunLocally(true);
|
||||
}
|
||||
} else {
|
||||
localMode = false;
|
||||
if (TRACE) logMessage("Using RMI on m_ComAdapter.getHostName()");
|
||||
m_ComAdapter.setRunLocally(false);
|
||||
}
|
||||
if (selectedModule == null) { // show a dialog and ask for a module
|
||||
String[] ModuleNameList = m_ComAdapter.getModuleNameList();
|
||||
if (ModuleNameList == null) {
|
||||
JOptionPane.showMessageDialog(m_Frame.getContentPane(), "No modules available on " + m_ComAdapter.getHostName(), "JavaEvA Information", 1);
|
||||
} else {
|
||||
String LastModuleName = Serializer.loadString("lastmodule.ser");
|
||||
if (LastModuleName == null) LastModuleName = ModuleNameList[0];
|
||||
selectedModule = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(),
|
||||
"Which module do you want \n to load on host: " + m_ComAdapter.getHostName() + " ?", "Load optimization module on host",
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
ModuleNameList,
|
||||
LastModuleName);
|
||||
}
|
||||
}
|
||||
if (selectedModule == null) {
|
||||
System.err.println("not loading any module");
|
||||
} else {
|
||||
Serializer.storeString("lastmodule.ser", selectedModule);
|
||||
|
||||
loadSpecificModule(selectedModule);
|
||||
|
||||
m_actHost.setEnabled(true);
|
||||
m_actAvailableHost.setEnabled(true);
|
||||
logMessage("Selected Module: " + selectedModule);
|
||||
// m_LogPanel.statusMessage("Selected Module: " + selectedModule);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSpecificModule(String selectedModule) {
|
||||
ModuleAdapter newModuleAdapter = null;
|
||||
//
|
||||
try {
|
||||
newModuleAdapter = m_ComAdapter.getModuleAdapter(selectedModule);
|
||||
} catch (Exception e) {
|
||||
logMessage("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
EVAERROR.EXIT("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage());
|
||||
}
|
||||
if (newModuleAdapter == null) showLoadModules = true;
|
||||
else {
|
||||
newModuleAdapter.setConnection(!localMode);
|
||||
if (m_ComAdapter.isRunLocally()) {
|
||||
// TODO in rmi-mode this doesnt work yet!
|
||||
newModuleAdapter.addRemoteStateListener((RemoteStateListener)this);
|
||||
}
|
||||
try {
|
||||
// this (or rather: JModuleGeneralPanel) is where the start button etc come from!
|
||||
JTabbedModuleFrame Temp = newModuleAdapter.getModuleFrame();
|
||||
// newModuleAdapter.setLogPanel(m_LogPanel);
|
||||
|
||||
JPanel moduleContainer = Temp.createContentPane(); // MK the frame is actually painted in here
|
||||
// m_Frame.setLayout(new BorderLayout());
|
||||
m_Frame.setVisible(false);
|
||||
m_Frame.getContentPane().removeAll();
|
||||
|
||||
// nested info-panel so that we can stay with simple borderlayouts
|
||||
JPanel infoPanel = new JPanel();
|
||||
infoPanel.setLayout(new BorderLayout());
|
||||
infoPanel.add(m_ProgressBar, BorderLayout.SOUTH);
|
||||
infoPanel.add(m_LogPanel, BorderLayout.NORTH);
|
||||
|
||||
m_Frame.add(Temp.getToolBar(), BorderLayout.NORTH);
|
||||
m_Frame.add(moduleContainer, BorderLayout.CENTER);
|
||||
//m_Frame.add(m_ProgressBar, BorderLayout.CENTER);
|
||||
//m_Frame.add(m_LogPanel, BorderLayout.SOUTH);
|
||||
m_Frame.add(infoPanel, BorderLayout.SOUTH);
|
||||
|
||||
m_Frame.pack();
|
||||
m_Frame.setVisible(true);
|
||||
|
||||
currentModule = selectedModule;
|
||||
// m_ModulGUIContainer.add(Temp);
|
||||
} catch (Exception e) {
|
||||
currentModule = null;
|
||||
e.printStackTrace();
|
||||
logMessage("Error while newModulAdapter.getModulFrame(): " + e.getMessage());
|
||||
EVAERROR.EXIT("Error while newModulAdapter.getModulFrame(): " + e.getMessage());
|
||||
}
|
||||
// try { TODO whats this?
|
||||
// newModuleAdapter.setConnection(true);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// m_LogPanel.logMessage("Error while m_ComAdapter.AddRMIPlotListener Host: " + e.getMessage());
|
||||
// EVAERROR.EXIT("Error while m_ComAdapter.AddRMIPlotListener: " + e.getMessage());
|
||||
// }
|
||||
// set mode (rmi or not)
|
||||
|
||||
// ModuladapterListe adden
|
||||
// m_ModuleAdapterList.add(newModuleAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void selectAvailableHost(String[] HostNames) {
|
||||
if (TRACE) System.out.println("SelectAvailableHost");
|
||||
if (HostNames == null || HostNames.length == 0) {
|
||||
showNoHostFoundDialog();
|
||||
} else {
|
||||
String HostName = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(),
|
||||
"Which active host do you want to connect to?", "Host", JOptionPane.QUESTION_MESSAGE, null,
|
||||
HostNames, m_ComAdapter.getHostName());
|
||||
if (HostName != null) selectHost(HostName);
|
||||
}
|
||||
}
|
||||
|
||||
private void selectHost(String hostName) {
|
||||
m_ComAdapter.setHostName(hostName);
|
||||
logMessage("Selected Host: " + hostName);
|
||||
if (currentModule != null) {
|
||||
logMessage("Reloading module from server...");
|
||||
loadModuleFromServer(currentModule);
|
||||
}
|
||||
|
||||
// m_mnuModule.setText("Select module");
|
||||
// m_mnuModule.repaint();
|
||||
// System.out.println(HostName + " selected");
|
||||
}
|
||||
|
||||
private void showPleaseWaitDialog() {
|
||||
JOptionPane.showMessageDialog(m_Frame.getContentPane(), "Please wait one moment.", "JavaEvA Information", 1);
|
||||
}
|
||||
|
||||
private void showAboutDialog() {
|
||||
JOptionPane.showMessageDialog
|
||||
(m_Frame,
|
||||
m_ProductName +
|
||||
"\n University of Tuebingen\n Computer Architecture\n Holger Ulmer & Felix Streichert & Hannes Planatscher \n Prof. Dr. Andreas Zell \n (c) 2007 \n Version " +
|
||||
EvAServer.Version + " \n http://www-ra.informatik.uni-tuebingen.de/software/JavaEvA/", "JavaEvA Information", 1);
|
||||
}
|
||||
|
||||
private void showNoHostFoundDialog() {
|
||||
JOptionPane.showMessageDialog(m_Frame.getContentPane(), "No host with running EVASERVER found. Please start one or \nadd the correct address to the properties list.", "JavaEvA Information", 1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void selectAvailableHostToKill(String[] HostNames) {
|
||||
if (TRACE) System.out.println("SelectAvailableHostToKill");
|
||||
if (HostNames == null || HostNames.length == 0) {
|
||||
showNoHostFoundDialog();
|
||||
return;
|
||||
}
|
||||
String HostName = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(),
|
||||
"Which server do you want to be killed ?", "Host", JOptionPane.QUESTION_MESSAGE, null,
|
||||
HostNames, m_ComAdapter.getHostName());
|
||||
if (HostName == null)
|
||||
return;
|
||||
logMessage("Kill host process on = " + HostName);
|
||||
m_ComAdapter.killServer(HostName);
|
||||
// m_LogPanel.statusMessage("");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void selectAllAvailableHostToKill(String[] HostNames) {
|
||||
System.out.println("SelectAllAvailableHostToKill");
|
||||
if (HostNames == null || HostNames.length == 0) {
|
||||
System.out.println("no host is running");
|
||||
return;
|
||||
}
|
||||
m_ComAdapter.killAllServers();
|
||||
}
|
||||
|
||||
public void performedRestart(String infoString) {
|
||||
logMessage("Restarted " + infoString);
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void performedStart(String infoString) {
|
||||
logMessage("Started " + infoString);
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void performedStop() {
|
||||
long t = (System.currentTimeMillis() - startTime);
|
||||
logMessage(String.format("Stopped after %1$d.%2$tL s", (t / 1000), (t % 1000)));
|
||||
}
|
||||
|
||||
/**
|
||||
* When the worker needs to update the GUI we do so by queuing
|
||||
* a Runnable for the event dispatching thread with
|
||||
* SwingUtilities.invokeLater(). In this case we're just
|
||||
* changing the progress bars value.
|
||||
*/
|
||||
public void updateProgress(final int percent) {
|
||||
if (this.m_ProgressBar != null) {
|
||||
Runnable doSetProgressBarValue = new Runnable() {
|
||||
public void run() {
|
||||
m_ProgressBar.setValue(percent);
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(doSetProgressBarValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
137
src/javaeva/client/EvAComAdapter.java
Normal file
137
src/javaeva/client/EvAComAdapter.java
Normal file
@@ -0,0 +1,137 @@
|
||||
package javaeva.client;
|
||||
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 320 $
|
||||
* $Date: 2007-12-06 16:05:11 +0100 (Thu, 06 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.util.ArrayList;
|
||||
import javaeva.gui.LogPanel;
|
||||
import javaeva.server.EvAMainAdapter;
|
||||
import javaeva.server.EvAMainAdapterImpl;
|
||||
import javaeva.server.RMIServerEvA;
|
||||
import javaeva.server.modules.ModuleAdapter;
|
||||
|
||||
import wsi.ra.jproxy.ComAdapter;
|
||||
import wsi.ra.jproxy.MainAdapter;
|
||||
import wsi.ra.jproxy.MainAdapterClient;
|
||||
import wsi.ra.jproxy.MainAdapterClientImpl;
|
||||
import wsi.ra.jproxy.RMIConnection;
|
||||
import wsi.ra.jproxy.RMIInvocationHandler;
|
||||
import wsi.ra.jproxy.RMIProxyLocal;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class EvAComAdapter extends ComAdapter {
|
||||
private LogPanel m_LogPanel;
|
||||
private EvAMainAdapterImpl localMainAdapter;
|
||||
private boolean runLocally = false;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setLogPanel(LogPanel OutputFrame) {
|
||||
m_LogPanel = OutputFrame;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static EvAComAdapter getInstance() {
|
||||
if (m_instance==null) {
|
||||
m_instance = new EvAComAdapter();
|
||||
m_instance.addServersFromProperties(EvAClient.getProperties());
|
||||
}
|
||||
return (EvAComAdapter)m_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the ModulAdapters RMI Object on the server
|
||||
* @return
|
||||
*/
|
||||
public ModuleAdapter getModuleAdapter(String str) {
|
||||
ModuleAdapter newModuleAdapter;
|
||||
if ((m_RMIServer == null) && isRunLocally()) {
|
||||
//ret = evaAdapter.getModuleAdapter(Modul, hostAdd, this.m_MainAdapterClient);
|
||||
newModuleAdapter = getLocalMainAdapter().getModuleAdapter(str, true, getHostName(), null);
|
||||
} else {
|
||||
newModuleAdapter = ((RMIConnectionEvA)getConnection(getHostName())).getModuleAdapter(str);
|
||||
if (newModuleAdapter == null) System.err.println("RMI Error for getting ModuleAdapterObject : " + str);
|
||||
}
|
||||
return newModuleAdapter;
|
||||
}
|
||||
|
||||
private EvAMainAdapter getLocalMainAdapter() {
|
||||
if (localMainAdapter == null) localMainAdapter = new EvAMainAdapterImpl();
|
||||
return localMainAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of modules available on the server.
|
||||
* @return
|
||||
*/
|
||||
public String[] getModuleNameList() {
|
||||
String[] list;
|
||||
if (TRACE) System.out.println("ComAdapter.GetModuleNameList()");
|
||||
|
||||
if ((m_RMIServer == null) && isRunLocally()) {
|
||||
list = getLocalMainAdapter().getModuleNameList();
|
||||
} else {
|
||||
RMIConnectionEvA Connection = (RMIConnectionEvA)getConnection(getHostName());
|
||||
if (Connection == null) {
|
||||
System.err.println("Couldnt create RMIConnection in EvAComAdapter.getModuleNameList");
|
||||
return null;
|
||||
}
|
||||
list = ((EvAMainAdapter)Connection.getMainAdapter()).getModuleNameList();
|
||||
}
|
||||
if (m_LogPanel != null)
|
||||
m_LogPanel.logMessage("List of modules on server:");
|
||||
if (list != null)
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if ( (String) list[i] != null && m_LogPanel != null)
|
||||
m_LogPanel.logMessage( (String) list[i]);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected MainAdapter getMainAdapter(RMIInvocationHandler invocHandler) throws RemoteException {
|
||||
return (EvAMainAdapter) invocHandler.getWrapper();
|
||||
}
|
||||
|
||||
protected void logInfo(String msg) {
|
||||
if (m_LogPanel != null) {
|
||||
m_LogPanel.logMessage(msg);
|
||||
} else super.logInfo(msg);
|
||||
}
|
||||
|
||||
protected RMIConnection createRMIConnection(String Host, MainAdapter mainRemoteObject, MainAdapterClient client) {
|
||||
return new RMIConnectionEvA(Host, mainRemoteObject, client);
|
||||
}
|
||||
/**
|
||||
* @return the runLocally
|
||||
*/
|
||||
public boolean isRunLocally() {
|
||||
return runLocally;
|
||||
}
|
||||
/**
|
||||
* @param runLocally the runLocally to set
|
||||
*/
|
||||
public void setRunLocally(boolean runLocally) {
|
||||
this.runLocally = runLocally;
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
53
src/javaeva/client/RMIConnectionEvA.java
Normal file
53
src/javaeva/client/RMIConnectionEvA.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package javaeva.client;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javaeva.server.EvAMainAdapter;
|
||||
import javaeva.server.modules.ModuleAdapter;
|
||||
import wsi.ra.jproxy.MainAdapter;
|
||||
import wsi.ra.jproxy.MainAdapterClient;
|
||||
import wsi.ra.jproxy.RMIConnection;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class RMIConnectionEvA extends RMIConnection {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public RMIConnectionEvA(String HostName, MainAdapter Adapter,
|
||||
MainAdapterClient AdapterClient) {
|
||||
super(HostName, Adapter, AdapterClient);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ModuleAdapter getModuleAdapter(String Modul) {
|
||||
if (m_MainAdapter instanceof EvAMainAdapter) {
|
||||
EvAMainAdapter evaAdapter = (EvAMainAdapter)m_MainAdapter;
|
||||
ModuleAdapter ret = null;
|
||||
if (TRACE) System.out.println("ComAdapter.getModuleAdapter(" + Modul + ")");
|
||||
String hostAdd = "";
|
||||
try {
|
||||
hostAdd = InetAddress.getLocalHost().getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
hostAdd = "unknown host";
|
||||
}
|
||||
if (TRACE) {
|
||||
System.out.println(" Client is = " + hostAdd);
|
||||
}
|
||||
m_MainAdapter.setBuf("Test_1");
|
||||
|
||||
ret = evaAdapter.getModuleAdapter(Modul, false, hostAdd, this.m_MainAdapterClient);
|
||||
|
||||
return ret;
|
||||
} else {
|
||||
System.err.println("error, couldnt get module adapter in EvAComAdapter.getModuleAdapter. Main adapter is not of type EvAMainAdapter!");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
309
src/javaeva/gui/BeanTest.java
Normal file
309
src/javaeva/gui/BeanTest.java
Normal file
@@ -0,0 +1,309 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 202 $
|
||||
* $Date: 2007-10-25 16:12:49 +0200 (Thu, 25 Oct 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.beans.*;
|
||||
import java.lang.reflect.Method;
|
||||
//import javaeva.server.oa.es.mutation.*;
|
||||
import javaeva.tools.*;
|
||||
import javaeva.server.EvAServer;
|
||||
/*
|
||||
* ==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
* ==========================================================================
|
||||
*/
|
||||
public class BeanTest {
|
||||
public static boolean TRACE = false;
|
||||
|
||||
public static int step = 0;
|
||||
public static String check(String s) {
|
||||
|
||||
s=s.replace('$','_');
|
||||
s=s.replace(';','_');
|
||||
// String ret = null;
|
||||
// try {
|
||||
// RE r = new RE("\\[");
|
||||
// ret = r.subst(s,"");
|
||||
// //ret.substring();
|
||||
// //ret
|
||||
// } catch (Exception e) {e.getMessage();};
|
||||
// System.out.println("s="+s+" ret"+ret);
|
||||
if (s.equals("[D")) return "Double_Array";
|
||||
if (s.startsWith("[D")) return s.substring(2);
|
||||
if (s.startsWith("[L")) return s.substring(2);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static boolean equalProperties(Object Target_1, Object Target_2) {
|
||||
if (Target_1 == null || Target_2 == null) {
|
||||
System.out.println("");
|
||||
return false;
|
||||
}
|
||||
System.out.println("equalProperties: " + Target_1.getClass().getName() + " " + Target_2.getClass().getName());
|
||||
if (Target_1.getClass().getName().equals(Target_2.getClass().getName()) == false) {
|
||||
System.out.println("");
|
||||
return false;
|
||||
}
|
||||
// compare each of the properties !!
|
||||
BeanInfo Info_1 = null;
|
||||
BeanInfo Info_2 = null;
|
||||
PropertyDescriptor[] Properties_1 = null;
|
||||
PropertyDescriptor[] Properties_2 = null;
|
||||
MethodDescriptor[] Methods_1 = null;
|
||||
MethodDescriptor[] Methods_2 = null;
|
||||
try {
|
||||
|
||||
Info_1 = Introspector.getBeanInfo(Target_1.getClass());
|
||||
Info_2 = Introspector.getBeanInfo(Target_2.getClass());
|
||||
Properties_1 = Info_1.getPropertyDescriptors();
|
||||
Properties_2 = Info_2.getPropertyDescriptors();
|
||||
Methods_1 = Info_1.getMethodDescriptors();
|
||||
} catch (IntrospectionException ex) {
|
||||
System.out.println("BeanTest: Couldn't introspect !!!!!!!!!");
|
||||
return false;
|
||||
}
|
||||
boolean BeansInside = false;
|
||||
boolean BeansEqual = true;
|
||||
for (int i = 0; i < Properties_1.length; i++) {
|
||||
if (Properties_1[i].isHidden() || Properties_1[i].isExpert()) {
|
||||
continue;
|
||||
}
|
||||
//String name = Properties_1[i].getDisplayName(); //System.out.println("name = "+name );
|
||||
//Class type = Properties_1[i].getPropertyType(); //System.out.println("type = "+type.getName() );
|
||||
Method getter_1 = Properties_1[i].getReadMethod();
|
||||
Method getter_2 = Properties_2[i].getReadMethod();
|
||||
Method setter_1 = Properties_1[i].getWriteMethod();
|
||||
// Only display read/write properties.
|
||||
if (getter_1 == null || setter_1 == null) {
|
||||
continue;
|
||||
}
|
||||
System.out.println("getter_1 = " + getter_1.getName() + " getter_2 = " + getter_2.getName());
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Object args_1[] = {};
|
||||
Object args_2[] = {};
|
||||
//System.out.println("m_Target"+m_Target.toString());
|
||||
try {
|
||||
Object value_1 = getter_1.invoke(Target_1, args_1);
|
||||
Object value_2 = getter_2.invoke(Target_2, args_2);
|
||||
BeansInside = true;
|
||||
if (BeanTest.equalProperties(value_1, value_2) == false) {
|
||||
BeansEqual = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(" BeanTest.equalProperties " + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (BeansInside == true) {
|
||||
return BeansEqual;
|
||||
}
|
||||
// here we have Integer or Double ...
|
||||
if (Target_1 instanceof Integer ||
|
||||
Target_1 instanceof Boolean ||
|
||||
Target_1 instanceof Float ||
|
||||
Target_1 instanceof Double ||
|
||||
Target_1 instanceof Long ||
|
||||
Target_1 instanceof String) {
|
||||
return Target_1.equals(Target_2);
|
||||
}
|
||||
|
||||
System.out.println(" Attention no match !!!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@param Target Description of the Parameter
|
||||
*@return Description of the Return Value
|
||||
*/
|
||||
public static String toString(Object Target) {
|
||||
String ret = "";
|
||||
// object itself
|
||||
try {
|
||||
Method[] methods = Target.getClass().getDeclaredMethods();
|
||||
for (int ii = 0; ii < methods.length; ii++) {
|
||||
if (methods[ii].getName().equals("toString") == true) {
|
||||
ret = (String) methods[ii].invoke(Target, (Object[])null);
|
||||
//System.out.println("calling to String off: "+Target.getClass().getName()+"=="+s);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//System.out.println(" ERROR +"+ e.getMessage());
|
||||
}
|
||||
// then the properties
|
||||
BeanInfo Info = null;
|
||||
PropertyDescriptor[] Properties = null;
|
||||
MethodDescriptor[] Methods = null;
|
||||
try {
|
||||
Info = Introspector.getBeanInfo(Target.getClass());
|
||||
Properties = Info.getPropertyDescriptors();
|
||||
Methods = Info.getMethodDescriptors();
|
||||
} catch (IntrospectionException ex) {
|
||||
System.out.println("BeanTest: Couldn't introspect");
|
||||
return ret;
|
||||
}
|
||||
for (int i = 0; i < Methods.length; i++) {
|
||||
String name = Methods[i].getDisplayName();
|
||||
Method meth = Methods[i].getMethod();
|
||||
}
|
||||
for (int i = 0; i < Properties.length; i++) {
|
||||
if (Properties[i].isHidden() || Properties[i].isExpert()) {
|
||||
continue;
|
||||
}
|
||||
String name = Properties[i].getDisplayName();
|
||||
//System.out.println("name = "+name );
|
||||
Class type = Properties[i].getPropertyType();
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Method getter = Properties[i].getReadMethod();
|
||||
Method setter = Properties[i].getWriteMethod();
|
||||
// Only display read/write properties.
|
||||
if (getter == null || setter == null) {
|
||||
continue;
|
||||
}
|
||||
//System.out.println("name = "+name );
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Object args[] = {};
|
||||
//System.out.println("m_Target"+m_Target.toString());
|
||||
|
||||
try {
|
||||
Object value = getter.invoke(Target, args);
|
||||
ret = ret + toString(value);
|
||||
} catch (Exception e) {
|
||||
//System.out.println("BeanTest ERROR +"+ e.getMessage());
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@param Target Description of the Parameter
|
||||
*/
|
||||
public static void showInfo(Object Target) {
|
||||
System.out.println("Inspecting " + Target.getClass().getName());
|
||||
// object itself
|
||||
try {
|
||||
if (Target instanceof java.lang.Integer) {
|
||||
System.out.println(" Prop = Integer" + Target.toString());
|
||||
}
|
||||
if (Target instanceof java.lang.Boolean) {
|
||||
System.out.println(" Prop = Boolean" + Target.toString());
|
||||
}
|
||||
if (Target instanceof java.lang.Long) {
|
||||
System.out.println(" Prop = Long" + Target.toString());
|
||||
}
|
||||
if (Target instanceof java.lang.Double) {
|
||||
System.out.println(" Prop = Long" + Target.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//System.out.println(" ERROR +"+ e.getMessage());
|
||||
}
|
||||
// then the properties
|
||||
BeanInfo Info = null;
|
||||
PropertyDescriptor[] Properties = null;
|
||||
MethodDescriptor[] Methods = null;
|
||||
try {
|
||||
Info = Introspector.getBeanInfo(Target.getClass());
|
||||
Properties = Info.getPropertyDescriptors();
|
||||
Methods = Info.getMethodDescriptors();
|
||||
} catch (IntrospectionException ex) {
|
||||
System.err.println("BeanTest: Couldn't introspect");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < Methods.length; i++) {
|
||||
String name = Methods[i].getDisplayName();
|
||||
Method meth = Methods[i].getMethod();
|
||||
}
|
||||
for (int i = 0; i < Properties.length; i++) {
|
||||
if (Properties[i].isHidden() || Properties[i].isExpert()) {
|
||||
continue;
|
||||
}
|
||||
String name = Properties[i].getDisplayName();
|
||||
//System.out.println("name = "+name );
|
||||
Class type = Properties[i].getPropertyType();
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Method getter = Properties[i].getReadMethod();
|
||||
Method setter = Properties[i].getWriteMethod();
|
||||
// Only display read/write properties.
|
||||
if (getter == null || setter == null) {
|
||||
continue;
|
||||
}
|
||||
//System.out.println("name = "+name );
|
||||
//System.out.println("type = "+type.getName() );
|
||||
Object args[] = {};
|
||||
//System.out.println("m_Target"+m_Target.toString());
|
||||
try {
|
||||
Object value = getter.invoke(Target, args);
|
||||
System.out.println("Inspecting name = " + name);
|
||||
if (value instanceof Integer) {
|
||||
Object args2[] = {new Integer(999)};
|
||||
setter.invoke(Target, args2);
|
||||
}
|
||||
showInfo(value);
|
||||
} catch (Exception e) {
|
||||
System.out.println("BeanTest ERROR +" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@param args The command line arguments
|
||||
*/
|
||||
// public static void main(String[] args) {
|
||||
// Tag t= new Tag();
|
||||
// System.out.println("name ========"+t.getClass().getName());
|
||||
// System.setProperty("java.security.policy","server.policy");
|
||||
// ESPopulation x = new ESPopulation();
|
||||
// x.add(new ESIndividual());
|
||||
// x.add(new ESIndividual());
|
||||
// x.add(new ESIndividual());
|
||||
// x.add(new ESIndividual());
|
||||
// x.add(new ESIndividual());
|
||||
//
|
||||
// ESPopulation y = new ESPopulation();
|
||||
// ESIndividual es = new ESIndividual();
|
||||
// MutationCMA ca = new MutationCMA();
|
||||
// es.setMutation(ca);
|
||||
// ca.setConstraints(true);
|
||||
// y.setIndividualTemplate(es);
|
||||
// System.out.println("***********");
|
||||
// //BeanTest.showInfo(x);
|
||||
// EvAServer xxx = new EvAServer(false,false);
|
||||
// //ObjectTOXML test = new ObjectTOXML();
|
||||
//// Element el = test.getXML(xxx,xxx.getClass(),false);
|
||||
//// Document doc = new Document(el);
|
||||
//// HTEFile f = HTEFile.getInstance();
|
||||
//// f.writeXMLFile(doc);
|
||||
//// System.out.println("***********");
|
||||
//// try{
|
||||
//// XMLEncoder e = new XMLEncoder(
|
||||
//// new BufferedOutputStream(
|
||||
//// new FileOutputStream("Test.xml")));
|
||||
//// e.writeObject(x);
|
||||
//// e.close();
|
||||
//// } catch (Exception ee ) {}
|
||||
//
|
||||
// //StandardESPopulation x = BeanTest.getRandomInstance(Class.forName("javaeva.server.oa.es.StandardESPopulation"));
|
||||
// //System.out.println("equal ??" + BeanTest.equalProperties(x, y));
|
||||
// }
|
||||
}
|
||||
|
||||
class mySecurityManager extends SecurityManager {
|
||||
public void checkMemberAccess( Class c, int which ) {
|
||||
System.out.println("KAKA") ; }// This is called only for
|
||||
// getDeclaredFields() and not for Field.get( )
|
||||
|
||||
public void checkPackageAccess( String p ) {}
|
||||
}
|
||||
210
src/javaeva/gui/BigStringEditor.java
Normal file
210
src/javaeva/gui/BigStringEditor.java
Normal file
@@ -0,0 +1,210 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 194 $
|
||||
* $Date: 2007-10-23 13:43:24 +0200 (Tue, 23 Oct 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.beans.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
public class BigStringEditor implements PropertyEditor {
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
private PropertyEditor m_ElementEditor;
|
||||
private JTextArea m_TextArea;
|
||||
private JScrollPane m_ScrollPane;
|
||||
private JPanel m_Panel;
|
||||
// private Source m_Source;
|
||||
private JButton m_SetButton;
|
||||
static private boolean m_finished = false;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void editSource (String file) {
|
||||
|
||||
try {
|
||||
m_finished=false;
|
||||
BigStringEditor editor = new BigStringEditor();
|
||||
//Source so = new Source ("\\javaeva\\server\\problems\\bench\\Problem_f1.java");
|
||||
// Source so = new Source (file);
|
||||
// editor.setValue(so);
|
||||
PropertyDialog frame = new PropertyDialog(editor,file, 50, 50);
|
||||
//frame.setSize(200, 200);
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing (WindowEvent e) {
|
||||
m_finished=true;
|
||||
}
|
||||
});
|
||||
while (m_finished==false) {
|
||||
try {Thread.sleep(1000);}
|
||||
catch (Exception e) {
|
||||
System.out.println("e+"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public BigStringEditor () {
|
||||
super();
|
||||
// m_TextArea = new JEditTextArea();
|
||||
// m_TextArea.setTokenMarker(new JavaTokenMarker());
|
||||
m_TextArea = new JTextArea(60,60);
|
||||
m_TextArea.setEditable(true);
|
||||
m_TextArea.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
|
||||
m_ScrollPane = new JScrollPane(m_TextArea);
|
||||
m_Panel = new JPanel();
|
||||
m_Panel.setBorder(BorderFactory.createTitledBorder("Sourcecode"));
|
||||
m_Panel.setLayout(new BorderLayout());
|
||||
m_SetButton = new JButton("SET");
|
||||
m_SetButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setValue(m_TextArea.getText());
|
||||
}
|
||||
});
|
||||
m_Panel.add(m_ScrollPane, BorderLayout.CENTER);
|
||||
m_Panel.add(m_SetButton, BorderLayout.SOUTH);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setValue (Object value) {
|
||||
m_ElementEditor = null;
|
||||
if (value instanceof String) {
|
||||
// m_Source.setString((String)value);
|
||||
m_TextArea.setText((String)value);
|
||||
|
||||
}
|
||||
/* if (value instanceof Source) {
|
||||
// m_Source = (Source) value;
|
||||
m_TextArea.setText(((Source)value).getString());
|
||||
}*/
|
||||
m_Support.firePropertyChange("", null, null);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Object getValue () {
|
||||
// m_Source.setString(m_TextArea.getText());
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getJavaInitializationString () {
|
||||
return "null";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to indicate that we can paint a representation of the
|
||||
* string array
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable () {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue (Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent())/2;
|
||||
//String rep = EVAHELP.cutClassName(m_ElementClass.getName());
|
||||
gfx.drawString("BigStringEditor", 2, fm.getHeight() + vpad - 3);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText () {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText (String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags () {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean supportsCustomEditor () {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Component getCustomEditor () {
|
||||
return m_Panel;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener (PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener (PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void main (String[] args) {
|
||||
try {
|
||||
BigStringEditor editor = new BigStringEditor();
|
||||
// Source so = new Source ("\\javaeva\\server\\problems\\bench\\Problem_f1.java");
|
||||
// editor.setValue(so);
|
||||
PropertyDialog frame = new PropertyDialog(editor, "test", 50, 50);
|
||||
frame.setSize(200, 200);
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing (WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
// editor.setValue(so);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
123
src/javaeva/gui/Chart2DDPointContentSelectable.java
Normal file
123
src/javaeva/gui/Chart2DDPointContentSelectable.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import wsi.ra.chart2d.DPointIcon;
|
||||
import wsi.ra.chart2d.DBorder;
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.mocco.paretofrontviewer.InterfaceRefSolutionListener;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 08.09.2005
|
||||
* Time: 10:15:30
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class Chart2DDPointContentSelectable implements InterfaceDPointWithContent, InterfaceSelectablePointIcon, DPointIcon {
|
||||
|
||||
AbstractEAIndividual m_Indy;
|
||||
InterfaceOptimizationProblem m_Problem;
|
||||
private InterfaceRefSolutionListener m_Listener;
|
||||
private Color m_Border = Color.BLACK;
|
||||
private Color m_Fill = null;
|
||||
private int m_Size = 4;
|
||||
|
||||
/** this method has to be overridden to paint the icon. The point itself lies
|
||||
* at coordinates (0, 0)
|
||||
*/
|
||||
public void paint( Graphics g ){
|
||||
Color prev = g.getColor();
|
||||
if (this.m_Indy.isMarked()) this.m_Fill = Color.RED;
|
||||
else this.m_Fill = Color.LIGHT_GRAY;
|
||||
g.setColor(m_Fill);
|
||||
g.fillOval(-this.m_Size, -this.m_Size, 2*this.m_Size +1, 2*this.m_Size +1);
|
||||
if (this.m_Border != null) g.setColor(m_Border);
|
||||
g.drawOval(-this.m_Size, -this.m_Size, 2*this.m_Size, 2*this.m_Size);
|
||||
g.setColor(prev);
|
||||
}
|
||||
|
||||
/** the border which is necessary to be paint around the DPoint that the whole
|
||||
* icon is visible
|
||||
* @return the border
|
||||
*/
|
||||
public DBorder getDBorder() {
|
||||
return new DBorder(4, 4, 4, 4);
|
||||
}
|
||||
|
||||
public void setBorderColor(Color c) {
|
||||
this.m_Border = c;
|
||||
}
|
||||
public void setFillColor(Color c) {
|
||||
this.m_Fill = c;
|
||||
}
|
||||
public void setSize(int d) {
|
||||
this.m_Size = d;
|
||||
}
|
||||
|
||||
/*********************************************************************************************
|
||||
* The InterfaceSelectablePointIcon
|
||||
*/
|
||||
|
||||
/** This method allows to add a selection listner to the PointIcon
|
||||
* it should need more than one listener to this abstruse event
|
||||
* @param a The selection listener
|
||||
*/
|
||||
public void addSelectionListener(InterfaceRefSolutionListener a) {
|
||||
this.m_Listener = a;
|
||||
}
|
||||
|
||||
/** This method returns the selection listner to the PointIcon
|
||||
* @return InterfaceSelectionListener
|
||||
*/
|
||||
public InterfaceRefSolutionListener getSelectionListener() {
|
||||
return this.m_Listener;
|
||||
}
|
||||
|
||||
/** This method allows to remove the selection listner to the PointIcon
|
||||
*/
|
||||
public void removeSelectionListeners() {
|
||||
this.m_Listener = null;
|
||||
}
|
||||
|
||||
/** This method allows you to set the according individual
|
||||
* @param indy AbstractEAIndividual
|
||||
*/
|
||||
public void setEAIndividual(AbstractEAIndividual indy) {
|
||||
this.m_Indy = indy;
|
||||
}
|
||||
public AbstractEAIndividual getEAIndividual() {
|
||||
return this.m_Indy;
|
||||
}
|
||||
|
||||
/** This method allows you to set the according optimization problem
|
||||
* @param problem InterfaceOptimizationProblem
|
||||
*/
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
}
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
}
|
||||
|
||||
/** This method allows you to draw additional data of the individual
|
||||
*/
|
||||
public void showIndividual() {
|
||||
JFrame newFrame = new JFrame();
|
||||
newFrame.setTitle(this.m_Indy.getName()+": "+this.m_Indy);
|
||||
newFrame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
System.gc();
|
||||
}
|
||||
});
|
||||
newFrame.getContentPane().add(this.m_Problem.drawIndividual(this.m_Indy));
|
||||
newFrame.setSize(200, 300);
|
||||
newFrame.pack();
|
||||
newFrame.validate();
|
||||
newFrame.setVisible(true);
|
||||
}
|
||||
}
|
||||
55
src/javaeva/gui/Chart2DDPointIconCircle.java
Normal file
55
src/javaeva/gui/Chart2DDPointIconCircle.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import wsi.ra.chart2d.DPointIcon;
|
||||
import wsi.ra.chart2d.DBorder;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 01.04.2004
|
||||
* Time: 09:55:30
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class Chart2DDPointIconCircle implements DPointIcon {
|
||||
|
||||
private Color m_Border = Color.BLACK;
|
||||
private Color m_Fill = null;
|
||||
private int m_Size = 4;
|
||||
|
||||
/**
|
||||
* this method has to be overridden to paint the icon. The point itself lies
|
||||
* at coordinates (0, 0)
|
||||
*/
|
||||
public void paint( Graphics g ){
|
||||
Color prev = g.getColor();
|
||||
if (m_Fill != null) {
|
||||
g.setColor(m_Fill);
|
||||
g.fillOval(-this.m_Size, -this.m_Size, 2*this.m_Size +1, 2*this.m_Size +1);
|
||||
}
|
||||
if (this.m_Border != null) g.setColor(m_Border);
|
||||
g.drawOval(-this.m_Size, -this.m_Size, 2*this.m_Size, 2*this.m_Size);
|
||||
g.setColor(prev);
|
||||
}
|
||||
|
||||
/**
|
||||
* the border which is necessary to be paint around the DPoint that the whole
|
||||
* icon is visible
|
||||
*
|
||||
* @return the border
|
||||
*/
|
||||
public DBorder getDBorder() {
|
||||
return new DBorder(4, 4, 4, 4);
|
||||
}
|
||||
|
||||
public void setBorderColor(Color c) {
|
||||
this.m_Border = c;
|
||||
}
|
||||
public void setFillColor(Color c) {
|
||||
this.m_Fill = c;
|
||||
}
|
||||
public void setSize(int d) {
|
||||
this.m_Size = d;
|
||||
}
|
||||
|
||||
}
|
||||
88
src/javaeva/gui/Chart2DDPointIconContent.java
Normal file
88
src/javaeva/gui/Chart2DDPointIconContent.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import wsi.ra.chart2d.DBorder;
|
||||
import wsi.ra.chart2d.DPointIcon;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 13.04.2004
|
||||
* Time: 13:31:48
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class Chart2DDPointIconContent implements InterfaceDPointWithContent, DPointIcon {
|
||||
|
||||
AbstractEAIndividual m_Indy;
|
||||
InterfaceOptimizationProblem m_Problem;
|
||||
|
||||
/**
|
||||
* this method has to be overridden to paint the icon. The point itself lies
|
||||
* at coordinates (0, 0)
|
||||
*/
|
||||
public void paint( Graphics g ){
|
||||
g.drawOval(-4, -4, 8, 8);
|
||||
g.drawLine(-2, 2, 2,-2);
|
||||
g.drawLine(-2,-2, 2, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* the border which is necessary to be paint around the DPoint that the whole
|
||||
* icon is visible
|
||||
*
|
||||
* @return the border
|
||||
*/
|
||||
public DBorder getDBorder() {
|
||||
return new DBorder(4, 4, 4, 4);
|
||||
}
|
||||
|
||||
/** This method allows you to set the according individual
|
||||
* @param indy AbstractEAIndividual
|
||||
*/
|
||||
public void setEAIndividual(AbstractEAIndividual indy) {
|
||||
this.m_Indy = indy;
|
||||
}
|
||||
public AbstractEAIndividual getEAIndividual() {
|
||||
return this.m_Indy;
|
||||
}
|
||||
|
||||
/** This method allows you to set the according optimization problem
|
||||
* @param problem InterfaceOptimizationProblem
|
||||
*/
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
}
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
}
|
||||
|
||||
/** This method allows you to draw additional data of the individual
|
||||
*/
|
||||
public void showIndividual() {
|
||||
JFrame newFrame = new JFrame();
|
||||
if (this.m_Indy == null) {
|
||||
System.out.println("No individual!");
|
||||
return;
|
||||
}
|
||||
newFrame.setTitle(this.m_Indy.getName()+": "+this.m_Indy);
|
||||
newFrame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
System.gc();
|
||||
}
|
||||
});
|
||||
newFrame.getContentPane().add(this.m_Problem.drawIndividual(this.m_Indy));
|
||||
newFrame.setSize(200, 300);
|
||||
newFrame.pack();
|
||||
newFrame.validate();
|
||||
newFrame.setVisible(true);
|
||||
newFrame.show();
|
||||
}
|
||||
}
|
||||
44
src/javaeva/gui/Chart2DDPointIconCross.java
Normal file
44
src/javaeva/gui/Chart2DDPointIconCross.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import wsi.ra.chart2d.DBorder;
|
||||
import wsi.ra.chart2d.DPointIcon;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 01.04.2004
|
||||
* Time: 10:00:50
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class Chart2DDPointIconCross implements DPointIcon {
|
||||
|
||||
private Color m_Color;
|
||||
|
||||
/**
|
||||
* this method has to be overridden to paint the icon. The point itself lies
|
||||
* at coordinates (0, 0)
|
||||
*/
|
||||
public void paint( Graphics g ){
|
||||
Color prev = g.getColor();
|
||||
g.setColor(this.m_Color);
|
||||
g.drawLine(-1, 1, 1,-1);
|
||||
g.drawLine(-1,-1, 1, 1);
|
||||
g.setColor(prev);
|
||||
}
|
||||
|
||||
/**
|
||||
* the border which is necessary to be paint around the DPoint that the whole
|
||||
* icon is visible
|
||||
*
|
||||
* @return the border
|
||||
*/
|
||||
public DBorder getDBorder() {
|
||||
return new DBorder(4, 4, 4, 4);
|
||||
}
|
||||
|
||||
public void setColor(Color c) {
|
||||
this.m_Color = c;
|
||||
}
|
||||
}
|
||||
56
src/javaeva/gui/Chart2DDPointIconPoint.java
Normal file
56
src/javaeva/gui/Chart2DDPointIconPoint.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import wsi.ra.chart2d.DPointIcon;
|
||||
import wsi.ra.chart2d.DBorder;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 17.08.2005
|
||||
* Time: 16:52:34
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class Chart2DDPointIconPoint implements DPointIcon {
|
||||
|
||||
private Color m_Border = Color.BLACK;
|
||||
private Color m_Fill = Color.BLACK;
|
||||
private int m_Size = 2;
|
||||
|
||||
/**
|
||||
* this method has to be overridden to paint the icon. The point itself lies
|
||||
* at coordinates (0, 0)
|
||||
*/
|
||||
public void paint( Graphics g ){
|
||||
Color prev = g.getColor();
|
||||
if (m_Fill != null) {
|
||||
g.setColor(m_Fill);
|
||||
g.fillOval(-this.m_Size, -this.m_Size, 2*this.m_Size, 2*this.m_Size);
|
||||
}
|
||||
if (this.m_Border != null) g.setColor(m_Border);
|
||||
g.drawOval(-this.m_Size, -this.m_Size, (2*this.m_Size)-1, (2*this.m_Size)-1);
|
||||
g.setColor(prev);
|
||||
}
|
||||
|
||||
/**
|
||||
* the border which is necessary to be paint around the DPoint that the whole
|
||||
* icon is visible
|
||||
*
|
||||
* @return the border
|
||||
*/
|
||||
public DBorder getDBorder() {
|
||||
return new DBorder(4, 4, 4, 4);
|
||||
}
|
||||
|
||||
public void setBorderColor(Color c) {
|
||||
this.m_Border = c;
|
||||
}
|
||||
public void setFillColor(Color c) {
|
||||
this.m_Fill = c;
|
||||
}
|
||||
public void setSize(int d) {
|
||||
this.m_Size = d;
|
||||
}
|
||||
|
||||
}
|
||||
49
src/javaeva/gui/Chart2DDPointIconText.java
Normal file
49
src/javaeva/gui/Chart2DDPointIconText.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import wsi.ra.chart2d.DPointIcon;
|
||||
import wsi.ra.chart2d.DBorder;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 01.04.2004
|
||||
* Time: 16:08:15
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class Chart2DDPointIconText implements DPointIcon {
|
||||
|
||||
private DPointIcon m_Icon = new Chart2DDPointIconCross();
|
||||
private String m_Text = " ";
|
||||
|
||||
public Chart2DDPointIconText(String s) {
|
||||
m_Text = s;
|
||||
}
|
||||
|
||||
/** This method allows you to set an icon
|
||||
* @param icon The new icon
|
||||
*/
|
||||
public void setIcon(DPointIcon icon) {
|
||||
this.m_Icon = icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method has to be overridden to paint the icon. The point itself lies
|
||||
* at coordinates (0, 0)
|
||||
*/
|
||||
public void paint( Graphics g ){
|
||||
this.m_Icon.paint(g);
|
||||
g.drawString(this.m_Text, 4, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* the border which is necessary to be paint around the DPoint that the whole
|
||||
* icon is visible
|
||||
*
|
||||
* @return the border
|
||||
*/
|
||||
public DBorder getDBorder() {
|
||||
return new DBorder(4, 4, 4, 4);
|
||||
}
|
||||
}
|
||||
17
src/javaeva/gui/ComponentFilter.java
Normal file
17
src/javaeva/gui/ComponentFilter.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
public interface ComponentFilter{
|
||||
public boolean accept(java.awt.Component c);
|
||||
}
|
||||
504
src/javaeva/gui/DPointSetMultiIcon.java
Normal file
504
src/javaeva/gui/DPointSetMultiIcon.java
Normal file
@@ -0,0 +1,504 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import wsi.ra.chart2d.*;
|
||||
|
||||
import wsi.ra.tool.IntegerArrayList;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 01.04.2004
|
||||
* Time: 16:17:35
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class DPointSetMultiIcon extends DComponent
|
||||
{
|
||||
//~ Instance fields ////////////////////////////////////////////////////////
|
||||
|
||||
protected ArrayList m_IconsMI = new ArrayList();
|
||||
protected DIntDoubleMap xMI;
|
||||
protected DIntDoubleMap yMI;
|
||||
protected DPointIcon iconMI = null;
|
||||
protected DPointSetMultiIcon.JumpManager jumperMI = new DPointSetMultiIcon.JumpManager();
|
||||
protected Stroke strokeMI = new BasicStroke();
|
||||
protected boolean connectedMI;
|
||||
|
||||
//~ Constructors ///////////////////////////////////////////////////////////
|
||||
|
||||
public DPointSetMultiIcon()
|
||||
{
|
||||
this(10, 2);
|
||||
}
|
||||
|
||||
public DPointSetMultiIcon(int initial_capacity)
|
||||
{
|
||||
this(initial_capacity, 2);
|
||||
}
|
||||
|
||||
public DPointSetMultiIcon(int initial_capacity, int length_multiplier)
|
||||
{
|
||||
this(new DArray(initial_capacity, length_multiplier),
|
||||
new DArray(initial_capacity, length_multiplier));
|
||||
}
|
||||
|
||||
public DPointSetMultiIcon(DIntDoubleMap x_values, DIntDoubleMap y_values)
|
||||
{
|
||||
if (x_values.getSize() != y_values.getSize())
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"The number of x-values has to be the same than the number of y-values");
|
||||
}
|
||||
|
||||
xMI = x_values;
|
||||
yMI = y_values;
|
||||
restore();
|
||||
setDBorder(new DBorder(1, 1, 1, 1));
|
||||
}
|
||||
|
||||
//~ Methods ////////////////////////////////////////////////////////////////
|
||||
|
||||
public void setConnected(boolean aFlag)
|
||||
{
|
||||
boolean changed = !(aFlag == connectedMI);
|
||||
connectedMI = aFlag;
|
||||
|
||||
if (changed)
|
||||
{
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* method puts the given DPoint at the given position in the set
|
||||
*
|
||||
* @param index the index of the point
|
||||
* @param p the point to insert
|
||||
*/
|
||||
public void setDPoint(int index, DPoint p)
|
||||
{
|
||||
if (index >= xMI.getSize())
|
||||
{
|
||||
throw new ArrayIndexOutOfBoundsException(index);
|
||||
}
|
||||
|
||||
rectangle.insert(p);
|
||||
xMI.setImage(index, p.x);
|
||||
yMI.setImage(index, p.y);
|
||||
m_IconsMI.set(index, p.getIcon());
|
||||
restore();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* method returns the DPoint at the given index
|
||||
*
|
||||
* @param index the index of the DPoint
|
||||
* @return the DPoint at the given index
|
||||
*/
|
||||
public DPoint getDPoint(int index)
|
||||
{
|
||||
if (index >= xMI.getSize())
|
||||
{
|
||||
throw new ArrayIndexOutOfBoundsException(index);
|
||||
}
|
||||
|
||||
DPoint p = new DPoint(xMI.getImage(index), yMI.getImage(index));
|
||||
p.setIcon(iconMI);
|
||||
p.setColor(color);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public DPointSet getDPointSet()
|
||||
{
|
||||
return new DPointSet(xMI, yMI);
|
||||
}
|
||||
|
||||
public ArrayList getIconsMI() {
|
||||
return this.m_IconsMI;
|
||||
}
|
||||
|
||||
/**
|
||||
* method sets an icon for a better displaying of the point set
|
||||
*
|
||||
* @param icon the DPointIcon
|
||||
*/
|
||||
public void setIcon(DPointIcon icon)
|
||||
{
|
||||
this.iconMI = icon;
|
||||
|
||||
if (icon == null)
|
||||
{
|
||||
setDBorder(new DBorder(1, 1, 1, 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
setDBorder(icon.getDBorder());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* method returns the current icon of the point set
|
||||
*
|
||||
* @return the DPointIcon
|
||||
*/
|
||||
public DPointIcon getIcon()
|
||||
{
|
||||
return iconMI;
|
||||
}
|
||||
|
||||
/**
|
||||
* method returns the nearest <code>DPoint</code> in this <code>DPointSet</code>.
|
||||
*
|
||||
* @return the nearest <code>DPoint</code>
|
||||
*/
|
||||
public DPoint getNearestDPoint(DPoint point)
|
||||
{
|
||||
int minIndex = getNearestDPointIndex(point);
|
||||
|
||||
if (minIndex == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
DPoint result = new DPoint(xMI.getImage(minIndex),
|
||||
yMI.getImage(minIndex));
|
||||
result.setIcon((DPointIcon) this.m_IconsMI.get(minIndex));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/** method returns the index to the nearest <code>DPoint</code> in this <code>DPointSet</code>.
|
||||
* @return the index to the nearest <code>DPoint</code>. -1 if no nearest <code>DPoint</code> was found.
|
||||
*/
|
||||
public int getNearestDPointIndex(DPoint point)
|
||||
{
|
||||
double minValue = Double.MAX_VALUE;
|
||||
int minIndex = -1;
|
||||
|
||||
for (int i = 0; i < xMI.getSize(); i++)
|
||||
{
|
||||
double dx = point.x - xMI.getImage(i);
|
||||
double dy = point.y - yMI.getImage(i);
|
||||
double dummy = (dx * dx) + (dy * dy);
|
||||
|
||||
if (dummy < minValue)
|
||||
{
|
||||
minValue = dummy;
|
||||
minIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
return minIndex;
|
||||
}
|
||||
|
||||
public int getSize()
|
||||
{
|
||||
int size = Math.min(xMI.getSize(), yMI.getSize());
|
||||
|
||||
// int size = x.getSize();
|
||||
// if( size != y.getSize() ) throw
|
||||
// new ArrayStoreException(
|
||||
// "The number of x-values is not equal to the number of y-values.\n"
|
||||
// +"The size of the DPointSet isn<73>t clear."
|
||||
// );
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* method sets the stroke of the line
|
||||
* if the points were not connected, they now will be connected
|
||||
*
|
||||
* @param s the new stroke
|
||||
*/
|
||||
public void setStroke(Stroke s)
|
||||
{
|
||||
if (s == null)
|
||||
{
|
||||
s = new BasicStroke();
|
||||
}
|
||||
|
||||
strokeMI = s;
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* method returns the current stroke of the line
|
||||
*
|
||||
* @return the stroke
|
||||
*/
|
||||
public Stroke getStroke()
|
||||
{
|
||||
return strokeMI;
|
||||
}
|
||||
|
||||
public void addDPoint(DPoint p)
|
||||
{
|
||||
xMI.addImage(p.x);
|
||||
yMI.addImage(p.y);
|
||||
m_IconsMI.add(p.getIcon());
|
||||
rectangle.insert(p);
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void addDPoint(double x, double y)
|
||||
{
|
||||
addDPoint(new DPoint(x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method causes the DPointSet to interupt the connected painting at the
|
||||
* current position.
|
||||
*/
|
||||
public void jump()
|
||||
{
|
||||
jumperMI.addJump();
|
||||
}
|
||||
|
||||
public void paint(DMeasures m)
|
||||
{
|
||||
try
|
||||
{
|
||||
Graphics2D g = (Graphics2D) m.getGraphics();
|
||||
g.setStroke(strokeMI);
|
||||
|
||||
if (color != null)
|
||||
{
|
||||
g.setColor(color);
|
||||
}
|
||||
|
||||
int size = getSize();
|
||||
|
||||
if (connectedMI && (size > 1))
|
||||
{
|
||||
jumperMI.restore();
|
||||
|
||||
while (jumperMI.hasMoreIntervals())
|
||||
{
|
||||
int[] interval = jumperMI.nextInterval();
|
||||
Point p1 = null;
|
||||
Point p2;
|
||||
|
||||
for (int i = interval[0]; i < interval[1]; i++)
|
||||
{
|
||||
p2 = m.getPoint(xMI.getImage(i), yMI.getImage(i));
|
||||
|
||||
if (p1 != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
g.drawLine(p1.x, p1.y, p2.x, p2.y);
|
||||
}
|
||||
catch (java.lang.NullPointerException e)
|
||||
{
|
||||
// pff
|
||||
}
|
||||
}
|
||||
|
||||
if ((i < this.m_IconsMI.size()) && (this.m_IconsMI.get(i) != null))
|
||||
{
|
||||
g.setStroke(new BasicStroke());
|
||||
g.translate(p2.x, p2.y);
|
||||
((DPointIcon) this.m_IconsMI.get(i)).paint(g);
|
||||
g.translate(-p2.x, -p2.y);
|
||||
g.setStroke(strokeMI);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iconMI != null)
|
||||
{
|
||||
g.setStroke(new BasicStroke());
|
||||
g.translate(p2.x, p2.y);
|
||||
iconMI.paint(g);
|
||||
g.translate(-p2.x, -p2.y);
|
||||
g.setStroke(strokeMI);
|
||||
}
|
||||
}
|
||||
|
||||
p1 = p2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Point p;
|
||||
|
||||
//for (int i = 0; i < size; i++)
|
||||
// @todo Streiche: Mal wieder eine index out of bounds exception, dass ist einfach mist...
|
||||
for (int i = 0; i < this.m_IconsMI.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
p = m.getPoint(xMI.getImage(i), yMI.getImage(i));
|
||||
|
||||
if (this.m_IconsMI.get(i) != null)
|
||||
{
|
||||
g.setStroke(new BasicStroke());
|
||||
g.translate(p.x, p.y);
|
||||
((DPointIcon) this.m_IconsMI.get(i)).paint(g);
|
||||
g.translate(-p.x, -p.y);
|
||||
g.setStroke(strokeMI);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iconMI == null)
|
||||
{
|
||||
g.drawLine(p.x - 1, p.y - 1, p.x + 1, p.y + 1);
|
||||
g.drawLine(p.x + 1, p.y - 1, p.x - 1, p.y + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.setStroke(new BasicStroke());
|
||||
g.translate(p.x, p.y);
|
||||
iconMI.paint(g);
|
||||
g.translate(-p.x, -p.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (java.lang.IllegalArgumentException e)
|
||||
{
|
||||
System.out.println(
|
||||
"The rectangle lies not in the currently painted rectangle.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.setStroke(new BasicStroke());
|
||||
}
|
||||
catch (java.lang.ArrayIndexOutOfBoundsException e)
|
||||
{
|
||||
// *pff*
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAllPoints()
|
||||
{
|
||||
if (xMI.getSize() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
xMI.reset();
|
||||
yMI.reset();
|
||||
jumperMI.reset();
|
||||
repaint();
|
||||
rectangle = DRectangle.getEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* method removes all jump positions
|
||||
* if the DPointSet is connected, all points will be painted connected to
|
||||
* their following point
|
||||
*/
|
||||
public void removeJumps()
|
||||
{
|
||||
jumperMI.reset();
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
String text = "wsi.ra.chart2d.DPointSet[size:" + getSize();
|
||||
|
||||
for (int i = 0; i < xMI.getSize(); i++)
|
||||
{
|
||||
text += (",(" + xMI.getImage(i) + "," + yMI.getImage(i) + ")");
|
||||
}
|
||||
|
||||
text += "]";
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
protected void restore()
|
||||
{
|
||||
if (getSize() == 0)
|
||||
{
|
||||
rectangle = DRectangle.getEmpty();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
double min_x = xMI.getMinImageValue();
|
||||
double max_x = xMI.getMaxImageValue();
|
||||
double min_y = yMI.getMinImageValue();
|
||||
double max_y = yMI.getMaxImageValue();
|
||||
rectangle = new DRectangle(min_x, min_y, max_x - min_x, max_y - min_y);
|
||||
}
|
||||
|
||||
//~ Inner Classes //////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* this class stores the jump positions (see this.jump)
|
||||
*/
|
||||
class JumpManager
|
||||
{
|
||||
protected IntegerArrayList jumps = new IntegerArrayList();
|
||||
protected int index = -1;
|
||||
|
||||
public void addJump()
|
||||
{
|
||||
jumps.add(getSize());
|
||||
}
|
||||
|
||||
public boolean hasMoreIntervals()
|
||||
{
|
||||
return index < jumps.size();
|
||||
}
|
||||
|
||||
public int[] nextInterval()
|
||||
{
|
||||
int no_jumps = jumps.size();
|
||||
|
||||
if (index >= no_jumps)
|
||||
{
|
||||
throw new ArrayIndexOutOfBoundsException(
|
||||
"No more intervals in JumpManager");
|
||||
}
|
||||
|
||||
int[] inter = new int[2];
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
inter[0] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
inter[0] = jumps.get(index);
|
||||
}
|
||||
|
||||
index++;
|
||||
|
||||
if (index < no_jumps)
|
||||
{
|
||||
inter[1] = jumps.get(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
inter[1] = getSize();
|
||||
}
|
||||
|
||||
return inter;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
index = -1;
|
||||
jumps.clear();
|
||||
}
|
||||
|
||||
public void restore()
|
||||
{
|
||||
index = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// END OF FILE.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
145
src/javaeva/gui/DataViewer.java
Normal file
145
src/javaeva/gui/DataViewer.java
Normal file
@@ -0,0 +1,145 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 320 $
|
||||
* $Date: 2007-12-06 16:05:11 +0100 (Thu, 06 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wsi.ra.jproxy.MainAdapterClient;
|
||||
import wsi.ra.jproxy.RMIProxyRemote;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
* It represents one plot window in the client GUI.
|
||||
*/
|
||||
public class DataViewer implements DataViewerInterface {
|
||||
public static boolean TRACE = false;
|
||||
|
||||
static private int m_GraphCounter = -1;
|
||||
static private ViewContainer m_ViewContainer;
|
||||
private MainAdapterClient m_MainAdapterClient;
|
||||
private static String m_MyHostName;
|
||||
private PlotInterface m_Plotter;
|
||||
private String m_Name;
|
||||
private Plot m_Plot;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static DataViewerInterface getInstance (MainAdapterClient client,String GraphWindowName) {
|
||||
if (m_ViewContainer == null)
|
||||
m_ViewContainer = new ViewContainer();
|
||||
DataViewerInterface ret =null;
|
||||
try {
|
||||
if (!m_ViewContainer.containsName(GraphWindowName)) {
|
||||
////////////////////////////////////////////////
|
||||
try {
|
||||
m_MyHostName = InetAddress.getLocalHost().getHostName();
|
||||
} catch (Exception e) {
|
||||
System.out.println("InetAddress.getLocalHost().getHostAddress() --> ERROR" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (client != null && client.getHostName().equals(m_MyHostName)== true) {
|
||||
if (TRACE) System.out.println("no RMI");
|
||||
ret = new DataViewer(GraphWindowName,true);
|
||||
}
|
||||
else {
|
||||
ret = (DataViewerInterface) RMIProxyRemote.newInstance(new DataViewer(GraphWindowName,false), client);
|
||||
ret.init();
|
||||
if (TRACE) System.out.println("with RMI");
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
m_ViewContainer.add(ret);
|
||||
}
|
||||
else {
|
||||
ret = m_ViewContainer.getPlot(GraphWindowName);
|
||||
}
|
||||
} catch (Exception ee) {
|
||||
System.out.println("GraphWindow ERROR : "+ee.getMessage());
|
||||
ee.printStackTrace();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private DataViewer(String PlotName,boolean initflag){
|
||||
if (TRACE) System.out.println("Constructor DataViewer");
|
||||
m_Name = PlotName;
|
||||
if(initflag)
|
||||
this.init();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getName () {
|
||||
return m_Name;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Graph getNewGraph(String InfoString) {
|
||||
m_GraphCounter++;
|
||||
if (TRACE) System.out.println("Graph.getNewGraph No:"+m_GraphCounter);
|
||||
return new Graph (InfoString,m_Plot,m_GraphCounter);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void init() {
|
||||
m_Plot = new Plot(m_Name,"x","y", true);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ViewContainer extends ArrayList {
|
||||
private DataViewer m_actualPlot;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ViewContainer() {}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean containsName (String name) {
|
||||
DataViewer temp = null;
|
||||
for (int i=0;i<size();i++) {
|
||||
temp = (DataViewer)(get(i));
|
||||
if (name.equals(temp.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DataViewer getPlot (String name) {
|
||||
if (m_actualPlot!=null)
|
||||
if (m_actualPlot.getName().equals(name))
|
||||
return m_actualPlot;
|
||||
DataViewer temp = null;
|
||||
for (int i=0;i<size();i++) {
|
||||
temp = (DataViewer)(get(i));
|
||||
if (name.equals(temp.getName())) {
|
||||
m_actualPlot = temp;
|
||||
return m_actualPlot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
18
src/javaeva/gui/DataViewerInterface.java
Normal file
18
src/javaeva/gui/DataViewerInterface.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
public interface DataViewerInterface {
|
||||
public Graph getNewGraph(String InfoString);
|
||||
public void init();
|
||||
}
|
||||
36
src/javaeva/gui/Exp.java
Normal file
36
src/javaeva/gui/Exp.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import wsi.ra.chart2d.DFunction;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Exp extends DFunction{
|
||||
public boolean isDefinedAt( double source ){ return true; }
|
||||
public boolean isInvertibleAt( double image ){ return image > 0; }
|
||||
public double getImageOf( double source ){ return Math.exp( source ); }
|
||||
public double getSourceOf( double target ){
|
||||
if( target <= 0 ) { throw
|
||||
new IllegalArgumentException(
|
||||
"Can not calculate log on values smaller than or equal 0 --> target = "+target
|
||||
);
|
||||
}
|
||||
return Math.log( target );
|
||||
}
|
||||
}
|
||||
|
||||
69
src/javaeva/gui/ExtAction.java
Normal file
69
src/javaeva/gui/ExtAction.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.Action;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public abstract class ExtAction extends AbstractAction {
|
||||
public final static String CAPTION = "Caption";
|
||||
public final static String MNEMONIC = "Mnemonic";
|
||||
public final static String TOOLTIP = "ToolTip";
|
||||
public final static String KEYSTROKE = "KeyStroke";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void setValues(String s, String toolTip){
|
||||
Mnemonic m = new Mnemonic(s);
|
||||
putValue(MNEMONIC, new Character(m.getMnemonic()));
|
||||
putValue(Action.NAME, m.getText());
|
||||
putValue(TOOLTIP, toolTip);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ExtAction(String s, Icon i, String toolTip, KeyStroke key){
|
||||
this(s, i, toolTip);
|
||||
if (i==null)
|
||||
System.out.println("Icon == null");
|
||||
putValue(KEYSTROKE, key);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ExtAction(String s, Icon i, String toolTip){
|
||||
super(null, i);
|
||||
if (i==null)
|
||||
System.out.println("Icon == null");
|
||||
setValues(s, toolTip);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ExtAction(String s, String toolTip, KeyStroke key){
|
||||
this(s, toolTip);
|
||||
putValue(KEYSTROKE, key);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ExtAction(String s, String toolTip){
|
||||
super();
|
||||
setValues(s, toolTip);
|
||||
}
|
||||
}
|
||||
|
||||
40
src/javaeva/gui/ExtActionChangedListener.java
Normal file
40
src/javaeva/gui/ExtActionChangedListener.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import javax.swing.JComponent;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public abstract class ExtActionChangedListener implements PropertyChangeListener{
|
||||
protected JComponent component;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
ExtActionChangedListener(JComponent c){
|
||||
super();
|
||||
setTarget(c);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public abstract void propertyChange(PropertyChangeEvent e);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setTarget(JComponent c){
|
||||
component = c;
|
||||
}
|
||||
}
|
||||
70
src/javaeva/gui/ExtDesktopManager.java
Normal file
70
src/javaeva/gui/ExtDesktopManager.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ExtDesktopManager extends DefaultDesktopManager{
|
||||
int WINDOW_LIST_START;
|
||||
public final static String INDEX = "Index";
|
||||
public final static String FRAME = "Frame";
|
||||
private JInternalFrame activeFrame = null;
|
||||
private JExtDesktopPane desktop;
|
||||
public ExtDesktopManager(JExtDesktopPane desktop){
|
||||
this.desktop = desktop;
|
||||
}
|
||||
public void activateFrame(JInternalFrame f){
|
||||
super.activateFrame(f);
|
||||
activeFrame = f;
|
||||
}
|
||||
public void deactivateFrame(JInternalFrame f){
|
||||
super.deactivateFrame(f);
|
||||
if(activeFrame == f) activeFrame = null;
|
||||
}
|
||||
public JInternalFrame getActiveFrame(){
|
||||
return activeFrame;
|
||||
}
|
||||
public void closeFrame(JInternalFrame f){
|
||||
System.out.println("closed internalframe called");
|
||||
super.closeFrame(f);
|
||||
int index = ((Integer)f.getClientProperty(INDEX)).intValue() + WINDOW_LIST_START - 1;
|
||||
int i;
|
||||
desktop.m_mnuWindow.remove(index);
|
||||
for(i = index; i < Math.min(WINDOW_LIST_START + 9, desktop.m_mnuWindow.getItemCount()); i++){
|
||||
JMenuItem m = desktop.m_mnuWindow.getItem(i);
|
||||
JInternalFrame frame = (JInternalFrame)m.getClientProperty(FRAME);
|
||||
frame.putClientProperty(INDEX, new Integer(((Integer)frame.getClientProperty(INDEX)).intValue() - 1));
|
||||
int winIndex = i - WINDOW_LIST_START + 1;
|
||||
m.setText((winIndex) + " " + frame.getTitle());
|
||||
m.setMnemonic((char)(0x30 + winIndex));
|
||||
m.setAccelerator(KeyStroke.getKeyStroke(0x30 + winIndex, Event.ALT_MASK));
|
||||
}
|
||||
|
||||
if(f.isSelected()){
|
||||
Component tmp = null;
|
||||
boolean found = false;
|
||||
for(i = 0; i < desktop.getComponentCount() && !found; i++){
|
||||
tmp = desktop.getComponent(i);
|
||||
if(tmp instanceof JInternalFrame) found = true;
|
||||
}
|
||||
|
||||
if(found) desktop.selectFrame((JInternalFrame)tmp);
|
||||
else activeFrame = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
702
src/javaeva/gui/FunctionArea.java
Normal file
702
src/javaeva/gui/FunctionArea.java
Normal file
@@ -0,0 +1,702 @@
|
||||
package javaeva.gui;
|
||||
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 306 $
|
||||
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
|
||||
import wsi.ra.chart2d.DArea;
|
||||
import wsi.ra.chart2d.DBorder;
|
||||
import wsi.ra.chart2d.DPoint;
|
||||
import wsi.ra.chart2d.DPointIcon;
|
||||
import wsi.ra.chart2d.DPointSet;
|
||||
import wsi.ra.chart2d.ScaledBorder;
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.mocco.paretofrontviewer.InterfaceRefPointListener;
|
||||
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class FunctionArea extends DArea implements Serializable {
|
||||
private InterfaceRefPointListener m_RefPointListener;
|
||||
private JFileChooser m_FileChooser;
|
||||
private ArrayList m_PointSetContainer;
|
||||
private ScaledBorder m_Border;
|
||||
private boolean m_log = false;
|
||||
private boolean notifyNegLog = true;
|
||||
private int m_x;
|
||||
private int m_y;
|
||||
|
||||
private DPointIcon m_CurrentPointIcon;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public FunctionArea() {}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public FunctionArea(String xname, String yname) {
|
||||
super();
|
||||
setPreferredSize(new Dimension(600, 500));
|
||||
setVisibleRectangle(1, 1, 100000, 1000);
|
||||
setAutoFocus(true);
|
||||
setMinRectangle(0, 0, 1, 1);
|
||||
//setAutoFocus(true);
|
||||
m_Border = new ScaledBorder();
|
||||
m_Border.x_label = xname; //"App. " + Name + " func. calls";
|
||||
m_Border.y_label = yname; //"fitness";
|
||||
setBorder(m_Border);
|
||||
setAutoGrid(true);
|
||||
setGridVisible(true);
|
||||
m_PointSetContainer = new ArrayList(20);
|
||||
//new DMouseZoom( this );
|
||||
addPopup();
|
||||
repaint();
|
||||
notifyNegLog = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getGraphInfo(int x, int y) {
|
||||
String ret = "";
|
||||
if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0))
|
||||
return ret;
|
||||
int minindex = getNearestGraphIndex(x, y);
|
||||
ret = ((GraphPointSet) (m_PointSetContainer.get(minindex))).getInfoString();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean isStatisticsGraph(int x, int y) {
|
||||
boolean ret = false;
|
||||
if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0))
|
||||
return ret;
|
||||
int minindex = getNearestGraphIndex(x, y);
|
||||
ret = ((GraphPointSet) (m_PointSetContainer.get(minindex))).isStatisticsGraph();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private int getNearestGraphIndex(int x, int y) {
|
||||
// get index of nearest Graph
|
||||
double distmin = 10000000;
|
||||
int minindex = -1;
|
||||
DPoint point1 = getDMeasures().getDPoint(x, y);
|
||||
DPoint point2 = null;
|
||||
double dist = 0;
|
||||
for (int i = 0; i < m_PointSetContainer.size(); i++) {
|
||||
if (m_PointSetContainer.get(i)instanceof GraphPointSet) {
|
||||
GraphPointSet pointset = (GraphPointSet) (m_PointSetContainer.get(i));
|
||||
point2 = pointset.getNearestDPoint(point1);
|
||||
if (point2 == null)
|
||||
continue;
|
||||
if (point1 == null)
|
||||
System.err.println("point1 == null");
|
||||
|
||||
dist = (point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y);
|
||||
//System.out.println("dist="+dist+"i="+i);
|
||||
if (dist < distmin) {
|
||||
distmin = dist;
|
||||
minindex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return minindex;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private DPoint getNearestDPoint(int x, int y) {
|
||||
// get index of nearest Graph
|
||||
double distmin = 10000000;
|
||||
DPoint ret = null;
|
||||
DPoint point1 = getDMeasures().getDPoint(x, y);
|
||||
DPoint point2 = null;
|
||||
double dist = 0;
|
||||
for (int i = 0; i < m_PointSetContainer.size(); i++) {
|
||||
if (m_PointSetContainer.get(i)instanceof GraphPointSet) {
|
||||
GraphPointSet pointset = (GraphPointSet) (m_PointSetContainer.get(i));
|
||||
point2 = pointset.getNearestDPoint(point1);
|
||||
if (point2 == null)
|
||||
continue;
|
||||
dist = (point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y);
|
||||
//System.out.println("dist="+dist+"i="+i);
|
||||
if (dist < distmin) {
|
||||
distmin = dist;
|
||||
ret = point2;
|
||||
}
|
||||
if ((dist == distmin) && !(ret.getIcon()instanceof Chart2DDPointIconContent) && !(ret.getIcon()instanceof InterfaceSelectablePointIcon)) {
|
||||
distmin = dist;
|
||||
ret = point2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void exportToAscii() {
|
||||
String[] s = null;
|
||||
for (int i = 0; i < m_PointSetContainer.size(); i++) {
|
||||
if (m_PointSetContainer.get(i)instanceof GraphPointSet) {
|
||||
GraphPointSet set = (GraphPointSet) m_PointSetContainer.get(i);
|
||||
String info = set.getInfoString();
|
||||
DPointSet pset = set.getConnectedPointSet();
|
||||
if (s == null) {
|
||||
s = new String[pset.getSize() + 1];
|
||||
s[0] = "calls";
|
||||
}
|
||||
s[0] = s[0] + " " + info;
|
||||
for (int j = 1; j < s.length; j++) {
|
||||
if (i == 0)
|
||||
s[j] = "" + pset.getDPoint(j - 1).x;
|
||||
try {
|
||||
s[j] = s[j] + " " + pset.getDPoint(j - 1).y;
|
||||
} catch (Exception e) {
|
||||
s[j] += " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < s.length; j++) {
|
||||
System.out.println("s=" + s[j]);
|
||||
}
|
||||
// todo: Steichert hat einfach einen default namen genommen
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("E'_'yyyy.MM.dd'_'HH.mm.ss");
|
||||
String fname = "PlotExport_"+formatter.format(new Date());
|
||||
// System.out.println("Filename ??");
|
||||
// String fname = null;
|
||||
// BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||
// try {
|
||||
// fname = in.readLine();
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("" + e.getMessage());
|
||||
// }
|
||||
try {
|
||||
File f = new File(fname + ".txt");
|
||||
f.createNewFile();
|
||||
PrintWriter Out = new PrintWriter(new FileOutputStream(f));
|
||||
for (int j = 0; j < s.length; j++)
|
||||
Out.println(s[j]);
|
||||
Out.flush();
|
||||
Out.close();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error:" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setConnectedPoint(double x, double y, int GraphLabel) {
|
||||
if (m_log == true && y <= 0.0) {
|
||||
y = 1;
|
||||
// y = Double.MIN_VALUE;
|
||||
if (notifyNegLog) {
|
||||
System.err.println("Warning: trying to plot value (" + x + "/" + y + ") with y < 0 in logarithmic mode! Setting y to " + y);
|
||||
notifyNegLog = false;
|
||||
}
|
||||
}
|
||||
getGraphPointSet(GraphLabel).addDPoint(x, y);
|
||||
|
||||
}
|
||||
|
||||
public void addGraphPointSet(GraphPointSet d) {
|
||||
this.m_PointSetContainer.add(d);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addGraph(int GraphLabel_1, int GraphLabel_2, boolean forceAdd) {
|
||||
getGraphPointSet(GraphLabel_1).addGraph(getGraphPointSet(GraphLabel_2), this.getDMeasures(), forceAdd);
|
||||
notifyNegLog = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void clearGraph(int GraphLabel) {
|
||||
getGraphPointSet(GraphLabel).removeAllPoints();
|
||||
m_PointSetContainer.remove(getGraphPointSet(GraphLabel));
|
||||
repaint();
|
||||
notifyNegLog = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void changeColorGraph(int GraphLabel) {
|
||||
Color col = getGraphPointSet(GraphLabel).getColor();
|
||||
if (col == Color.black)
|
||||
col = Color.red;
|
||||
else
|
||||
if (col == Color.red)
|
||||
col = Color.blue;
|
||||
else
|
||||
if (col == Color.blue)
|
||||
col = Color.red;
|
||||
else
|
||||
if (col == Color.red)
|
||||
col = Color.black;
|
||||
getGraphPointSet(GraphLabel).setColor(col);
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void clearGraph(int x, int y) {
|
||||
int index = getNearestGraphIndex(x, y);
|
||||
if (index == -1)
|
||||
return;
|
||||
int GraphLabel = ((GraphPointSet) (this.m_PointSetContainer.get(index))).getGraphLabel();
|
||||
clearGraph(GraphLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void changeColorGraph(int x, int y) {
|
||||
int index = getNearestGraphIndex(x, y);
|
||||
if (index == -1)
|
||||
return;
|
||||
int GraphLabel = ((GraphPointSet) (this.m_PointSetContainer.get(index))).getGraphLabel();
|
||||
changeColorGraph(GraphLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePoint(int x, int y) {
|
||||
DPoint point = getNearestDPoint(x, y);
|
||||
int index = getNearestGraphIndex(x, y);
|
||||
if (index == -1 || point == null)
|
||||
return;
|
||||
GraphPointSet pointset = (GraphPointSet) (this.m_PointSetContainer.get(index));
|
||||
pointset.removePoint(point);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setInfoString(int GraphLabel, String Info, float stroke) {
|
||||
getGraphPointSet(GraphLabel).setInfoString(Info, stroke);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void clearAll() {
|
||||
this.removeAllDElements();
|
||||
for (int i = 0; i < m_PointSetContainer.size(); i++)
|
||||
((GraphPointSet) (m_PointSetContainer.get(i))).removeAllPoints();
|
||||
m_PointSetContainer.clear();
|
||||
notifyNegLog = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private GraphPointSet getGraphPointSet(int GraphLabel) {
|
||||
// System.out.println("looping through " + m_PointSetContainer.size() + " point sets...");
|
||||
for (int i = 0; i < m_PointSetContainer.size(); i++) {
|
||||
if (m_PointSetContainer.get(i) instanceof GraphPointSet) {
|
||||
GraphPointSet xx = (GraphPointSet) (m_PointSetContainer.get(i));
|
||||
// System.out.println("looking at "+xx.getGraphLabel());
|
||||
if (xx.getGraphLabel() == GraphLabel) {
|
||||
// System.out.println("match!");
|
||||
return xx;
|
||||
}
|
||||
}
|
||||
}
|
||||
// create new GraphPointSet
|
||||
GraphPointSet NewPointSet = new GraphPointSet(GraphLabel, this);
|
||||
// System.out.println("adding new point set " + GraphLabel);
|
||||
//NewPointSet.setStroke(new BasicStroke( (float)1.0 ));
|
||||
//addGraphPointSet(NewPointSet); already done within GraphPointSet!!!
|
||||
return NewPointSet;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setUnconnectedPoint(double x, double y, int GraphLabel) {
|
||||
if (m_log == true && y <= 0.0) {
|
||||
if (notifyNegLog) {
|
||||
System.err.println("Warning: trying to plot value (" + x + "/" + y + ") with y < 0 in logarithmic mode! Setting y to " + y );
|
||||
notifyNegLog = false;
|
||||
}
|
||||
y = 1;
|
||||
}
|
||||
this.getGraphPointSet(GraphLabel).addDPoint(x, y);
|
||||
this.getGraphPointSet(GraphLabel).setConnectedMode(false);
|
||||
repaint();
|
||||
}
|
||||
|
||||
Color[] Colors = new Color[] {Color.black, Color.red, Color.blue, Color.green,Color.magenta, Color.orange, Color.pink, Color.yellow};
|
||||
|
||||
public void setGraphColor(int GraphLabel,int colorindex) {
|
||||
this.getGraphPointSet(GraphLabel).setColor(Colors[colorindex%Colors.length]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of points within the graph of the given label.
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public int getPointCount(int label) {
|
||||
return getGraphPointSet(label).getPointCount();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int getContainerSize() {
|
||||
return m_PointSetContainer.size();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DPointSet[] printPoints() {
|
||||
DPointSet[] ret = new DPointSet[m_PointSetContainer.size()];
|
||||
for (int i = 0; i < m_PointSetContainer.size(); i++) {
|
||||
System.out.println("");
|
||||
System.out.println("GraphPointSet No " + i);
|
||||
|
||||
ret[i] = ((GraphPointSet) m_PointSetContainer.get(i)).printPoints();
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
public DPointSet printPoints(int i) {
|
||||
//for (int i = 0; i < m_PointSetContainer.size();i++) {
|
||||
System.out.println("");
|
||||
System.out.println("GraphPointSet No " + i);
|
||||
|
||||
return ((GraphPointSet) m_PointSetContainer.get(i)).printPoints();
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void toggleLog() {
|
||||
//System.out.println("ToggleLog log was: "+m_log);
|
||||
if (m_log == false) {
|
||||
setMinRectangle(0.001, 0.001, 1, 1);
|
||||
//setVisibleRectangle( 0.001, 0.001, 100000, 1000 );
|
||||
setYScale(new Exp());
|
||||
m_Border.setSrcdY(Math.log(10));
|
||||
((java.text.DecimalFormat) m_Border.format_y).applyPattern("0.###E0");
|
||||
m_log = true;
|
||||
} else {
|
||||
m_log = false;
|
||||
setYScale(null);
|
||||
ScaledBorder buffer = m_Border;
|
||||
m_Border = new ScaledBorder();
|
||||
m_Border.x_label = buffer.x_label; //"App. " + Name + " func. calls";
|
||||
m_Border.y_label = buffer.y_label; //"fitness";
|
||||
setBorder(m_Border);
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes all PointSets to interupt the connected painting at the
|
||||
* current position.
|
||||
*/
|
||||
public void jump() {
|
||||
for (int i = 0; i < m_PointSetContainer.size(); i++)
|
||||
((GraphPointSet) (m_PointSetContainer.get(i))).jump();
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public Object openObject() {
|
||||
if (m_FileChooser == null)
|
||||
createFileChooser();
|
||||
int returnVal = m_FileChooser.showOpenDialog(this);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File selected = m_FileChooser.getSelectedFile();
|
||||
try {
|
||||
ObjectInputStream oi = new ObjectInputStream(new BufferedInputStream(new FileInputStream(selected)));
|
||||
Object obj = oi.readObject();
|
||||
oi.close();
|
||||
|
||||
Object[] objects = (Object[]) obj;
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
GraphPointSet xx = ((GraphPointSet.SerPointSet) objects[i]).getGraphPointSet();
|
||||
xx.initGraph(this);
|
||||
addGraphPointSet(xx);
|
||||
}
|
||||
repaint();
|
||||
return obj;
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Couldn't read object: "
|
||||
+ selected.getName()
|
||||
+ "\n" + ex.getMessage(),
|
||||
"Open object file",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void saveObject() {
|
||||
Object[] object = new Object[m_PointSetContainer.size()];
|
||||
for (int i = 0; i < m_PointSetContainer.size(); i++) {
|
||||
object[i] = ((GraphPointSet) m_PointSetContainer.get(i)).getSerPointSet();
|
||||
}
|
||||
if (m_FileChooser == null)
|
||||
createFileChooser();
|
||||
int returnVal = m_FileChooser.showSaveDialog(this);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File sFile = m_FileChooser.getSelectedFile();
|
||||
try {
|
||||
ObjectOutputStream oo = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(sFile)));
|
||||
oo.writeObject(object);
|
||||
oo.close();
|
||||
} catch (IOException ex) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Couldn't write to file: "
|
||||
+ sFile.getName()
|
||||
+ "\n" + ex.getMessage(),
|
||||
"Save object",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void createFileChooser() {
|
||||
m_FileChooser = new JFileChooser(new File("/resources"));
|
||||
m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
}
|
||||
|
||||
/** Add a popup menu for displaying certain information.
|
||||
*/
|
||||
private void addPopup() {
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
|
||||
// do nothing
|
||||
} else {
|
||||
JPopupMenu GraphMenu = new JPopupMenu();
|
||||
m_x = e.getX();
|
||||
m_y = e.getY();
|
||||
|
||||
// The first info element
|
||||
JMenuItem Info = new JMenuItem("Graph Info: " + getGraphInfo(e.getX(), e.getY()));
|
||||
Info.addActionListener(new ActionListener() {
|
||||
//
|
||||
public void actionPerformed(ActionEvent ee) {
|
||||
DPoint temp = FunctionArea.this.getDMeasures().getDPoint(FunctionArea.this.m_x, FunctionArea.this.m_y);
|
||||
DPointIcon icon1 = new DPointIcon() {
|
||||
public void paint(Graphics g) {
|
||||
g.drawLine( -2, 0, 2, 0);
|
||||
g.drawLine(0, 0, 0, 4);
|
||||
}
|
||||
|
||||
public DBorder getDBorder() {
|
||||
return new DBorder(4, 4, 4, 4);
|
||||
}
|
||||
};
|
||||
temp.setIcon(icon1);
|
||||
FunctionArea.this.addDElement(temp);
|
||||
}
|
||||
});
|
||||
GraphMenu.add(Info);
|
||||
if (m_RefPointListener != null) {
|
||||
DPoint temp = getDMeasures().getDPoint(m_x, m_y);
|
||||
JMenuItem refPoint = new JMenuItem("Reference Point:("+temp.x+"/"+temp.y+")");
|
||||
refPoint.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent ee) {
|
||||
DPoint temp = getDMeasures().getDPoint(m_x, m_y);
|
||||
double[] point = new double[2];
|
||||
point[0] = temp.x;
|
||||
point[1] = temp.y;
|
||||
m_RefPointListener.refPointGiven(point);
|
||||
}
|
||||
});
|
||||
GraphMenu.add(refPoint);
|
||||
}
|
||||
|
||||
// darn this point is an empty copy !!
|
||||
DPoint point = getNearestDPoint(e.getX(), e.getY());
|
||||
|
||||
if (point != null) {
|
||||
JMenuItem InfoXY = new JMenuItem("(" + point.x + "/" + point.y+")");
|
||||
Info.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent ee) {
|
||||
}
|
||||
});
|
||||
GraphMenu.add(InfoXY);
|
||||
|
||||
if (point.getIcon()instanceof InterfaceSelectablePointIcon) {
|
||||
m_CurrentPointIcon = point.getIcon();
|
||||
if (((InterfaceSelectablePointIcon)m_CurrentPointIcon).getSelectionListener() != null) {
|
||||
JMenuItem select;
|
||||
AbstractEAIndividual indy = ((InterfaceSelectablePointIcon)m_CurrentPointIcon).getEAIndividual();
|
||||
if (indy.isMarked()) select = new JMenuItem("Deselect individual");
|
||||
else select = new JMenuItem("Select individual");
|
||||
select.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent ee) {
|
||||
((InterfaceSelectablePointIcon)m_CurrentPointIcon).getSelectionListener().individualSelected(((InterfaceSelectablePointIcon)m_CurrentPointIcon).getEAIndividual());
|
||||
}
|
||||
});
|
||||
GraphMenu.add(select);
|
||||
}
|
||||
}
|
||||
|
||||
if (point.getIcon()instanceof InterfaceDPointWithContent) {
|
||||
m_CurrentPointIcon = point.getIcon();
|
||||
JMenuItem drawIndy = new JMenuItem("Show individual");
|
||||
drawIndy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent ee) {
|
||||
((InterfaceDPointWithContent)m_CurrentPointIcon).showIndividual();
|
||||
}
|
||||
});
|
||||
GraphMenu.add(drawIndy);
|
||||
}
|
||||
|
||||
}
|
||||
if (FunctionArea.this.m_PointSetContainer.size() > 0) {
|
||||
JMenuItem removeGraph = new JMenuItem("Remove graph");
|
||||
removeGraph.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent ee) {
|
||||
clearGraph(FunctionArea.this.m_x, FunctionArea.this.m_y);
|
||||
}
|
||||
});
|
||||
GraphMenu.add(removeGraph);
|
||||
}
|
||||
if (FunctionArea.this.m_PointSetContainer.size() > 0) {
|
||||
JMenuItem changecolorGraph = new JMenuItem("Change color");
|
||||
changecolorGraph.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent ee) {
|
||||
changeColorGraph(FunctionArea.this.m_x, FunctionArea.this.m_y);
|
||||
}
|
||||
});
|
||||
GraphMenu.add(changecolorGraph);
|
||||
}
|
||||
if (FunctionArea.this.m_PointSetContainer.size() > 0) {
|
||||
JMenuItem removePoint = new JMenuItem("Remove point");
|
||||
removePoint.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent ee) {
|
||||
removePoint(FunctionArea.this.m_x, FunctionArea.this.m_y);
|
||||
}
|
||||
});
|
||||
GraphMenu.add(removePoint);
|
||||
}
|
||||
// if (isStatisticsGraph(e.getX(),e.getY())==true) {
|
||||
// if (getVar(e.getX(),e.getY())==false) {
|
||||
// JMenuItem showVar = new JMenuItem("Show varianz ");
|
||||
// showVar.addActionListener(new ActionListener() {
|
||||
// //
|
||||
// public void actionPerformed(ActionEvent ee) {
|
||||
// setVar(m_x,m_y,true);
|
||||
// }
|
||||
// });
|
||||
// GraphMenu.add(showVar);
|
||||
//
|
||||
// }
|
||||
// else {
|
||||
// JMenuItem hideVar = new JMenuItem("Hide varianz ");
|
||||
// hideVar.addActionListener(new ActionListener() {
|
||||
// //
|
||||
// public void actionPerformed(ActionEvent ee) {
|
||||
// setVar(m_x,m_y,false);
|
||||
// }
|
||||
// });
|
||||
// GraphMenu.add(hideVar);
|
||||
// }
|
||||
// }
|
||||
GraphMenu.show(FunctionArea.this, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** This method allows to add a selection listner to the PointIcon
|
||||
* it should need more than one listener to this abstruse event
|
||||
* @param a The selection listener
|
||||
*/
|
||||
public void addRefPointSelectionListener(InterfaceRefPointListener a) {
|
||||
this.m_RefPointListener = a;
|
||||
}
|
||||
|
||||
/** This method returns the selection listner to the PointIcon
|
||||
* @return InterfaceSelectionListener
|
||||
*/
|
||||
public InterfaceRefPointListener getRefPointSelectionListener() {
|
||||
return this.m_RefPointListener;
|
||||
}
|
||||
|
||||
/** This method allows to remove the selection listner to the PointIcon
|
||||
*/
|
||||
public void removeRefPointSelectionListeners() {
|
||||
this.m_RefPointListener = null;
|
||||
}
|
||||
|
||||
}
|
||||
168
src/javaeva/gui/GenericAreaEditor.java
Normal file
168
src/javaeva/gui/GenericAreaEditor.java
Normal file
@@ -0,0 +1,168 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javaeva.tools.EVAHELP;
|
||||
import javaeva.server.go.individuals.codings.gp.AbstractGPNode;
|
||||
import javaeva.server.go.individuals.codings.gp.GPArea;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 27.06.2003
|
||||
* Time: 11:41:01
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class GenericAreaEditor extends JPanel implements PropertyEditor {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The GPArea that is to be edited*/
|
||||
private GPArea m_AreaObject;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JPanel m_CustomEditor, m_NodePanel;
|
||||
private JCheckBox[] m_BlackCheck;
|
||||
|
||||
public GenericAreaEditor() {
|
||||
// compiled code
|
||||
}
|
||||
|
||||
/** This method will init the CustomEditor Panel
|
||||
*/
|
||||
private void initCustomEditor() {
|
||||
this.m_CustomEditor = new JPanel();
|
||||
this.m_CustomEditor.setLayout(new BorderLayout());
|
||||
this.m_CustomEditor.add(new JLabel("Choose the area:"), BorderLayout.NORTH);
|
||||
this.m_NodePanel = new JPanel();
|
||||
this.m_CustomEditor.add(new JScrollPane(this.m_NodePanel), BorderLayout.CENTER);
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
/** The object may have changed update the editor.
|
||||
*/
|
||||
private void updateEditor() {
|
||||
if (this.m_NodePanel != null) {
|
||||
|
||||
ArrayList GPNodes = this.m_AreaObject.getCompleteList();
|
||||
ArrayList Allowed = this.m_AreaObject.getBlackList();
|
||||
this.m_NodePanel.removeAll();
|
||||
this.m_NodePanel.setLayout(new GridLayout(GPNodes.size(), 1));
|
||||
this.m_BlackCheck = new JCheckBox[GPNodes.size()];
|
||||
for (int i = 0; i < GPNodes.size(); i++) {
|
||||
this.m_BlackCheck[i] = new JCheckBox((((AbstractGPNode)GPNodes.get(i))).getName(), ((Boolean)Allowed.get(i)).booleanValue());
|
||||
this.m_BlackCheck[i].addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
makeNodeList();
|
||||
}
|
||||
});
|
||||
this.m_NodePanel.add(this.m_BlackCheck[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method checks the current BlackList and compiles it
|
||||
* to a new ReducedList.
|
||||
*/
|
||||
private void makeNodeList() {
|
||||
for (int i = 0; i < this.m_BlackCheck.length; i++) {
|
||||
this.m_AreaObject.setBlackListElement(i, this.m_BlackCheck[i].isSelected());
|
||||
}
|
||||
this.m_AreaObject.compileReducedList();
|
||||
}
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof GPArea) {
|
||||
this.m_AreaObject = (GPArea) o;
|
||||
this.updateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/** Retruns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_AreaObject;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = "Select from available GPNodes";
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (this.m_CustomEditor == null) this.initCustomEditor();
|
||||
return m_CustomEditor;
|
||||
}
|
||||
}
|
||||
434
src/javaeva/gui/GenericArrayEditor.java
Normal file
434
src/javaeva/gui/GenericArrayEditor.java
Normal file
@@ -0,0 +1,434 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 235 $
|
||||
* $Date: 2007-11-08 13:53:51 +0100 (Thu, 08 Nov 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
|
||||
import javaeva.tools.EVAHELP;
|
||||
import javaeva.tools.SelectedTag;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import javax.swing.ListCellRenderer;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyEditorManager;
|
||||
import java.lang.reflect.Array;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
public class GenericArrayEditor extends JPanel
|
||||
implements PropertyEditor {
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The list component displaying current values */
|
||||
private JList m_ElementList = new JList();
|
||||
/** The class of objects allowed in the array */
|
||||
private Class m_ElementClass = String.class;
|
||||
/** The defaultlistmodel holding our data */
|
||||
private DefaultListModel m_ListModel;
|
||||
/** The property editor for the class we are editing */
|
||||
private PropertyEditor m_ElementEditor;
|
||||
/** Click this to delete the selected array values */
|
||||
private JButton m_DeleteBut = new JButton("Delete");
|
||||
/** Click to add the current object configuration to the array */
|
||||
private JButton m_AddBut = new JButton("Add");
|
||||
/** Listens to buttons being pressed and taking the appropriate action */
|
||||
private ActionListener m_InnerActionListener =
|
||||
new ActionListener() {
|
||||
//
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getSource() == m_DeleteBut) {
|
||||
int [] selected = m_ElementList.getSelectedIndices();
|
||||
if (selected != null) {
|
||||
for (int i = 0; i < selected.length; i++) {
|
||||
int current = selected[i];
|
||||
m_ListModel.removeElementAt(current);
|
||||
if (m_ListModel.size() > current) {
|
||||
m_ElementList.setSelectedIndex(current);
|
||||
}
|
||||
}
|
||||
m_Support.firePropertyChange("", null, null);
|
||||
}
|
||||
if (m_ElementList.getSelectedIndex() == -1) {
|
||||
m_DeleteBut.setEnabled(false);
|
||||
}
|
||||
} else if (e.getSource() == m_AddBut) {
|
||||
int selected = m_ElementList.getSelectedIndex();
|
||||
Object addObj = m_ElementEditor.getValue();
|
||||
|
||||
// Make a full copy of the object using serialization
|
||||
try {
|
||||
SerializedObject so = new SerializedObject(addObj);
|
||||
addObj = so.getObject();
|
||||
if (selected != -1) {
|
||||
m_ListModel.insertElementAt(addObj, selected);
|
||||
} else {
|
||||
m_ListModel.addElement(addObj);
|
||||
}
|
||||
m_Support.firePropertyChange("", null, null);
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(GenericArrayEditor.this,"Could not create an object copy",null,JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** Listens to list items being selected and takes appropriate action */
|
||||
private ListSelectionListener m_InnerSelectionListener =
|
||||
new ListSelectionListener() {
|
||||
//
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
|
||||
if (e.getSource() == m_ElementList) {
|
||||
// Enable the delete button
|
||||
//System.out.println("m_ElementList.getSelectedIndex()"+m_ElementList.getSelectedIndex());
|
||||
if (m_ElementList.getSelectedIndex() != -1) {
|
||||
m_DeleteBut.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the array editor.
|
||||
*/
|
||||
public GenericArrayEditor() {
|
||||
setLayout(new BorderLayout());
|
||||
add(m_Label, BorderLayout.CENTER);
|
||||
m_DeleteBut.addActionListener(m_InnerActionListener);
|
||||
m_AddBut.addActionListener(m_InnerActionListener);
|
||||
m_ElementList.addListSelectionListener(m_InnerSelectionListener);
|
||||
m_AddBut.setToolTipText("Add the current item to the list");
|
||||
m_DeleteBut.setToolTipText("Delete the selected list item");
|
||||
}
|
||||
|
||||
/* This class handles the creation of list cell renderers from the
|
||||
* property editors.
|
||||
*/
|
||||
private class EditorListCellRenderer implements ListCellRenderer {
|
||||
/** The class of the property editor for array objects */
|
||||
private Class m_EditorClass;
|
||||
/** The class of the array values */
|
||||
private Class m_ValueClass;
|
||||
/**
|
||||
* Creates the list cell renderer.
|
||||
*
|
||||
* @param editorClass The class of the property editor for array objects
|
||||
* @param valueClass The class of the array values
|
||||
*/
|
||||
public EditorListCellRenderer(Class editorClass, Class valueClass) {
|
||||
m_EditorClass = editorClass;
|
||||
m_ValueClass = valueClass;
|
||||
}
|
||||
/**
|
||||
* Creates a cell rendering component.
|
||||
*
|
||||
* @param JList the list that will be rendered in
|
||||
* @param Object the cell value
|
||||
* @param int which element of the list to render
|
||||
* @param boolean true if the cell is selected
|
||||
* @param boolean true if the cell has the focus
|
||||
* @return the rendering component
|
||||
*/
|
||||
public Component getListCellRendererComponent(final JList list,
|
||||
final Object value,
|
||||
final int index,
|
||||
final boolean isSelected,
|
||||
final boolean cellHasFocus) {
|
||||
try {
|
||||
final PropertyEditor e = (PropertyEditor)m_EditorClass.newInstance();
|
||||
if (e instanceof GenericObjectEditor) {
|
||||
// ((GenericObjectEditor) e).setDisplayOnly(true);
|
||||
((GenericObjectEditor) e).setClassType(m_ValueClass);
|
||||
}
|
||||
e.setValue(value);
|
||||
return new JPanel() {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void paintComponent(Graphics g) {
|
||||
Insets i = this.getInsets();
|
||||
Rectangle box = new Rectangle(i.left,i.top,
|
||||
this.getWidth(), //- i.right,
|
||||
this.getHeight() );//- i.bottom +20);
|
||||
g.setColor(isSelected ? list.getSelectionBackground() : list.getBackground());
|
||||
g.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
g.setColor(isSelected ? list.getSelectionForeground(): list.getForeground());
|
||||
e.paintValue(g, box);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Dimension getPreferredSize() {
|
||||
// Dimension newPref = getPreferredSize();
|
||||
// newPref.height = getFontMetrics(getFont()).getHeight() * 6 / 4; //6 / 4;
|
||||
// newPref.width = newPref.height * 6; //5
|
||||
// setPreferredSize(newPref);
|
||||
|
||||
|
||||
// Font f = this.getFont();
|
||||
// FontMetrics fm = this.getFontMetrics(f);
|
||||
// return new Dimension(0, fm.getHeight());
|
||||
|
||||
Font f = this.getFont();
|
||||
FontMetrics fm = this.getFontMetrics(f);
|
||||
Dimension newPref = new Dimension(0, fm.getHeight());
|
||||
newPref.height = getFontMetrics(getFont()).getHeight() * 6 / 4; //6 / 4;
|
||||
newPref.width = newPref.height * 6; //5
|
||||
return newPref;
|
||||
}
|
||||
};
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the type of object being edited, so attempts to find an
|
||||
* appropriate propertyeditor.
|
||||
*
|
||||
* @param o a value of type 'Object'
|
||||
*/
|
||||
private void updateEditorType(Object o) {
|
||||
|
||||
// Determine if the current object is an array
|
||||
m_ElementEditor = null; m_ListModel = null;
|
||||
removeAll();
|
||||
|
||||
if ((o != null) && (o.getClass().isArray())) {
|
||||
Class elementClass = o.getClass().getComponentType();
|
||||
PropertyEditor editor = PropertyEditorProvider.findEditor(elementClass);
|
||||
Component view = null;
|
||||
ListCellRenderer lcr = new DefaultListCellRenderer();
|
||||
if (editor != null) {
|
||||
if (editor instanceof GenericObjectEditor) {
|
||||
((GenericObjectEditor) editor).setClassType(elementClass);
|
||||
}
|
||||
if (editor.isPaintable() && editor.supportsCustomEditor()) {
|
||||
view = new PropertyPanel(editor);
|
||||
lcr = new EditorListCellRenderer(editor.getClass(), elementClass);
|
||||
} else if (editor.getTags() != null) {
|
||||
view = new PropertyValueSelector(editor);
|
||||
} else if (editor.getAsText() != null) {
|
||||
view = new PropertyText(editor);
|
||||
}
|
||||
}
|
||||
if (view == null) {
|
||||
System.err.println("No property editor for class: "
|
||||
+ elementClass.getName());
|
||||
} else {
|
||||
m_ElementEditor = editor;
|
||||
|
||||
// Create the ListModel and populate it
|
||||
m_ListModel = new DefaultListModel();
|
||||
m_ElementClass = elementClass;
|
||||
for (int i = 0; i < Array.getLength(o); i++) {
|
||||
m_ListModel.addElement(Array.get(o,i));
|
||||
}
|
||||
m_ElementList.setCellRenderer(lcr);
|
||||
m_ElementList.setModel(m_ListModel);
|
||||
if (m_ListModel.getSize() > 0) {
|
||||
m_ElementList.setSelectedIndex(0);
|
||||
m_DeleteBut.setEnabled(true);
|
||||
} else {
|
||||
m_DeleteBut.setEnabled(false);
|
||||
}
|
||||
|
||||
try {
|
||||
if (m_ListModel.getSize() > 0) {
|
||||
m_ElementEditor.setValue(m_ListModel.getElementAt(0));
|
||||
} else {
|
||||
if (m_ElementEditor instanceof GenericObjectEditor) {
|
||||
((GenericObjectEditor)m_ElementEditor).setDefaultValue();
|
||||
} else {
|
||||
m_ElementEditor.setValue(m_ElementClass.newInstance());
|
||||
}
|
||||
}
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.add(view, BorderLayout.CENTER);
|
||||
panel.add(m_AddBut, BorderLayout.EAST);
|
||||
add(panel, BorderLayout.NORTH);
|
||||
add(new JScrollPane(m_ElementList), BorderLayout.CENTER);
|
||||
add(m_DeleteBut, BorderLayout.SOUTH);
|
||||
m_ElementEditor.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
System.err.println(ex.getMessage());
|
||||
m_ElementEditor = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_ElementEditor == null) {
|
||||
add(m_Label, BorderLayout.CENTER);
|
||||
}
|
||||
m_Support.firePropertyChange("", null, null);
|
||||
validate();
|
||||
}
|
||||
/**
|
||||
* Sets the current object array.
|
||||
*
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
// Create a new list model, put it in the list and resize?
|
||||
updateEditorType(o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current object array.
|
||||
*
|
||||
* @return the current object array
|
||||
*/
|
||||
public Object getValue() {
|
||||
|
||||
if (m_ListModel == null) {
|
||||
return null;
|
||||
}
|
||||
// Convert the listmodel to an array of strings and return it.
|
||||
int length = m_ListModel.getSize();
|
||||
Object result = Array.newInstance(m_ElementClass, length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
Array.set(result, i, m_ListModel.elementAt(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supposedly returns an initialization string to create a classifier
|
||||
* identical to the current one, including it's state, but this doesn't
|
||||
* appear possible given that the initialization string isn't supposed to
|
||||
* contain multiple statements.
|
||||
*
|
||||
* @return the java source code initialisation string
|
||||
*/
|
||||
public String getJavaInitializationString() {
|
||||
return "null";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to indicate that we can paint a representation of the
|
||||
* string array
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
// System.out.println(m_ListModel + " --- " + m_ElementClass);
|
||||
String rep = m_ListModel.getSize() + " " + EVAHELP.cutClassName(m_ElementClass.getName());
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void main(String [] args) {
|
||||
try {
|
||||
java.beans.PropertyEditorManager.registerEditor(SelectedTag.class,TagEditor.class);
|
||||
java.beans.PropertyEditorManager.registerEditor(String [].class,GenericArrayEditor.class);
|
||||
java.beans.PropertyEditorManager.registerEditor(double [].class,GenericArrayEditor.class);
|
||||
GenericArrayEditor editor = new GenericArrayEditor();
|
||||
|
||||
double [] initial = { 1, 2, 34,656,46 };
|
||||
PropertyDialog pd = new PropertyDialog(editor,EVAHELP.cutClassName(editor.getClass().getName())
|
||||
, 100, 100);
|
||||
pd.setSize(200,200);
|
||||
pd.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
editor.setValue(initial);
|
||||
//ce.validate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
279
src/javaeva/gui/GenericDoubleArrayEditor.java
Normal file
279
src/javaeva/gui/GenericDoubleArrayEditor.java
Normal file
@@ -0,0 +1,279 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 05.03.2004
|
||||
* Time: 13:51:14
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class GenericDoubleArrayEditor extends JPanel implements PropertyEditor {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The FilePath that is to be edited*/
|
||||
private PropertyDoubleArray m_DoubleArray;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JPanel m_CustomEditor, m_DataPanel, m_ButtonPanel;
|
||||
private JTextField[] m_InputTextField;
|
||||
private JButton m_OKButton, m_AddButton, m_DeleteButton, m_NormalizeButton;
|
||||
|
||||
public GenericDoubleArrayEditor() {
|
||||
// compiled code
|
||||
}
|
||||
|
||||
/** This method will init the CustomEditor Panel
|
||||
*/
|
||||
private void initCustomEditor() {
|
||||
this.m_CustomEditor = new JPanel();
|
||||
this.m_CustomEditor.setLayout(new BorderLayout());
|
||||
|
||||
this.m_CustomEditor.add(new JLabel("Current Double Array:"), BorderLayout.NORTH);
|
||||
|
||||
// init data panel
|
||||
this.m_DataPanel = new JPanel();
|
||||
this.updateDataPanel();
|
||||
this.m_CustomEditor.add(this.m_DataPanel, BorderLayout.CENTER);
|
||||
|
||||
// init button panel
|
||||
this.m_ButtonPanel = new JPanel();
|
||||
this.m_AddButton = new JButton("Add");
|
||||
this.m_AddButton.addActionListener(this.addAction);
|
||||
this.m_DeleteButton = new JButton("Delete");
|
||||
this.m_DeleteButton.addActionListener(this.deleteAction);
|
||||
this.m_NormalizeButton = new JButton("Normalize");
|
||||
this.m_NormalizeButton.addActionListener(this.mormalizeAction);
|
||||
this.m_OKButton = new JButton("OK");
|
||||
this.m_OKButton.setEnabled(true);
|
||||
this.m_OKButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//m_Backup = copyObject(m_Object);
|
||||
if ((m_CustomEditor.getTopLevelAncestor() != null) && (m_CustomEditor.getTopLevelAncestor() instanceof Window)) {
|
||||
Window w = (Window) m_CustomEditor.getTopLevelAncestor();
|
||||
w.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.m_ButtonPanel.add(this.m_AddButton);
|
||||
this.m_ButtonPanel.add(this.m_DeleteButton);
|
||||
this.m_ButtonPanel.add(this.m_NormalizeButton);
|
||||
this.m_ButtonPanel.add(this.m_OKButton);
|
||||
this.m_CustomEditor.add(this.m_ButtonPanel, BorderLayout.SOUTH);
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
/** This action listener adds an element to DoubleArray
|
||||
*/
|
||||
ActionListener addAction = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
double[] tmpD = m_DoubleArray.getDoubleArray();
|
||||
double[] newD = new double[tmpD.length+1];
|
||||
|
||||
for (int i = 0; i < newD.length; i++) newD[i] = 1.0;
|
||||
for (int i = 0; i < tmpD.length; i++) newD[i] = tmpD[i];
|
||||
m_DoubleArray.setDoubleArray(newD);
|
||||
updateEditor();
|
||||
}
|
||||
};
|
||||
/** This action listener removes an element to DoubleArray
|
||||
*/
|
||||
ActionListener deleteAction = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
double[] tmpD = m_DoubleArray.getDoubleArray();
|
||||
double[] newD = new double[tmpD.length-1];
|
||||
|
||||
for (int i = 0; i < newD.length; i++) newD[i] = tmpD[i];
|
||||
m_DoubleArray.setDoubleArray(newD);
|
||||
updateEditor();
|
||||
}
|
||||
};
|
||||
/** This action listener nomalizes the values of the DoubleArray
|
||||
*/
|
||||
ActionListener mormalizeAction = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
double[] tmpD = m_DoubleArray.getDoubleArray();
|
||||
double sum = 0;
|
||||
|
||||
for (int i = 0; i < tmpD.length; i++) sum += tmpD[i];
|
||||
if (sum == 0) return;
|
||||
for (int i = 0; i < tmpD.length; i++) tmpD[i] = tmpD[i]/sum;
|
||||
m_DoubleArray.setDoubleArray(tmpD);
|
||||
updateEditor();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener reads all values
|
||||
*/
|
||||
KeyListener readDoubleArrayAction = new KeyListener() {
|
||||
public void keyPressed(KeyEvent event) {
|
||||
}
|
||||
public void keyTyped(KeyEvent event) {
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent event) {
|
||||
double[] tmpD = new double[m_InputTextField.length];
|
||||
|
||||
for (int i = 0; i < tmpD.length; i++) {
|
||||
|
||||
try {
|
||||
double d = 0;
|
||||
d = new Double(m_InputTextField[i].getText()).doubleValue();
|
||||
tmpD[i] = d;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
//tmpD[i] = new Double(m_InputTextField[i].getText()).doubleValue();
|
||||
}
|
||||
|
||||
m_DoubleArray.setDoubleArray(tmpD);
|
||||
//updateEditor();
|
||||
}
|
||||
};
|
||||
|
||||
/** The object may have changed update the editor.
|
||||
*/
|
||||
private void updateEditor() {
|
||||
if (this.m_CustomEditor != null) {
|
||||
this.updateDataPanel();
|
||||
this.m_CustomEditor.validate();
|
||||
this.m_CustomEditor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/** This method updates the data panel
|
||||
*/
|
||||
private void updateDataPanel() {
|
||||
double[] tmpD = this.m_DoubleArray.getDoubleArray();
|
||||
|
||||
this.m_DataPanel.removeAll();
|
||||
this.m_DataPanel.setLayout(new GridLayout(tmpD.length, 2));
|
||||
this.m_InputTextField = new JTextField[tmpD.length];
|
||||
for (int i = 0; i < tmpD.length; i++) {
|
||||
JLabel label = new JLabel("Value X"+i+": ");
|
||||
this.m_DataPanel.add(label);
|
||||
this.m_InputTextField[i] = new JTextField();
|
||||
this.m_InputTextField[i].setText(""+tmpD[i]);
|
||||
this.m_InputTextField[i].addKeyListener(this.readDoubleArrayAction);
|
||||
this.m_DataPanel.add(this.m_InputTextField[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof PropertyDoubleArray) {
|
||||
this.m_DoubleArray = (PropertyDoubleArray) o;
|
||||
this.updateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_DoubleArray;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/** This is used to hook an action listener to the ok button
|
||||
* @param a The action listener.
|
||||
*/
|
||||
public void addOkListener(ActionListener a) {
|
||||
m_OKButton.addActionListener(a);
|
||||
}
|
||||
|
||||
/** This is used to remove an action listener from the ok button
|
||||
* @param a The action listener
|
||||
*/
|
||||
public void removeOkListener(ActionListener a) {
|
||||
m_OKButton.removeActionListener(a);
|
||||
}
|
||||
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = "Edit double[]";
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (this.m_CustomEditor == null) this.initCustomEditor();
|
||||
return m_CustomEditor;
|
||||
}
|
||||
}
|
||||
246
src/javaeva/gui/GenericEpsilonConstraintEditor.java
Normal file
246
src/javaeva/gui/GenericEpsilonConstraintEditor.java
Normal file
@@ -0,0 +1,246 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 14.07.2005
|
||||
* Time: 16:33:45
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class GenericEpsilonConstraintEditor extends JPanel implements PropertyEditor {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The FilePath that is to be edited*/
|
||||
private PropertyEpsilonConstraint m_EpsilonConstraint;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JPanel m_CustomEditor, m_DataPanel, m_ButtonPanel, m_TargetPanel;
|
||||
private JTextField[] m_TargetTextField;
|
||||
private JComboBox m_Objective;
|
||||
private JButton m_OKButton;
|
||||
|
||||
public GenericEpsilonConstraintEditor() {
|
||||
// compiled code
|
||||
}
|
||||
|
||||
/** This method will init the CustomEditor Panel
|
||||
*/
|
||||
private void initCustomEditor() {
|
||||
this.m_CustomEditor = new JPanel();
|
||||
this.m_CustomEditor.setLayout(new BorderLayout());
|
||||
|
||||
// target panel
|
||||
this.m_TargetPanel = new JPanel();
|
||||
this.m_TargetPanel.setLayout(new GridLayout(1, 2));
|
||||
this.m_TargetPanel.add(new JLabel("Optimize:"));
|
||||
this.m_Objective = new JComboBox();
|
||||
for (int i = 0; i < this.m_EpsilonConstraint.m_TargetValue.length; i++) this.m_Objective.addItem("Objective "+i);
|
||||
this.m_TargetPanel.add(this.m_Objective);
|
||||
this.m_Objective.addItemListener(this.objectiveAction);
|
||||
this.m_CustomEditor.add(this.m_TargetPanel, BorderLayout.NORTH);
|
||||
|
||||
// init data panel
|
||||
this.m_DataPanel = new JPanel();
|
||||
this.updateDataPanel();
|
||||
this.m_CustomEditor.add(this.m_DataPanel, BorderLayout.CENTER);
|
||||
|
||||
// init button panel
|
||||
this.m_ButtonPanel = new JPanel();
|
||||
this.m_OKButton = new JButton("OK");
|
||||
this.m_OKButton.setEnabled(true);
|
||||
this.m_OKButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//m_Backup = copyObject(m_Object);
|
||||
if ((m_CustomEditor.getTopLevelAncestor() != null) && (m_CustomEditor.getTopLevelAncestor() instanceof Window)) {
|
||||
Window w = (Window) m_CustomEditor.getTopLevelAncestor();
|
||||
w.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.m_ButtonPanel.add(this.m_OKButton);
|
||||
this.m_CustomEditor.add(this.m_ButtonPanel, BorderLayout.SOUTH);
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
/** This action listener adds an element to DoubleArray
|
||||
*/
|
||||
ItemListener objectiveAction = new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent event) {
|
||||
m_EpsilonConstraint.m_OptimizeObjective = m_Objective.getSelectedIndex();
|
||||
updateEditor();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener reads all values
|
||||
*/
|
||||
KeyListener readDoubleArrayAction = new KeyListener() {
|
||||
public void keyPressed(KeyEvent event) {
|
||||
}
|
||||
public void keyTyped(KeyEvent event) {
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent event) {
|
||||
double[] tmpT = m_EpsilonConstraint.m_TargetValue;
|
||||
|
||||
for (int i = 0; i < tmpT.length; i++) {
|
||||
|
||||
try {
|
||||
double d = 0;
|
||||
d = new Double(m_TargetTextField[i].getText()).doubleValue();
|
||||
tmpT[i] = d;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
m_EpsilonConstraint.m_TargetValue = tmpT;
|
||||
}
|
||||
};
|
||||
|
||||
/** The object may have changed update the editor.
|
||||
*/
|
||||
private void updateEditor() {
|
||||
if (this.m_CustomEditor != null) {
|
||||
this.updateDataPanel();
|
||||
this.m_CustomEditor.validate();
|
||||
this.m_CustomEditor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/** This method updates the data panel
|
||||
*/
|
||||
private void updateDataPanel() {
|
||||
double[] tmpT = this.m_EpsilonConstraint.m_TargetValue;
|
||||
int obj = this.m_EpsilonConstraint.m_OptimizeObjective;
|
||||
|
||||
this.m_DataPanel.removeAll();
|
||||
this.m_DataPanel.setLayout(new GridLayout(tmpT.length+1, 2));
|
||||
this.m_DataPanel.add(new JLabel());
|
||||
this.m_DataPanel.add(new JLabel("Target Value"));
|
||||
this.m_TargetTextField = new JTextField[tmpT.length];
|
||||
for (int i = 0; i < tmpT.length; i++) {
|
||||
JLabel label = new JLabel("Objective "+i+": ");
|
||||
this.m_DataPanel.add(label);
|
||||
this.m_TargetTextField[i] = new JTextField();
|
||||
this.m_TargetTextField[i].setText(""+tmpT[i]);
|
||||
this.m_TargetTextField[i].addKeyListener(this.readDoubleArrayAction);
|
||||
this.m_DataPanel.add(this.m_TargetTextField[i]);
|
||||
}
|
||||
this.m_TargetTextField[obj].setEditable(false);
|
||||
}
|
||||
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof PropertyEpsilonConstraint) {
|
||||
this.m_EpsilonConstraint = (PropertyEpsilonConstraint) o;
|
||||
this.updateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_EpsilonConstraint;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/** This is used to hook an action listener to the ok button
|
||||
* @param a The action listener.
|
||||
*/
|
||||
public void addOkListener(ActionListener a) {
|
||||
m_OKButton.addActionListener(a);
|
||||
}
|
||||
|
||||
/** This is used to remove an action listener from the ok button
|
||||
* @param a The action listener
|
||||
*/
|
||||
public void removeOkListener(ActionListener a) {
|
||||
m_OKButton.removeActionListener(a);
|
||||
}
|
||||
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = "Edit Epsilon Constraint";
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (this.m_CustomEditor == null) this.initCustomEditor();
|
||||
return m_CustomEditor;
|
||||
}
|
||||
}
|
||||
263
src/javaeva/gui/GenericEpsilonThresholdEditor.java
Normal file
263
src/javaeva/gui/GenericEpsilonThresholdEditor.java
Normal file
@@ -0,0 +1,263 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 05.03.2004
|
||||
* Time: 15:17:09
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class GenericEpsilonThresholdEditor extends JPanel implements PropertyEditor {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The FilePath that is to be edited*/
|
||||
private PropertyEpsilonThreshold m_EpsilonThreshhold;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JPanel m_CustomEditor, m_DataPanel, m_ButtonPanel, m_TargetPanel;
|
||||
private JTextField[] m_TargetTextField, m_PunishTextField;
|
||||
private JComboBox m_Objective;
|
||||
private JButton m_OKButton;
|
||||
|
||||
public GenericEpsilonThresholdEditor() {
|
||||
// compiled code
|
||||
}
|
||||
|
||||
/** This method will init the CustomEditor Panel
|
||||
*/
|
||||
private void initCustomEditor() {
|
||||
this.m_CustomEditor = new JPanel();
|
||||
this.m_CustomEditor.setLayout(new BorderLayout());
|
||||
|
||||
// target panel
|
||||
this.m_TargetPanel = new JPanel();
|
||||
this.m_TargetPanel.setLayout(new GridLayout(1, 2));
|
||||
this.m_TargetPanel.add(new JLabel("Optimize:"));
|
||||
this.m_Objective = new JComboBox();
|
||||
for (int i = 0; i < this.m_EpsilonThreshhold.m_TargetValue.length; i++) this.m_Objective.addItem("Objective "+i);
|
||||
this.m_TargetPanel.add(this.m_Objective);
|
||||
this.m_Objective.addItemListener(this.objectiveAction);
|
||||
this.m_CustomEditor.add(this.m_TargetPanel, BorderLayout.NORTH);
|
||||
|
||||
// init data panel
|
||||
this.m_DataPanel = new JPanel();
|
||||
this.updateDataPanel();
|
||||
this.m_CustomEditor.add(this.m_DataPanel, BorderLayout.CENTER);
|
||||
|
||||
// init button panel
|
||||
this.m_ButtonPanel = new JPanel();
|
||||
this.m_OKButton = new JButton("OK");
|
||||
this.m_OKButton.setEnabled(true);
|
||||
this.m_OKButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//m_Backup = copyObject(m_Object);
|
||||
if ((m_CustomEditor.getTopLevelAncestor() != null) && (m_CustomEditor.getTopLevelAncestor() instanceof Window)) {
|
||||
Window w = (Window) m_CustomEditor.getTopLevelAncestor();
|
||||
w.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.m_ButtonPanel.add(this.m_OKButton);
|
||||
this.m_CustomEditor.add(this.m_ButtonPanel, BorderLayout.SOUTH);
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
/** This action listener adds an element to DoubleArray
|
||||
*/
|
||||
ItemListener objectiveAction = new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent event) {
|
||||
m_EpsilonThreshhold.m_OptimizeObjective = m_Objective.getSelectedIndex();
|
||||
updateEditor();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener reads all values
|
||||
*/
|
||||
KeyListener readDoubleArrayAction = new KeyListener() {
|
||||
public void keyPressed(KeyEvent event) {
|
||||
}
|
||||
public void keyTyped(KeyEvent event) {
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent event) {
|
||||
double[] tmpT = m_EpsilonThreshhold.m_TargetValue;
|
||||
double[] tmpP = m_EpsilonThreshhold.m_Punishment;
|
||||
|
||||
for (int i = 0; i < tmpT.length; i++) {
|
||||
|
||||
try {
|
||||
double d = 0;
|
||||
d = new Double(m_TargetTextField[i].getText()).doubleValue();
|
||||
tmpT[i] = d;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
try {
|
||||
double d = 0;
|
||||
d = new Double(m_PunishTextField[i].getText()).doubleValue();
|
||||
tmpP[i] = d;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
m_EpsilonThreshhold.m_TargetValue = tmpT;
|
||||
m_EpsilonThreshhold.m_Punishment = tmpP;
|
||||
}
|
||||
};
|
||||
|
||||
/** The object may have changed update the editor.
|
||||
*/
|
||||
private void updateEditor() {
|
||||
if (this.m_CustomEditor != null) {
|
||||
this.updateDataPanel();
|
||||
this.m_CustomEditor.validate();
|
||||
this.m_CustomEditor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/** This method updates the data panel
|
||||
*/
|
||||
private void updateDataPanel() {
|
||||
double[] tmpT = this.m_EpsilonThreshhold.m_TargetValue;
|
||||
double[] tmpP = this.m_EpsilonThreshhold.m_Punishment;
|
||||
int obj = this.m_EpsilonThreshhold.m_OptimizeObjective;
|
||||
|
||||
this.m_DataPanel.removeAll();
|
||||
this.m_DataPanel.setLayout(new GridLayout(tmpT.length+1, 3));
|
||||
this.m_DataPanel.add(new JLabel());
|
||||
this.m_DataPanel.add(new JLabel("Target Value"));
|
||||
this.m_DataPanel.add(new JLabel("Punishment"));
|
||||
this.m_TargetTextField = new JTextField[tmpT.length];
|
||||
this.m_PunishTextField = new JTextField[tmpT.length];
|
||||
for (int i = 0; i < tmpT.length; i++) {
|
||||
JLabel label = new JLabel("Objective "+i+": ");
|
||||
this.m_DataPanel.add(label);
|
||||
this.m_TargetTextField[i] = new JTextField();
|
||||
this.m_TargetTextField[i].setText(""+tmpT[i]);
|
||||
this.m_TargetTextField[i].addKeyListener(this.readDoubleArrayAction);
|
||||
this.m_DataPanel.add(this.m_TargetTextField[i]);
|
||||
this.m_PunishTextField[i] = new JTextField();
|
||||
this.m_PunishTextField[i].setText(""+tmpP[i]);
|
||||
this.m_PunishTextField[i].addKeyListener(this.readDoubleArrayAction);
|
||||
this.m_DataPanel.add(this.m_PunishTextField[i]);
|
||||
}
|
||||
this.m_TargetTextField[obj].setEditable(false);
|
||||
this.m_PunishTextField[obj].setEditable(false);
|
||||
}
|
||||
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof PropertyEpsilonThreshold) {
|
||||
this.m_EpsilonThreshhold = (PropertyEpsilonThreshold) o;
|
||||
this.updateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_EpsilonThreshhold;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/** This is used to hook an action listener to the ok button
|
||||
* @param a The action listener.
|
||||
*/
|
||||
public void addOkListener(ActionListener a) {
|
||||
m_OKButton.addActionListener(a);
|
||||
}
|
||||
|
||||
/** This is used to remove an action listener from the ok button
|
||||
* @param a The action listener
|
||||
*/
|
||||
public void removeOkListener(ActionListener a) {
|
||||
m_OKButton.removeActionListener(a);
|
||||
}
|
||||
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = "Edit Epsilon Threshhold";
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (this.m_CustomEditor == null) this.initCustomEditor();
|
||||
return m_CustomEditor;
|
||||
}
|
||||
}
|
||||
154
src/javaeva/gui/GenericFilePathEditor.java
Normal file
154
src/javaeva/gui/GenericFilePathEditor.java
Normal file
@@ -0,0 +1,154 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.io.File;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 28.08.2003
|
||||
* Time: 11:11:59
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class GenericFilePathEditor extends JPanel implements PropertyEditor {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The FilePath that is to be edited*/
|
||||
private PropertyFilePath m_FilePath;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JFileChooser m_FileChooser;
|
||||
private JPanel m_Panel;
|
||||
|
||||
public GenericFilePathEditor() {
|
||||
// compiled code
|
||||
}
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof PropertyFilePath) {
|
||||
this.m_FilePath = (PropertyFilePath) o;
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_FilePath;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = this.m_FilePath.FileName;
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
this.m_Panel = new JPanel();
|
||||
this.m_FileChooser = new JFileChooser();
|
||||
File file = new File(this.m_FilePath.getCompleteFilePath());
|
||||
this.m_FileChooser.setSelectedFile(file);
|
||||
this.m_FileChooser.setMultiSelectionEnabled(false);
|
||||
this.m_Panel.add(this.m_FileChooser);
|
||||
this.m_FileChooser.addActionListener(this.fileChooserAction);
|
||||
return this.m_Panel;
|
||||
}
|
||||
|
||||
/** This action listener, called by the "train" button, causes
|
||||
* the SOM to recalculate the mapping.
|
||||
*/
|
||||
ActionListener fileChooserAction = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
if (event.getActionCommand() == "ApproveSelection") {
|
||||
m_FilePath.setCompleteFilePath(m_FileChooser.getSelectedFile().getAbsolutePath());
|
||||
m_Support.firePropertyChange("", m_FilePath, null);
|
||||
Window w = (Window) m_FileChooser.getTopLevelAncestor();
|
||||
w.dispose();
|
||||
m_Panel = null;
|
||||
}
|
||||
if (event.getActionCommand() == "CancelSelection") {
|
||||
m_FilePath.setCompleteFilePath(m_FileChooser.getSelectedFile().getAbsolutePath());
|
||||
m_Support.firePropertyChange("", m_FilePath, null);
|
||||
Window w = (Window) m_FileChooser.getTopLevelAncestor();
|
||||
if (w != null) w.dispose();
|
||||
m_Panel = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
225
src/javaeva/gui/GenericIntArrayEditor.java
Normal file
225
src/javaeva/gui/GenericIntArrayEditor.java
Normal file
@@ -0,0 +1,225 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 12.09.2005
|
||||
* Time: 10:20:30
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class GenericIntArrayEditor extends JPanel implements PropertyEditor {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The FilePath that is to be edited*/
|
||||
private PropertyIntArray m_IntArray;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JPanel m_CustomEditor, m_DataPanel, m_ButtonPanel;
|
||||
private JTextField[] m_InputTextField;
|
||||
private JButton m_OKButton;
|
||||
|
||||
public GenericIntArrayEditor() {
|
||||
// compiled code
|
||||
}
|
||||
|
||||
/** This method will init the CustomEditor Panel
|
||||
*/
|
||||
private void initCustomEditor() {
|
||||
this.m_CustomEditor = new JPanel();
|
||||
this.m_CustomEditor.setLayout(new BorderLayout());
|
||||
|
||||
this.m_CustomEditor.add(new JLabel("Current Int Array:"), BorderLayout.NORTH);
|
||||
|
||||
// init data panel
|
||||
this.m_DataPanel = new JPanel();
|
||||
this.updateDataPanel();
|
||||
this.m_CustomEditor.add(this.m_DataPanel, BorderLayout.CENTER);
|
||||
|
||||
// init button panel
|
||||
this.m_ButtonPanel = new JPanel();
|
||||
this.m_OKButton = new JButton("OK");
|
||||
this.m_OKButton.setEnabled(true);
|
||||
this.m_OKButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//m_Backup = copyObject(m_Object);
|
||||
if ((m_CustomEditor.getTopLevelAncestor() != null) && (m_CustomEditor.getTopLevelAncestor() instanceof Window)) {
|
||||
Window w = (Window) m_CustomEditor.getTopLevelAncestor();
|
||||
w.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.m_ButtonPanel.add(this.m_OKButton);
|
||||
this.m_CustomEditor.add(this.m_ButtonPanel, BorderLayout.SOUTH);
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
/** This action listener reads all values
|
||||
*/
|
||||
KeyListener readIntArrayAction = new KeyListener() {
|
||||
public void keyPressed(KeyEvent event) {
|
||||
}
|
||||
public void keyTyped(KeyEvent event) {
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent event) {
|
||||
int[] tmpD = new int[m_InputTextField.length];
|
||||
|
||||
for (int i = 0; i < tmpD.length; i++) {
|
||||
try {
|
||||
int d = 0;
|
||||
d = new Integer(m_InputTextField[i].getText()).intValue();
|
||||
tmpD[i] = d;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
m_IntArray.setIntArray(tmpD);
|
||||
}
|
||||
};
|
||||
|
||||
/** The object may have changed update the editor.
|
||||
*/
|
||||
private void updateEditor() {
|
||||
if (this.m_CustomEditor != null) {
|
||||
this.updateDataPanel();
|
||||
this.m_CustomEditor.validate();
|
||||
this.m_CustomEditor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/** This method updates the data panel
|
||||
*/
|
||||
private void updateDataPanel() {
|
||||
int[] tmpD = this.m_IntArray.getIntArray();
|
||||
|
||||
this.m_DataPanel.removeAll();
|
||||
this.m_DataPanel.setLayout(new GridLayout(tmpD.length, 2));
|
||||
this.m_InputTextField = new JTextField[tmpD.length];
|
||||
for (int i = 0; i < tmpD.length; i++) {
|
||||
JLabel label = new JLabel("Value X"+i+": ");
|
||||
this.m_DataPanel.add(label);
|
||||
this.m_InputTextField[i] = new JTextField();
|
||||
this.m_InputTextField[i].setText(""+tmpD[i]);
|
||||
this.m_InputTextField[i].addKeyListener(this.readIntArrayAction);
|
||||
this.m_DataPanel.add(this.m_InputTextField[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof PropertyIntArray) {
|
||||
this.m_IntArray = (PropertyIntArray) o;
|
||||
this.updateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_IntArray;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/** This is used to hook an action listener to the ok button
|
||||
* @param a The action listener.
|
||||
*/
|
||||
public void addOkListener(ActionListener a) {
|
||||
m_OKButton.addActionListener(a);
|
||||
}
|
||||
|
||||
/** This is used to remove an action listener from the ok button
|
||||
* @param a The action listener
|
||||
*/
|
||||
public void removeOkListener(ActionListener a) {
|
||||
m_OKButton.removeActionListener(a);
|
||||
}
|
||||
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = "Edit int[]";
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (this.m_CustomEditor == null) this.initCustomEditor();
|
||||
return m_CustomEditor;
|
||||
}
|
||||
}
|
||||
871
src/javaeva/gui/GenericObjectEditor.java
Normal file
871
src/javaeva/gui/GenericObjectEditor.java
Normal file
@@ -0,0 +1,871 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 266 $
|
||||
* $Date: 2007-11-20 14:33:48 +0100 (Tue, 20 Nov 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyEditorManager;
|
||||
import java.io.File;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import wsi.ra.jproxy.RMIProxyLocal;
|
||||
|
||||
//import wsi.ra.tool.DummyCategory;
|
||||
|
||||
import javaeva.client.EvAClient;
|
||||
import javaeva.tools.CompileAndLoad;
|
||||
import javaeva.tools.EVAHELP;
|
||||
import javaeva.tools.ReflectPackage;
|
||||
import javaeva.tools.Tag;
|
||||
import javaeva.tools.SelectedTag;
|
||||
import javaeva.tools.Serializer;
|
||||
import javaeva.server.stat.StatisticsParameter;
|
||||
import javaeva.server.stat.StatisticsParameterImpl;
|
||||
|
||||
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
public class GenericObjectEditor implements PropertyEditor {
|
||||
static final public boolean TRACE = false;
|
||||
|
||||
private Object m_Object;
|
||||
private Object m_Backup;
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
private Class m_ClassType;
|
||||
private GOEPanel m_EditorComponent;
|
||||
private boolean m_Enabled = true;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class GOEPanel extends JPanel implements ItemListener {
|
||||
/** The chooser component */
|
||||
private JComboBox m_ObjectChooser;
|
||||
/** The component that performs classifier customization */
|
||||
private PropertySheetPanel m_ChildPropertySheet;
|
||||
/** The model containing the list of names to select from */
|
||||
private DefaultComboBoxModel m_ObjectNames;
|
||||
/** Open object from disk */
|
||||
private JButton m_OpenBut;
|
||||
/** Save object to disk */
|
||||
private JButton m_SaveBut;
|
||||
/** ok button */
|
||||
public JButton m_okBut;
|
||||
/** cancel button */
|
||||
private JButton m_cancelBut;
|
||||
/** edit source button */
|
||||
// private JButton m_editSourceBut;
|
||||
/** The filechooser for opening and saving object files */
|
||||
private JFileChooser m_FileChooser;
|
||||
/** Creates the GUI editor component */
|
||||
private Vector<String> m_ClassesLongName;
|
||||
// private String[] m_ClassesShortName;
|
||||
// private SourceCodeEditor m_SourceCodeEditor;
|
||||
// private PropertyDialog m_SourceCodeEditorFrame;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public GOEPanel() {
|
||||
//System.out.println("GOEPanel.Constructor !!");
|
||||
if (!(Proxy.isProxyClass(m_Object.getClass()))) m_Backup = copyObject(m_Object);
|
||||
m_ObjectNames = new DefaultComboBoxModel(new String [0]);
|
||||
m_ObjectChooser = new JComboBox(m_ObjectNames);
|
||||
m_ObjectChooser.setEditable(false);
|
||||
m_ChildPropertySheet = new PropertySheetPanel();
|
||||
m_ChildPropertySheet.addPropertyChangeListener(
|
||||
new PropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
m_Support.firePropertyChange("", m_Backup, m_Object);
|
||||
}
|
||||
});
|
||||
m_OpenBut = new JButton("Open...");
|
||||
m_OpenBut.setToolTipText("Load a configured object");
|
||||
m_OpenBut.setEnabled(true);
|
||||
m_OpenBut.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object object = openObject();
|
||||
if (object != null) {
|
||||
// setValue takes care of: Making sure obj is of right type,
|
||||
// and firing property change.
|
||||
setValue(object);
|
||||
// Need a second setValue to get property values filled in OK.
|
||||
// Not sure why.
|
||||
setValue(object); // <- Hannes ?!?!?
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
m_SaveBut = new JButton("Save...");
|
||||
m_SaveBut.setToolTipText("Save the current configured object");
|
||||
m_SaveBut.setEnabled(true);
|
||||
m_SaveBut.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
saveObject(m_Object);
|
||||
}
|
||||
});
|
||||
//
|
||||
// m_editSourceBut = new JButton("Edit Source");
|
||||
// m_editSourceBut.setToolTipText("Edit the Source");
|
||||
// m_editSourceBut.setEnabled(false);
|
||||
// m_editSourceBut.addActionListener(new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent e) {
|
||||
// m_editSourceBut.setEnabled(false);
|
||||
// m_SourceCodeEditor = new SourceCodeEditor();
|
||||
// String className = m_Object.getClass().getName();
|
||||
// m_SourceCodeEditor.editSource(EvAClient.DYNAMICCLASSES_PROPERTIES.getProperty(className));
|
||||
// m_SourceCodeEditorFrame = new PropertyDialog(m_SourceCodeEditor, "test", 50, 50);
|
||||
// m_SourceCodeEditorFrame.pack();
|
||||
// m_SourceCodeEditorFrame.addWindowListener(new WindowAdapter() {
|
||||
// public void windowClosing (WindowEvent e) {
|
||||
// m_SourceCodeEditor = null;
|
||||
// m_editSourceBut.setEnabled(true);
|
||||
// }
|
||||
// });
|
||||
// m_SourceCodeEditor.addPropertyChangeListener(new
|
||||
// PropertyChangeListener() {
|
||||
// public void propertyChange(PropertyChangeEvent evt) {
|
||||
// sourceChanged();
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
|
||||
m_okBut = new JButton("OK");
|
||||
m_okBut.setEnabled(true);
|
||||
m_okBut.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
m_Backup = copyObject(m_Object);
|
||||
if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) {
|
||||
Window w = (Window) getTopLevelAncestor();
|
||||
w.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
m_cancelBut = new JButton("Cancel");
|
||||
m_cancelBut.setEnabled(false);
|
||||
m_cancelBut.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (m_Backup != null) {
|
||||
m_Object = copyObject(m_Backup);
|
||||
setObject(m_Object);
|
||||
updateClassType();
|
||||
updateChooser();
|
||||
updateChildPropertySheet();
|
||||
}
|
||||
if ((getTopLevelAncestor() != null)
|
||||
&& (getTopLevelAncestor() instanceof Window)) {
|
||||
Window w = (Window) getTopLevelAncestor();
|
||||
w.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add(m_ObjectChooser, BorderLayout.NORTH); // important
|
||||
add(m_ChildPropertySheet, BorderLayout.CENTER);
|
||||
// Since we resize to the size of the property sheet, a scrollpane isn't
|
||||
// typically needed
|
||||
// add(new JScrollPane(m_ChildPropertySheet), BorderLayout.CENTER);
|
||||
|
||||
JPanel okcButs = new JPanel();
|
||||
okcButs.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
okcButs.setLayout(new GridLayout(1, 4, 5, 5));
|
||||
okcButs.add(m_OpenBut);
|
||||
okcButs.add(m_SaveBut);
|
||||
okcButs.add(m_okBut);
|
||||
// okcButs.add(m_editSourceBut);
|
||||
//okcButs.add(m_cancelBut);
|
||||
add(okcButs, BorderLayout.SOUTH);
|
||||
|
||||
if (m_ClassType != null) {
|
||||
updateClassType();
|
||||
updateChooser();
|
||||
updateChildPropertySheet();
|
||||
}
|
||||
m_ObjectChooser.addItemListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens an object from a file selected by the user.
|
||||
*
|
||||
* @return the loaded object, or null if the operation was cancelled
|
||||
*/
|
||||
protected Object openObject() {
|
||||
if (m_FileChooser == null) {
|
||||
createFileChooser();
|
||||
}
|
||||
int returnVal = m_FileChooser.showOpenDialog(this);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File selected = m_FileChooser.getSelectedFile();
|
||||
try {
|
||||
ObjectInputStream oi = new ObjectInputStream(new BufferedInputStream(new FileInputStream(selected)));
|
||||
Object obj = oi.readObject();
|
||||
oi.close();
|
||||
if (!m_ClassType.isAssignableFrom(obj.getClass())) {
|
||||
throw new Exception("Object not of type: " + m_ClassType.getName());
|
||||
}
|
||||
return obj;
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Couldn't read object: "
|
||||
+ selected.getName()
|
||||
+ "\n" + ex.getMessage(),
|
||||
"Open object file",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Saves the current object to a file selected by the user.
|
||||
* @param object The object to save.
|
||||
*/
|
||||
protected void saveObject(Object object) {
|
||||
|
||||
if (m_FileChooser == null) {
|
||||
createFileChooser();
|
||||
}
|
||||
int returnVal = m_FileChooser.showSaveDialog(this);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File sFile = m_FileChooser.getSelectedFile();
|
||||
try {
|
||||
ObjectOutputStream oo = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(sFile)));
|
||||
oo.writeObject(object);
|
||||
oo.close();
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Couldn't write to file: "
|
||||
+ sFile.getName()
|
||||
+ "\n" + ex.getMessage(),
|
||||
"Save object",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void createFileChooser() {
|
||||
m_FileChooser = new JFileChooser(new File("/resources"));
|
||||
m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a copy of an object using serialization
|
||||
* @param source the object to copy
|
||||
* @return a copy of the source object
|
||||
*/
|
||||
protected Object copyObject(Object source) {
|
||||
Object result = null;
|
||||
try {
|
||||
SerializedObject so = new SerializedObject(source);
|
||||
result = so.getObject();
|
||||
} catch (Exception ex) {
|
||||
System.err.println("GenericObjectEditor: Problem making backup object");
|
||||
System.err.println(source.getClass().getName());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to hook an action listener to the ok button
|
||||
* @param a The action listener.
|
||||
*/
|
||||
public void addOkListener(ActionListener a) {
|
||||
m_okBut.addActionListener(a);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to hook an action listener to the cancel button
|
||||
* @param a The action listener.
|
||||
*/
|
||||
public void addCancelListener(ActionListener a) {
|
||||
m_cancelBut.addActionListener(a);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to remove an action listener from the ok button
|
||||
* @param a The action listener
|
||||
*/
|
||||
public void removeOkListener(ActionListener a) {
|
||||
m_okBut.removeActionListener(a);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to remove an action listener from the cancel button
|
||||
* @param a The action listener
|
||||
*/
|
||||
public void removeCancelListener(ActionListener a) {
|
||||
m_cancelBut.removeActionListener(a);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void updateClassType() {
|
||||
if (TRACE) System.out.println("# updating class "+m_ClassType.getName());
|
||||
|
||||
if (Proxy.isProxyClass(m_ClassType)) {
|
||||
if (TRACE) System.out.println("PROXY! original was " + ((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_Object))).getOriginalClass().getName());
|
||||
m_ClassesLongName = new Vector<String>(getClassesFromProperties(((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_Object))).getOriginalClass().getName()));
|
||||
} else {
|
||||
m_ClassesLongName = new Vector<String>(getClassesFromProperties(m_ClassType.getName()));
|
||||
}
|
||||
m_ObjectChooser.setModel(new DefaultComboBoxModel(m_ClassesLongName));
|
||||
if (m_ClassesLongName.size() > 1) // testhu
|
||||
add(m_ObjectChooser, BorderLayout.NORTH);
|
||||
else
|
||||
remove(m_ObjectChooser);
|
||||
if (TRACE) System.out.println("# done updating class "+m_ClassType.getName());
|
||||
}
|
||||
|
||||
protected void updateChooser() {
|
||||
String objectName = /*EVAHELP.cutClassName*/ (m_Object.getClass().getName());
|
||||
boolean found = false;
|
||||
for (int i = 0; i < m_ObjectNames.getSize(); i++) {
|
||||
if (TRACE) System.out.println("in updateChooser: looking at "+(String)m_ObjectNames.getElementAt(i));
|
||||
if (objectName.equals((String)m_ObjectNames.getElementAt(i))) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
m_ObjectNames.addElement(objectName);
|
||||
m_ObjectChooser.getModel().setSelectedItem(objectName);
|
||||
}
|
||||
|
||||
|
||||
/** Updates the child property sheet, and creates if needed */
|
||||
public void updateChildPropertySheet() {
|
||||
//System.err.println("GOE::updateChildPropertySheet()");
|
||||
// Set the object as the target of the propertysheet
|
||||
m_ChildPropertySheet.setTarget(m_Object);
|
||||
// Adjust size of containing window if possible
|
||||
if ((getTopLevelAncestor() != null)
|
||||
&& (getTopLevelAncestor() instanceof Window)) {
|
||||
((Window) getTopLevelAncestor()).pack();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// public void sourceChanged() {
|
||||
//
|
||||
// //System.out.println("SOURCESTATECHANGED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ");
|
||||
// String className = (String) m_ObjectChooser.getSelectedItem();
|
||||
//
|
||||
//// @todohannes: hack! ausbessern
|
||||
// className = (String) m_ObjectChooser.getSelectedItem();
|
||||
// try {
|
||||
// if (m_userdefclasses == true) {
|
||||
// className = m_Object.getClass().getName();
|
||||
// Object[] para = new Object[] {};
|
||||
// Object n = (Object) CompileAndLoad.getInstanceFull(
|
||||
// EvAClient.DYNAMICCLASSES_PROPERTIES.getProperty(className),
|
||||
// className,
|
||||
// para);
|
||||
// setObject(n);
|
||||
// }
|
||||
// else {
|
||||
// System.out.println("m_userdefclasses == false!!!!!");
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex) {
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* When the chooser selection is changed, ensures that the Object
|
||||
* is changed appropriately.
|
||||
*
|
||||
* @param e a value of type 'ItemEvent'
|
||||
*/
|
||||
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
String className = (String)m_ObjectChooser.getSelectedItem();
|
||||
// m_editSourceBut.setEnabled(false);
|
||||
// @todohannes: hack! ausbessern
|
||||
// try {
|
||||
// if (EvAClient.DYNAMICCLASSES_PROPERTIES.containsKey(className) && m_userdefclasses) {
|
||||
// m_editSourceBut.setEnabled(true);
|
||||
// }
|
||||
// } catch (Exception e1) {
|
||||
// System.out.println("Fehler !!! " + e1);
|
||||
// }
|
||||
|
||||
// @todohannes: hack! ausbessern
|
||||
//
|
||||
// if (this.m_SourceCodeEditorFrame != null) {
|
||||
// m_SourceCodeEditorFrame.setVisible(false);
|
||||
// m_SourceCodeEditorFrame = null;
|
||||
// m_SourceCodeEditor = null;
|
||||
// }
|
||||
|
||||
if (TRACE) System.out.println("Event-Quelle: " + e.getSource().toString());
|
||||
if ((e.getSource() == m_ObjectChooser) && (e.getStateChange() == ItemEvent.SELECTED)){
|
||||
className = (String)m_ObjectChooser.getSelectedItem();
|
||||
try {
|
||||
// if (EvAClient.DYNAMICCLASSES_PROPERTIES.containsKey(className) && m_userdefclasses) {
|
||||
// Object[] para = new Object[] {};
|
||||
// String source = EvAClient.DYNAMICCLASSES_PROPERTIES.getProperty(className);
|
||||
// Object dummy = CompileAndLoad.getInstanceFull(source,className,para);
|
||||
// setObject(dummy);
|
||||
// } else {
|
||||
if (TRACE) System.out.println(className);
|
||||
Object n = (Object)Class.forName(className, true, ClassLoader.getSystemClassLoader()).newInstance();
|
||||
n = (Object)Class.forName(className).newInstance();
|
||||
setObject(n);
|
||||
// }
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Exeption in itemStateChanged "+ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
m_ObjectChooser.hidePopup();
|
||||
m_ObjectChooser.setSelectedIndex(0);
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Could not create an example of\n"
|
||||
+ className + "\n"
|
||||
+ "from the current classpath. Is it abstract? Is the default constructor missing?",
|
||||
"GenericObjectEditor",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
EVAHELP.getSystemPropertyString();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end of inner class
|
||||
|
||||
/**
|
||||
* Read the classes available for user selection from the properties or the classpath respectively
|
||||
*/
|
||||
public static ArrayList<String> getClassesFromProperties(String className) {
|
||||
if (TRACE) System.out.println("getClassesFromProperties - requesting className: "+className);
|
||||
|
||||
// Try to read the predefined classes from the props file.
|
||||
String typeOptions = EvAClient.getProperty(className);
|
||||
if (typeOptions == null) {
|
||||
// If none are defined, all assignable classes are searched the hard way, using the ReflectPackage
|
||||
return getClassesFromClassPath(className);
|
||||
} else {
|
||||
StringTokenizer st = new StringTokenizer(typeOptions, ", ");
|
||||
ArrayList<String> classes = new ArrayList<String>();
|
||||
while (st.hasMoreTokens()) {
|
||||
String current = st.nextToken().trim();
|
||||
//System.out.println("current ="+current);
|
||||
try {
|
||||
Class.forName(current); // test for instantiability
|
||||
classes.add(current);
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Couldn't load class with name: " + current);
|
||||
System.err.println("ex:"+ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<String> getClassesFromClassPath(String className) {
|
||||
ArrayList<String> classes = new ArrayList<String>();
|
||||
int dotIndex = className.lastIndexOf('.');
|
||||
if (dotIndex <= 0) {
|
||||
System.err.println("warning: " + className + " is not a package!");
|
||||
} else {
|
||||
String pckg = className.substring(0, className.lastIndexOf('.'));
|
||||
Class[] clsArr;
|
||||
try {
|
||||
clsArr = ReflectPackage.getAssignableClassesInPackage(pckg, Class.forName(className), true, true);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
clsArr = null;
|
||||
}
|
||||
if (clsArr == null) {
|
||||
System.out.println("Warning: No configuration property found in: "
|
||||
+EvAClient.EVA_PROPERTY_FILE + " "+"for "+className);
|
||||
classes.add(className);
|
||||
} else {
|
||||
for (Class class1 : clsArr) {
|
||||
int m = class1.getModifiers();
|
||||
if (!Modifier.isAbstract(m) && !class1.isInterface()) { // dont take abstract classes or interfaces
|
||||
try {
|
||||
Class[] params = new Class[0];
|
||||
class1.getConstructor(params);
|
||||
classes.add(class1.getName());
|
||||
} catch (NoSuchMethodException e) {
|
||||
System.err.println("GOE warning: Class " + class1.getName() + " has no default constructor, skipping...");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide or show the editable property of a class, this makes sense for classes
|
||||
* which are represented visually using the GenericObjectEditor.
|
||||
* Returns false, if an error occurs, else true.
|
||||
* An instance may call this statically on itself by means of this.getClass().
|
||||
* Actually this only sets the hidden property of the java bean which is checked in the
|
||||
* wasModified method of PropertySheetPanel.
|
||||
*
|
||||
* @param cls class the property belongs to
|
||||
* @param property string name of the property
|
||||
* @param hide desired value to set, true for hidden, false for visible
|
||||
* @return false, if an error occurs, else true
|
||||
*/
|
||||
public static boolean setExpertProperty(Class cls, String property, boolean expertValue) {
|
||||
try {
|
||||
BeanInfo bi = Introspector.getBeanInfo(cls);
|
||||
PropertyDescriptor[] props = bi.getPropertyDescriptors();
|
||||
for (int i=0; i<props.length; i++) {
|
||||
if ((props[i].getName().equals(property))) {
|
||||
if (expertValue != props[i].isExpert()) props[i].setExpert(expertValue);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.err.println("exception in setHideProperty: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide or show the editable property of a class, this makes sense for classes
|
||||
* which are represented visually using the GenericObjectEditor.
|
||||
* Returns false, if an error occurs, else true.
|
||||
* An instance may call this statically on itself by means of this.getClass().
|
||||
* Actually this only sets the hidden property of the java bean which is checked in the
|
||||
* wasModified method of PropertySheetPanel.
|
||||
*
|
||||
* @param cls class the property belongs to
|
||||
* @param property string name of the property
|
||||
* @param hide desired value to set, true for hidden, false for visible
|
||||
* @return false, if an error occurs, else true
|
||||
*/
|
||||
public static boolean setHideProperty(Class cls, String property, boolean hide) {
|
||||
try {
|
||||
BeanInfo bi = Introspector.getBeanInfo(cls);
|
||||
PropertyDescriptor[] props = bi.getPropertyDescriptors();
|
||||
for (int i=0; i<props.length; i++) {
|
||||
if ((props[i].getName().equals(property))) {
|
||||
if (hide != props[i].isHidden()) props[i].setHidden(hide);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.err.println("exception in setHideProperty: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience-method. See setHideProperty.
|
||||
*
|
||||
* @param cls
|
||||
* @param property
|
||||
* @param show
|
||||
* @return
|
||||
*/
|
||||
public static boolean setShowProperty(Class cls, String property, boolean show) {
|
||||
return GenericObjectEditor.setHideProperty(cls, property, !show);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the editor is "enabled", meaning that the current
|
||||
* values will be painted.
|
||||
*
|
||||
* @param newVal a value of type 'boolean'
|
||||
*/
|
||||
public void setEnabled(boolean newVal) {
|
||||
if (newVal != m_Enabled) {
|
||||
m_Enabled = newVal;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the class of values that can be edited.
|
||||
*
|
||||
* @param type a value of type 'Class'
|
||||
*/
|
||||
public void setClassType(Class type) {
|
||||
if (TRACE) System.out.println("GOE setClassType("+ (type == null? "<null>" : type.getName()) + ")");
|
||||
m_ClassType = type;
|
||||
if (m_EditorComponent != null)
|
||||
m_EditorComponent.updateClassType();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current object to be the default, taken as the first item in
|
||||
* the chooser
|
||||
*/
|
||||
public void setDefaultValue() {
|
||||
if (m_ClassType == null) {
|
||||
System.err.println("No ClassType set up for GenericObjectEditor!!");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector<String> v;
|
||||
if (Proxy.isProxyClass(m_ClassType)) {
|
||||
if (TRACE) System.out.println("PROXY! original was " + ((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_Object))).getOriginalClass().getName());
|
||||
v = new Vector<String>(getClassesFromProperties(((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_Object))).getOriginalClass().getName()));
|
||||
} else {
|
||||
v = new Vector<String>(getClassesFromProperties(m_ClassType.getName()));
|
||||
}
|
||||
|
||||
v = new Vector<String>(getClassesFromProperties(m_ClassType.getName()));
|
||||
try {
|
||||
if (v.size() > 0)
|
||||
setObject((Object)Class.forName((String)v.get(0)).newInstance());
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Exception in setDefaultValue !!!"+ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current Object. If the Object is in the
|
||||
* Object chooser, this becomes the selected item (and added
|
||||
* to the chooser if necessary).
|
||||
*
|
||||
* @param o an object that must be a Object.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
//System.err.println("setValue()" + m_ClassType.toString());
|
||||
|
||||
if (m_ClassType == null) {
|
||||
System.err.println("No ClassType set up for GenericObjectEditor!!");
|
||||
return;
|
||||
}
|
||||
if (!m_ClassType.isAssignableFrom(o.getClass())) {
|
||||
if (m_ClassType.isPrimitive()) {
|
||||
System.err.println("setValue object not of correct type! Expected "+m_ClassType.getName()+", got " + o.getClass().getName());
|
||||
System.err.println("setting primitive type");
|
||||
setObject((Object)o);
|
||||
//throw new NullPointerException("ASDF");
|
||||
} else {
|
||||
System.err.println("setValue object not of correct type! Expected "+m_ClassType.getName()+", got " + o.getClass().getName());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
setObject((Object)o);
|
||||
if (m_EditorComponent != null)
|
||||
m_EditorComponent.updateChooser();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current Object, but doesn't worry about updating
|
||||
* the state of the Object chooser.
|
||||
*
|
||||
* @param c a value of type 'Object'
|
||||
*/
|
||||
private void setObject(Object c) {
|
||||
// This should really call equals() for comparison.
|
||||
if (TRACE) System.out.println("setObject "+ c.getClass().getName());
|
||||
boolean trueChange = (c != getValue());
|
||||
//System.err.println("Didn't even try to make a Object copy!! "+ "(using original)");
|
||||
|
||||
m_Backup = m_Object;
|
||||
m_Object = c;
|
||||
|
||||
if (m_EditorComponent != null) {
|
||||
m_EditorComponent.updateChildPropertySheet();
|
||||
if (trueChange)
|
||||
m_Support.firePropertyChange("", m_Backup, m_Object);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the current Object.
|
||||
*
|
||||
* @return the current Object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return m_Object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supposedly returns an initialization string to create a Object
|
||||
* identical to the current one, including it's state, but this doesn't
|
||||
* appear possible given that the initialization string isn't supposed to
|
||||
* contain multiple statements.
|
||||
*
|
||||
* @return the java source code initialisation string
|
||||
*/
|
||||
public String getJavaInitializationString() {
|
||||
return "new " + m_Object.getClass().getName() + "()";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to indicate that we can paint a representation of the
|
||||
* Object.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Paints a representation of the current Object.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx,Rectangle box) {
|
||||
if (m_Enabled && m_Object != null) {
|
||||
int getNameMethod = -1;
|
||||
MethodDescriptor[] methods;
|
||||
String rep = "";
|
||||
try {
|
||||
BeanInfo bi = Introspector.getBeanInfo(m_Object.getClass());
|
||||
methods = bi.getMethodDescriptors();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
if (methods[i].getName().equalsIgnoreCase("getName")) getNameMethod = i;
|
||||
}
|
||||
} catch (IntrospectionException ex) {
|
||||
System.out.println("PropertySheetPanel.setTarget(): Couldn't introspect");
|
||||
return;
|
||||
}
|
||||
if (getNameMethod >= 0) {
|
||||
try {
|
||||
rep = (String)methods[getNameMethod].getMethod().invoke(m_Object, (Object[])null);
|
||||
} catch (java.lang.IllegalAccessException e1) {
|
||||
|
||||
} catch (java.lang.reflect.InvocationTargetException e2) {
|
||||
|
||||
}
|
||||
}
|
||||
if (rep.length() <= 0) {
|
||||
rep = m_Object.getClass().getName();
|
||||
int dotPos = rep.lastIndexOf('.');
|
||||
if (dotPos != -1)
|
||||
rep = rep.substring(dotPos + 1);
|
||||
}
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getHeight()) / 2;
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad -2 );
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns null as we don't support getting/setting values as text.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null as we don't support getting/setting values as text.
|
||||
*
|
||||
* @param text the text value
|
||||
* @exception IllegalArgumentException as we don't support
|
||||
* getting/setting values as text.
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null as we don't support getting values as tags.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true because we do support a custom editor.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array editing component.
|
||||
*
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (m_EditorComponent == null)
|
||||
m_EditorComponent = new GOEPanel();
|
||||
return m_EditorComponent;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void disableOK() {
|
||||
if (m_EditorComponent == null)
|
||||
m_EditorComponent = new GOEPanel();
|
||||
m_EditorComponent.m_okBut.setEnabled(false);
|
||||
}
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void main(String [] args) {
|
||||
try {
|
||||
PropertyEditorManager.registerEditor(SelectedTag.class,TagEditor.class);
|
||||
PropertyEditorManager.registerEditor(double[].class,GenericArrayEditor.class);
|
||||
GenericObjectEditor editor = new GenericObjectEditor();
|
||||
editor.setClassType(StatisticsParameter.class);
|
||||
editor.setValue(new StatisticsParameterImpl());
|
||||
PropertyDialog pd = new PropertyDialog(editor,EVAHELP.cutClassName(editor.getClass().getName()),110, 120);
|
||||
pd.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
PropertyEditor pe = ((PropertyDialog)e.getSource()).getEditor();
|
||||
Object c = (Object)pe.getValue();
|
||||
String options = "";
|
||||
if (TRACE) System.out.println(c.getClass().getName() + " " + options);
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
411
src/javaeva/gui/GenericOptimizationObjectivesEditor.java
Normal file
411
src/javaeva/gui/GenericOptimizationObjectivesEditor.java
Normal file
@@ -0,0 +1,411 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javaeva.server.go.problems.InterfaceOptimizationObjective;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationTarget;
|
||||
import javaeva.server.go.tools.GeneralGOEProperty;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 14.01.2005
|
||||
* Time: 17:32:47
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class GenericOptimizationObjectivesEditor extends JPanel implements PropertyEditor, java.beans.PropertyChangeListener {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The FilePath that is to be edited*/
|
||||
private PropertyOptimizationObjectives m_OptimizationObjectives;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JComponent m_Editor;
|
||||
private JPanel m_TargetList;
|
||||
private JComponent[] m_Targets;
|
||||
private JButton[] m_Delete;
|
||||
private JScrollPane m_ScrollTargets;
|
||||
private GeneralGOEProperty[] m_Editors;
|
||||
private PropertyChangeListener m_self;
|
||||
|
||||
public GenericOptimizationObjectivesEditor() {
|
||||
m_self = this;
|
||||
|
||||
}
|
||||
|
||||
/** This method will init the CustomEditor Panel
|
||||
*/
|
||||
private void initCustomEditor() {
|
||||
m_self = this;
|
||||
this.m_Editor = new JPanel();
|
||||
this.m_Editor.setPreferredSize(new Dimension(400, 200));
|
||||
this.m_Editor.setMinimumSize(new Dimension(400, 200));
|
||||
|
||||
// init the editors
|
||||
InterfaceOptimizationObjective[] list = this.m_OptimizationObjectives.getSelectedTargets();
|
||||
this.m_Editors = new GeneralGOEProperty[list.length];
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
this.m_Editors[i] = new GeneralGOEProperty();
|
||||
this.m_Editors[i].m_Name = list[i].getName();
|
||||
try {
|
||||
this.m_Editors[i].m_Value = list[i];
|
||||
this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(this.m_Editors[i].m_Value.getClass());
|
||||
if (this.m_Editors[i].m_Editor == null) this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(InterfaceOptimizationObjective.class);
|
||||
if (this.m_Editors[i].m_Editor instanceof GenericObjectEditor)
|
||||
((GenericObjectEditor) this.m_Editors[i].m_Editor).setClassType(InterfaceOptimizationTarget.class);
|
||||
this.m_Editors[i].m_Editor.setValue(this.m_Editors[i].m_Value);
|
||||
this.m_Editors[i].m_Editor.addPropertyChangeListener(this);
|
||||
this.findViewFor(this.m_Editors[i]);
|
||||
if (this.m_Editors[i].m_View != null) this.m_Editors[i].m_View.repaint();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Darn can't read the value...");
|
||||
}
|
||||
}
|
||||
this.m_TargetList = new JPanel();
|
||||
this.updateTargetList();
|
||||
this.m_ScrollTargets = new JScrollPane(this.m_TargetList);
|
||||
|
||||
this.m_Editor.setLayout(new BorderLayout());
|
||||
this.m_Editor.add(this.m_ScrollTargets, BorderLayout.CENTER);
|
||||
|
||||
// the add button
|
||||
JButton addButton = new JButton("Add Opt. Target");
|
||||
addButton.addActionListener(addTarget);
|
||||
this.m_Editor.add(addButton, BorderLayout.SOUTH);
|
||||
|
||||
// Some description would be nice
|
||||
JTextArea jt = new JTextArea();
|
||||
jt.setFont(new Font("SansSerif", Font.PLAIN,12));
|
||||
jt.setEditable(false);
|
||||
jt.setLineWrap(true);
|
||||
jt.setWrapStyleWord(true);
|
||||
jt.setText("Choose and parameterize optimization objectives.");
|
||||
jt.setBackground(getBackground());
|
||||
JPanel jp = new JPanel();
|
||||
jp.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder("Info"),
|
||||
BorderFactory.createEmptyBorder(0, 5, 5, 5)
|
||||
));
|
||||
jp.setLayout(new BorderLayout());
|
||||
jp.add(jt, BorderLayout.CENTER);
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new BorderLayout());
|
||||
JButton help = new JButton("Help");
|
||||
help.setEnabled(false);
|
||||
p2.add(help, BorderLayout.NORTH);
|
||||
jp.add(p2, BorderLayout.EAST);
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
this.m_Editor.add(jp, BorderLayout.NORTH);
|
||||
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
/** This method updates the server list
|
||||
*
|
||||
*/
|
||||
private void updateTargetList() {
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes;
|
||||
InterfaceOptimizationObjective[] list = this.m_OptimizationObjectives.getSelectedTargets();
|
||||
|
||||
this.m_TargetList.removeAll();
|
||||
this.m_TargetList.setLayout(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
this.m_Targets = new JComponent[list.length];
|
||||
this.m_Delete = new JButton[list.length];
|
||||
String[] cups = new String[8];
|
||||
for (int i = 0; i < cups.length; i++) cups[i] = ""+(i+1);
|
||||
// The head title
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 10;
|
||||
this.m_TargetList.add(new JLabel("Target"), gbc);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 1;
|
||||
this.m_TargetList.add(new JLabel("Remove"), gbc);
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
// the status indicator
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 10;
|
||||
// this.m_Targets[i] = new JButton(""+list[i].getName());
|
||||
// this.m_Targets[i].setEnabled(false);
|
||||
this.m_Targets[i] = this.m_Editors[i].m_View;
|
||||
this.m_TargetList.add(this.m_Targets[i], gbc);
|
||||
// The delete button
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 1;
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif");
|
||||
try {
|
||||
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find Sub24 icon, please move rescoure folder to working directory!");
|
||||
this.m_Delete[i] = new JButton("Sub");
|
||||
}
|
||||
this.m_Delete[i].addActionListener(deleteTarget);
|
||||
this.m_TargetList.add(this.m_Delete[i], gbc);
|
||||
}
|
||||
this.m_TargetList.repaint();
|
||||
this.m_TargetList.validate();
|
||||
if (this.m_ScrollTargets != null) {
|
||||
this.m_ScrollTargets.validate();
|
||||
this.m_ScrollTargets.repaint();
|
||||
}
|
||||
if (this.m_Editor != null) {
|
||||
this.m_Editor.validate();
|
||||
this.m_Editor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener updateTargets = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
updateTargetList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener addTarget = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
m_OptimizationObjectives.addTarget((InterfaceOptimizationObjective)m_OptimizationObjectives.getAvailableTargets()[0].clone());
|
||||
int l = m_OptimizationObjectives.getSelectedTargets().length;
|
||||
GeneralGOEProperty[] newEdit = new GeneralGOEProperty[l];
|
||||
for (int i = 0; i < m_Editors.length; i++) {
|
||||
newEdit[i] = m_Editors[i];
|
||||
}
|
||||
InterfaceOptimizationObjective[] list = m_OptimizationObjectives.getSelectedTargets();
|
||||
l--;
|
||||
newEdit[l] = new GeneralGOEProperty();
|
||||
newEdit[l].m_Name = list[l].getName();
|
||||
try {
|
||||
newEdit[l].m_Value = list[l];
|
||||
newEdit[l].m_Editor = PropertyEditorProvider.findEditor(newEdit[l].m_Value.getClass());
|
||||
if (newEdit[l].m_Editor == null) newEdit[l].m_Editor = PropertyEditorProvider.findEditor(InterfaceOptimizationObjective.class);
|
||||
if (newEdit[l].m_Editor instanceof GenericObjectEditor)
|
||||
((GenericObjectEditor) newEdit[l].m_Editor).setClassType(InterfaceOptimizationTarget.class);
|
||||
newEdit[l].m_Editor.setValue(newEdit[l].m_Value);
|
||||
newEdit[l].m_Editor.addPropertyChangeListener(m_self);
|
||||
findViewFor(newEdit[l]);
|
||||
if (newEdit[l].m_View != null) newEdit[l].m_View.repaint();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Darn can't read the value...");
|
||||
}
|
||||
m_Editors = newEdit;
|
||||
updateTargetList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener deleteTarget = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
int l = m_OptimizationObjectives.getSelectedTargets().length, j = 0;
|
||||
GeneralGOEProperty[] newEdit = new GeneralGOEProperty[l-1];
|
||||
for (int i = 0; i < m_Delete.length; i++) {
|
||||
if (event.getSource().equals(m_Delete[i])) m_OptimizationObjectives.removeTarget(i);
|
||||
else {
|
||||
newEdit[j] = m_Editors[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
m_Editors = newEdit;
|
||||
updateTargetList();
|
||||
}
|
||||
};
|
||||
|
||||
/** The object may have changed update the editor.
|
||||
*/
|
||||
private void updateEditor() {
|
||||
if (this.m_Editor != null) {
|
||||
this.m_TargetList.validate();
|
||||
this.m_TargetList.repaint();
|
||||
this.m_ScrollTargets.validate();
|
||||
this.m_ScrollTargets.repaint();
|
||||
this.m_Editor.validate();
|
||||
this.m_Editor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof PropertyOptimizationObjectives) {
|
||||
this.m_OptimizationObjectives= (PropertyOptimizationObjectives) o;
|
||||
this.updateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_OptimizationObjectives;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** This is used to hook an action listener to the ok button
|
||||
* @param a The action listener.
|
||||
*/
|
||||
public void addOkListener(ActionListener a) {
|
||||
//m_OKButton.addActionListener(a);
|
||||
}
|
||||
|
||||
/** This is used to remove an action listener from the ok button
|
||||
* @param a The action listener
|
||||
*/
|
||||
public void removeOkListener(ActionListener a) {
|
||||
//m_OKButton.removeActionListener(a);
|
||||
}
|
||||
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = "Optimization Targets";
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (this.m_Editor == null) this.initCustomEditor();
|
||||
return m_Editor;
|
||||
}
|
||||
|
||||
/** This method will udate the status of the object taking the values from all
|
||||
* supsequent editors and setting them to my object.
|
||||
*/
|
||||
public void updateCenterComponent(PropertyChangeEvent evt) {
|
||||
//this.updateTargetList();
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
public void findViewFor(GeneralGOEProperty editor) {
|
||||
if (editor.m_Editor instanceof sun.beans.editors.BoolEditor) {
|
||||
editor.m_View = new PropertyBoolSelector(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor instanceof sun.beans.editors.DoubleEditor) {
|
||||
editor.m_View = new PropertyText(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.isPaintable() && editor.m_Editor.supportsCustomEditor()) {
|
||||
editor.m_View = new PropertyPanel(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.getTags() != null ) {
|
||||
editor.m_View = new PropertyValueSelector(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.getAsText() != null) {
|
||||
editor.m_View = new PropertyText(editor.m_Editor);
|
||||
} else {
|
||||
System.out.println("Warning: Property \"" + editor.m_Name
|
||||
+ "\" has non-displayabale editor. Skipping.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/********************************* java.beans.PropertyChangeListener *************************/
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
/** This will wait for the GenericObjectEditor to finish
|
||||
* editing an object.
|
||||
* @param evt
|
||||
*/
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
Object newVal = evt.getNewValue();
|
||||
Object oldVal = evt.getOldValue();
|
||||
InterfaceOptimizationObjective[] list = this.m_OptimizationObjectives.getSelectedTargets();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (oldVal.equals(list[i])) {
|
||||
list[i] = (InterfaceOptimizationObjective)newVal;
|
||||
this.m_Editors[i].m_Name = list[i].getName();
|
||||
try {
|
||||
this.m_Editors[i].m_Value = list[i];
|
||||
this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(this.m_Editors[i].m_Value.getClass());
|
||||
if (this.m_Editors[i].m_Editor == null) this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(InterfaceOptimizationObjective.class);
|
||||
if (this.m_Editors[i].m_Editor instanceof GenericObjectEditor)
|
||||
((GenericObjectEditor) this.m_Editors[i].m_Editor).setClassType(InterfaceOptimizationTarget.class);
|
||||
this.m_Editors[i].m_Editor.setValue(this.m_Editors[i].m_Value);
|
||||
this.m_Editors[i].m_Editor.addPropertyChangeListener(this);
|
||||
this.findViewFor(this.m_Editors[i]);
|
||||
if (this.m_Editors[i].m_View != null) this.m_Editors[i].m_View.repaint();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Darn can't read the value...");
|
||||
}
|
||||
this.m_Targets[i] = this.m_Editors[i].m_View;
|
||||
}
|
||||
}
|
||||
//this.m_OptimizationTargets.setSelectedTargets(list);
|
||||
this.updateCenterComponent(evt); // Let our panel update before guys downstream
|
||||
m_Support.firePropertyChange("", m_OptimizationObjectives, m_OptimizationObjectives);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,476 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javaeva.server.go.problems.InterfaceOptimizationObjective;
|
||||
import javaeva.server.go.tools.GeneralGOEProperty;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 18.01.2005
|
||||
* Time: 13:46:20
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class GenericOptimizationObjectivesWithParamEditor extends JPanel implements PropertyEditor, java.beans.PropertyChangeListener {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The FilePath that is to be edited*/
|
||||
private PropertyOptimizationObjectivesWithParam m_OptimizationObjectivesWithWeights;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JComponent m_Editor;
|
||||
private JPanel m_TargetList;
|
||||
private JTextField[] m_Weights;
|
||||
private JComponent[] m_Targets;
|
||||
private JButton[] m_Delete;
|
||||
private JScrollPane m_ScrollTargets;
|
||||
private GeneralGOEProperty[] m_Editors;
|
||||
private PropertyChangeListener m_self;
|
||||
|
||||
public GenericOptimizationObjectivesWithParamEditor() {
|
||||
m_self = this;
|
||||
}
|
||||
|
||||
/** This method will init the CustomEditor Panel
|
||||
*/
|
||||
private void initCustomEditor() {
|
||||
m_self = this;
|
||||
this.m_Editor = new JPanel();
|
||||
this.m_Editor.setPreferredSize(new Dimension(450, 200));
|
||||
this.m_Editor.setMinimumSize(new Dimension(450, 200));
|
||||
|
||||
// init the editors
|
||||
InterfaceOptimizationObjective[] list = this.m_OptimizationObjectivesWithWeights.getSelectedTargets();
|
||||
this.m_Editors = new GeneralGOEProperty[list.length];
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
this.m_Editors[i] = new GeneralGOEProperty();
|
||||
this.m_Editors[i].m_Name = list[i].getName();
|
||||
try {
|
||||
this.m_Editors[i].m_Value = list[i];
|
||||
this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(this.m_Editors[i].m_Value.getClass());
|
||||
if (this.m_Editors[i].m_Editor == null) this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(InterfaceOptimizationObjective.class);
|
||||
if (this.m_Editors[i].m_Editor instanceof GenericObjectEditor)
|
||||
((GenericObjectEditor) this.m_Editors[i].m_Editor).setClassType(InterfaceOptimizationObjective.class);
|
||||
this.m_Editors[i].m_Editor.setValue(this.m_Editors[i].m_Value);
|
||||
this.m_Editors[i].m_Editor.addPropertyChangeListener(this);
|
||||
this.findViewFor(this.m_Editors[i]);
|
||||
if (this.m_Editors[i].m_View != null) this.m_Editors[i].m_View.repaint();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Darn can't read the value...");
|
||||
}
|
||||
}
|
||||
this.m_TargetList = new JPanel();
|
||||
this.updateTargetList();
|
||||
this.m_ScrollTargets = new JScrollPane(this.m_TargetList);
|
||||
|
||||
this.m_Editor.setLayout(new BorderLayout());
|
||||
this.m_Editor.add(this.m_ScrollTargets, BorderLayout.CENTER);
|
||||
|
||||
// The Button Panel
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new GridLayout(1,2));
|
||||
JButton addButton = new JButton("Add Opt. Target");
|
||||
JButton normButton = new JButton("Normalize Weights");
|
||||
normButton.setEnabled(this.m_OptimizationObjectivesWithWeights.isNormalizationEnabled());
|
||||
normButton.addActionListener(normalizeWeights);
|
||||
addButton.addActionListener(addTarget);
|
||||
buttonPanel.add(normButton);
|
||||
buttonPanel.add(addButton);
|
||||
|
||||
this.m_Editor.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// Some description would be nice
|
||||
JTextArea jt = new JTextArea();
|
||||
jt.setFont(new Font("SansSerif", Font.PLAIN,12));
|
||||
jt.setEditable(false);
|
||||
jt.setLineWrap(true);
|
||||
jt.setWrapStyleWord(true);
|
||||
jt.setText(this.m_OptimizationObjectivesWithWeights.getDescriptiveString());
|
||||
jt.setBackground(getBackground());
|
||||
JPanel jp = new JPanel();
|
||||
jp.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder("Info"),
|
||||
BorderFactory.createEmptyBorder(0, 5, 5, 5)
|
||||
));
|
||||
jp.setLayout(new BorderLayout());
|
||||
jp.add(jt, BorderLayout.CENTER);
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new BorderLayout());
|
||||
JButton help = new JButton("Help");
|
||||
help.setEnabled(false);
|
||||
p2.add(help, BorderLayout.NORTH);
|
||||
jp.add(p2, BorderLayout.EAST);
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
this.m_Editor.add(jp, BorderLayout.NORTH);
|
||||
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
/** This method updates the server list
|
||||
*
|
||||
*/
|
||||
private void updateTargetList() {
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes;
|
||||
InterfaceOptimizationObjective[] list = this.m_OptimizationObjectivesWithWeights.getSelectedTargets();
|
||||
double[] weights = this.m_OptimizationObjectivesWithWeights.getWeights();
|
||||
|
||||
this.m_TargetList.removeAll();
|
||||
this.m_TargetList.setLayout(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
this.m_Weights = new JTextField[list.length];
|
||||
this.m_Targets = new JComponent[list.length];
|
||||
this.m_Delete = new JButton[list.length];
|
||||
String[] cups = new String[8];
|
||||
for (int i = 0; i < cups.length; i++) cups[i] = ""+(i+1);
|
||||
// The head title
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 2;
|
||||
this.m_TargetList.add(new JLabel(this.m_OptimizationObjectivesWithWeights.getWeigthsLabel()), gbc);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 10;
|
||||
this.m_TargetList.add(new JLabel("Target"), gbc);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 2;
|
||||
gbc.weightx = 1;
|
||||
this.m_TargetList.add(new JLabel("Remove"), gbc);
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
// the weight
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 2;
|
||||
this.m_Weights[i] = new JTextField(""+weights[i]);
|
||||
this.m_Weights[i].addKeyListener(this.readDoubleArrayAction);
|
||||
this.m_TargetList.add(this.m_Weights[i], gbc);
|
||||
// the status indicator
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 10;
|
||||
this.m_Targets[i] = this.m_Editors[i].m_View;
|
||||
this.m_TargetList.add(this.m_Targets[i], gbc);
|
||||
// The delete button
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 2;
|
||||
gbc.weightx = 1;
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif");
|
||||
try {
|
||||
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find Sub24 icon, please move rescoure folder to working directory!");
|
||||
this.m_Delete[i] = new JButton("Sub");
|
||||
}
|
||||
this.m_Delete[i].addActionListener(deleteTarget);
|
||||
this.m_TargetList.add(this.m_Delete[i], gbc);
|
||||
}
|
||||
this.m_TargetList.repaint();
|
||||
this.m_TargetList.validate();
|
||||
if (this.m_ScrollTargets != null) {
|
||||
this.m_ScrollTargets.validate();
|
||||
this.m_ScrollTargets.repaint();
|
||||
}
|
||||
if (this.m_Editor != null) {
|
||||
this.m_Editor.validate();
|
||||
this.m_Editor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener updateTargets = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
updateTargetList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener addTarget = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
m_OptimizationObjectivesWithWeights.addTarget((InterfaceOptimizationObjective)m_OptimizationObjectivesWithWeights.getAvailableTargets()[0].clone());
|
||||
int l = m_OptimizationObjectivesWithWeights.getSelectedTargets().length;
|
||||
GeneralGOEProperty[] newEdit = new GeneralGOEProperty[l];
|
||||
for (int i = 0; i < m_Editors.length; i++) {
|
||||
newEdit[i] = m_Editors[i];
|
||||
}
|
||||
InterfaceOptimizationObjective[] list = m_OptimizationObjectivesWithWeights.getSelectedTargets();
|
||||
l--;
|
||||
newEdit[l] = new GeneralGOEProperty();
|
||||
newEdit[l].m_Name = list[l].getName();
|
||||
try {
|
||||
newEdit[l].m_Value = list[l];
|
||||
newEdit[l].m_Editor = PropertyEditorProvider.findEditor(newEdit[l].m_Value.getClass());
|
||||
if (newEdit[l].m_Editor == null) newEdit[l].m_Editor = PropertyEditorProvider.findEditor(InterfaceOptimizationObjective.class);
|
||||
if (newEdit[l].m_Editor instanceof GenericObjectEditor)
|
||||
((GenericObjectEditor) newEdit[l].m_Editor).setClassType(InterfaceOptimizationObjective.class);
|
||||
newEdit[l].m_Editor.setValue(newEdit[l].m_Value);
|
||||
newEdit[l].m_Editor.addPropertyChangeListener(m_self);
|
||||
findViewFor(newEdit[l]);
|
||||
if (newEdit[l].m_View != null) newEdit[l].m_View.repaint();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Darn can't read the value...");
|
||||
}
|
||||
m_Editors = newEdit;
|
||||
updateTargetList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener deleteTarget = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
int l = m_OptimizationObjectivesWithWeights.getSelectedTargets().length, j = 0;
|
||||
GeneralGOEProperty[] newEdit = new GeneralGOEProperty[l-1];
|
||||
for (int i = 0; i < m_Delete.length; i++) {
|
||||
if (event.getSource().equals(m_Delete[i])) m_OptimizationObjectivesWithWeights.removeTarget(i);
|
||||
else {
|
||||
newEdit[j] = m_Editors[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
m_Editors = newEdit;
|
||||
updateTargetList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener normalizeWeights = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
double[] newW = m_OptimizationObjectivesWithWeights.getWeights();
|
||||
double sum = 0;
|
||||
for (int i = 0; i < newW.length; i++) {
|
||||
sum += newW[i];
|
||||
}
|
||||
if (sum != 0) {
|
||||
for (int i = 0; i < newW.length; i++) {
|
||||
newW[i] = newW[i]/sum;
|
||||
}
|
||||
m_OptimizationObjectivesWithWeights.setWeights(newW);
|
||||
}
|
||||
updateTargetList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener reads all values
|
||||
*/
|
||||
KeyListener readDoubleArrayAction = new KeyListener() {
|
||||
public void keyPressed(KeyEvent event) {
|
||||
}
|
||||
public void keyTyped(KeyEvent event) {
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent event) {
|
||||
double[] newW = m_OptimizationObjectivesWithWeights.getWeights();
|
||||
|
||||
for (int i = 0; i < newW.length; i++) {
|
||||
try {
|
||||
double d = 0;
|
||||
d = new Double(m_Weights[i].getText()).doubleValue();
|
||||
newW[i] = d;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
m_OptimizationObjectivesWithWeights.setWeights(newW);
|
||||
}
|
||||
};
|
||||
|
||||
/** The object may have changed update the editor.
|
||||
*/
|
||||
private void updateEditor() {
|
||||
if (this.m_Editor != null) {
|
||||
this.m_TargetList.validate();
|
||||
this.m_TargetList.repaint();
|
||||
this.m_ScrollTargets.validate();
|
||||
this.m_ScrollTargets.repaint();
|
||||
this.m_Editor.validate();
|
||||
this.m_Editor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof PropertyOptimizationObjectivesWithParam) {
|
||||
this.m_OptimizationObjectivesWithWeights= (PropertyOptimizationObjectivesWithParam) o;
|
||||
this.updateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_OptimizationObjectivesWithWeights;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** This is used to hook an action listener to the ok button
|
||||
* @param a The action listener.
|
||||
*/
|
||||
public void addOkListener(ActionListener a) {
|
||||
//m_OKButton.addActionListener(a);
|
||||
}
|
||||
|
||||
/** This is used to remove an action listener from the ok button
|
||||
* @param a The action listener
|
||||
*/
|
||||
public void removeOkListener(ActionListener a) {
|
||||
//m_OKButton.removeActionListener(a);
|
||||
}
|
||||
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = "Optimization Targets With Weights";
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (this.m_Editor == null) this.initCustomEditor();
|
||||
return m_Editor;
|
||||
}
|
||||
|
||||
/** This method will udate the status of the object taking the values from all
|
||||
* supsequent editors and setting them to my object.
|
||||
*/
|
||||
public void updateCenterComponent(PropertyChangeEvent evt) {
|
||||
//this.updateTargetList();
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
public void findViewFor(GeneralGOEProperty editor) {
|
||||
if (editor.m_Editor instanceof sun.beans.editors.BoolEditor) {
|
||||
editor.m_View = new PropertyBoolSelector(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor instanceof sun.beans.editors.DoubleEditor) {
|
||||
editor.m_View = new PropertyText(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.isPaintable() && editor.m_Editor.supportsCustomEditor()) {
|
||||
editor.m_View = new PropertyPanel(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.getTags() != null ) {
|
||||
editor.m_View = new PropertyValueSelector(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.getAsText() != null) {
|
||||
editor.m_View = new PropertyText(editor.m_Editor);
|
||||
} else {
|
||||
System.out.println("Warning: Property \"" + editor.m_Name
|
||||
+ "\" has non-displayabale editor. Skipping.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/********************************* java.beans.PropertyChangeListener *************************/
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
/** This will wait for the GenericObjectEditor to finish
|
||||
* editing an object.
|
||||
* @param evt
|
||||
*/
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
Object newVal = evt.getNewValue();
|
||||
Object oldVal = evt.getOldValue();
|
||||
InterfaceOptimizationObjective[] list = this.m_OptimizationObjectivesWithWeights.getSelectedTargets();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (oldVal.equals(list[i])) {
|
||||
list[i] = (InterfaceOptimizationObjective)newVal;
|
||||
this.m_Editors[i].m_Name = list[i].getName();
|
||||
try {
|
||||
this.m_Editors[i].m_Value = list[i];
|
||||
this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(this.m_Editors[i].m_Value.getClass());
|
||||
if (this.m_Editors[i].m_Editor == null) this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(InterfaceOptimizationObjective.class);
|
||||
if (this.m_Editors[i].m_Editor instanceof GenericObjectEditor)
|
||||
((GenericObjectEditor) this.m_Editors[i].m_Editor).setClassType(InterfaceOptimizationObjective.class);
|
||||
this.m_Editors[i].m_Editor.setValue(this.m_Editors[i].m_Value);
|
||||
this.m_Editors[i].m_Editor.addPropertyChangeListener(this);
|
||||
this.findViewFor(this.m_Editors[i]);
|
||||
if (this.m_Editors[i].m_View != null) this.m_Editors[i].m_View.repaint();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Darn can't read the value...");
|
||||
}
|
||||
this.m_Targets[i] = this.m_Editors[i].m_View;
|
||||
}
|
||||
}
|
||||
//this.m_OptimizationTargets.setSelectedTargets(list);
|
||||
this.updateCenterComponent(evt); // Let our panel update before guys downstream
|
||||
m_Support.firePropertyChange("", m_OptimizationObjectivesWithWeights, m_OptimizationObjectivesWithWeights);
|
||||
}
|
||||
}
|
||||
537
src/javaeva/gui/GenericRemoteServersEditor.java
Normal file
537
src/javaeva/gui/GenericRemoteServersEditor.java
Normal file
@@ -0,0 +1,537 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javaeva.server.go.SwingWorker;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 14.12.2004
|
||||
* Time: 11:33:43
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
public class GenericRemoteServersEditor extends JPanel implements PropertyEditor {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The FilePath that is to be edited*/
|
||||
private PropertyRemoteServers m_RemoteServers;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JComponent m_Editor;
|
||||
private JPanel m_ParameterPanel;
|
||||
private JTextField m_Login;
|
||||
private JPasswordField m_Password;
|
||||
private JPanel m_ServerList;
|
||||
private JButton[] m_Status;
|
||||
private JTextField[] m_Names;
|
||||
private JComboBox[] m_CPUs;
|
||||
private JButton[] m_Delete;
|
||||
|
||||
public GenericRemoteServersEditor() {
|
||||
|
||||
}
|
||||
|
||||
/** This method will init the CustomEditor Panel
|
||||
*/
|
||||
private void initCustomEditor() {
|
||||
this.m_Editor = new JPanel();
|
||||
// This is the upper panel
|
||||
this.m_ParameterPanel = new JPanel();
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.weightx = 1;
|
||||
this.m_ParameterPanel.setLayout(new GridBagLayout());
|
||||
this.m_ParameterPanel.add(new JLabel("Login: "), gbc);
|
||||
this.m_Login = new JTextField(""+this.m_RemoteServers.getLogin());
|
||||
this.m_Login.addKeyListener(loginListener);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.gridwidth = 2;
|
||||
gbc.gridx = 1;
|
||||
gbc.gridy = 0;
|
||||
gbc.weightx = 100;
|
||||
this.m_ParameterPanel.add(this.m_Login, gbc);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridx = 3;
|
||||
gbc.gridy = 0;
|
||||
gbc.weightx = 1;
|
||||
this.m_ParameterPanel.add(new JLabel("Password: "), gbc);
|
||||
this.m_Password = new JPasswordField(""+this.m_RemoteServers.getPassword());
|
||||
this.m_Password.addKeyListener(passwordListener);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.gridwidth = 2;
|
||||
gbc.gridx = 4;
|
||||
gbc.gridy = 0;
|
||||
gbc.weightx = 100;
|
||||
this.m_ParameterPanel.add(this.m_Password, gbc);
|
||||
|
||||
JButton tmpB;
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes;
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Add24.gif");
|
||||
try {
|
||||
tmpB = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find Add24 icon, please move rescoure folder to working directory!");
|
||||
tmpB = new JButton("Add");
|
||||
}
|
||||
tmpB.addActionListener(addServer);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
gbc.weightx = 1;
|
||||
this.m_ParameterPanel.add(tmpB, gbc);
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Export24.gif");
|
||||
try {
|
||||
tmpB = new JButton("Load", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find Export24 icon, please move rescoure folder to working directory!");
|
||||
tmpB = new JButton("Load");
|
||||
}
|
||||
tmpB.addActionListener(loadServers);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.gridx = 1;
|
||||
gbc.gridy = 1;
|
||||
gbc.weightx = 1;
|
||||
this.m_ParameterPanel.add(tmpB, gbc);
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Import24.gif");
|
||||
try {
|
||||
tmpB = new JButton("Save", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find Import24 icon, please move rescoure folder to working directory!");
|
||||
tmpB = new JButton("Save");
|
||||
}
|
||||
tmpB.addActionListener(saveServers);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.gridx = 2;
|
||||
gbc.gridy = 1;
|
||||
gbc.weightx = 1;
|
||||
this.m_ParameterPanel.add(tmpB, gbc);
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Refresh24.gif");
|
||||
try {
|
||||
tmpB = new JButton("Update Status", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find Refresh24 icon, please move rescoure folder to working directory!");
|
||||
tmpB = new JButton("Update Status");
|
||||
}
|
||||
tmpB.addActionListener(updateServers);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.gridx = 3;
|
||||
gbc.gridy = 1;
|
||||
gbc.weightx = 1;
|
||||
this.m_ParameterPanel.add(tmpB, gbc);
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Play24.gif");
|
||||
try {
|
||||
tmpB = new JButton("Start Server", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find Play24 icon, please move rescoure folder to working directory!");
|
||||
tmpB = new JButton("Start Server");
|
||||
}
|
||||
tmpB.addActionListener(startServers);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.gridx = 4;
|
||||
gbc.gridy = 1;
|
||||
gbc.weightx = 1;
|
||||
this.m_ParameterPanel.add(tmpB, gbc);
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Stop24.gif");
|
||||
try {
|
||||
tmpB = new JButton("Stop Server", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find Stop24 icon, please move rescoure folder to working directory!");
|
||||
tmpB = new JButton("Stop Server");
|
||||
}
|
||||
tmpB.addActionListener(killServers);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.gridx = 5;
|
||||
gbc.gridy = 1;
|
||||
gbc.weightx = 1;
|
||||
this.m_ParameterPanel.add(tmpB, gbc);
|
||||
|
||||
this.m_ServerList = new JPanel();
|
||||
this.updateServerList();
|
||||
JScrollPane scrollServer = new JScrollPane(this.m_ServerList);
|
||||
|
||||
this.m_Editor.setLayout(new BorderLayout());
|
||||
this.m_Editor.add(this.m_ParameterPanel, BorderLayout.NORTH);
|
||||
this.m_Editor.add(scrollServer, BorderLayout.CENTER);
|
||||
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
/** This method updates the server list
|
||||
*
|
||||
*/
|
||||
private void updateServerList() {
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes;
|
||||
ServerNode t;
|
||||
this.m_ServerList.removeAll();
|
||||
this.m_ServerList.setLayout(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
this.m_Status = new JButton[this.m_RemoteServers.size()];
|
||||
this.m_Names = new JTextField[this.m_RemoteServers.size()];
|
||||
this.m_CPUs = new JComboBox[this.m_RemoteServers.size()];
|
||||
this.m_Delete = new JButton[this.m_RemoteServers.size()];
|
||||
String[] cups = new String[8];
|
||||
for (int i = 0; i < cups.length; i++) cups[i] = ""+(i+1);
|
||||
// The head title
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 1;
|
||||
this.m_ServerList.add(new JLabel("Status"), gbc);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 80;
|
||||
this.m_ServerList.add(new JLabel("Server Name"), gbc);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 2;
|
||||
gbc.weightx = 10;
|
||||
this.m_ServerList.add(new JLabel("CPUs"), gbc);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 3;
|
||||
gbc.weightx = 10;
|
||||
this.m_ServerList.add(new JLabel("Remove"), gbc);
|
||||
for (int i = 0; i < this.m_RemoteServers.size(); i++) {
|
||||
t = this.m_RemoteServers.get(i);
|
||||
// the status indicator
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 1;
|
||||
this.m_Status[i] = new JButton(" ");
|
||||
this.m_Status[i].setEnabled(false);
|
||||
if (this.m_RemoteServers.isServerOnline(t.m_ServerName)) this.m_Status[i].setBackground(Color.GREEN);
|
||||
else this.m_Status[i].setBackground(Color.RED);
|
||||
this.m_ServerList.add(this.m_Status[i], gbc);
|
||||
// the server name
|
||||
gbc = new GridBagConstraints();
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 80;
|
||||
this.m_Names[i] = new JTextField(""+t.m_ServerName);
|
||||
this.m_Names[i].addKeyListener(serverNameListener);
|
||||
this.m_ServerList.add(this.m_Names[i], gbc);
|
||||
// the number of CPUs
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 2;
|
||||
gbc.weightx = 10;
|
||||
this.m_CPUs[i] = new JComboBox(cups);
|
||||
this.m_CPUs[i].setSelectedIndex(t.m_CPUs-1);
|
||||
this.m_CPUs[i].addItemListener(cpuStateListener);
|
||||
this.m_ServerList.add(this.m_CPUs[i], gbc);
|
||||
// The delete button
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 3;
|
||||
gbc.weightx = 10;
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif");
|
||||
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
this.m_Delete[i].addActionListener(deleteServer);
|
||||
this.m_ServerList.add(this.m_Delete[i], gbc);
|
||||
}
|
||||
String[] h = this.m_RemoteServers.getCheckedServerNodes();
|
||||
System.out.println("My active nodes: ");
|
||||
for (int i = 0; i < h.length; i++) {
|
||||
System.out.println(""+h[i]);
|
||||
}
|
||||
this.m_ServerList.repaint();
|
||||
this.m_ServerList.validate();
|
||||
}
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener saveServers = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String text = m_RemoteServers.writeToText();
|
||||
JFileChooser saver = new JFileChooser();
|
||||
int option = saver.showSaveDialog(m_Editor);
|
||||
if (option == JFileChooser.APPROVE_OPTION) {
|
||||
// now save the stuff to the file
|
||||
File file = saver.getSelectedFile();
|
||||
try {
|
||||
BufferedWriter OutputFile = new BufferedWriter(new OutputStreamWriter (new FileOutputStream (file.getAbsolutePath())));
|
||||
OutputFile.write(text);
|
||||
OutputFile.close();
|
||||
} catch (FileNotFoundException t) {
|
||||
System.out.println("Could not open output file! Filename: " + file.getName());
|
||||
} catch (java.io.IOException t) {
|
||||
System.out.println("Could not write to output file! Filename: " + file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener killServers = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
m_RemoteServers.killServers();
|
||||
updateServerList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener startServers = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
m_RemoteServers.startServers();
|
||||
updateServerList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener updateServers = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
updateServerList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener addServer = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
m_RemoteServers.addServerNode("none", 1);
|
||||
updateServerList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener deleteServer = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
for (int i = 0; i < m_Delete.length; i++) {
|
||||
if (event.getSource().equals(m_Delete[i])) m_RemoteServers.removeServerNode(m_RemoteServers.get(i).m_ServerName);
|
||||
}
|
||||
updateServerList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener loadServers = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String text = "";
|
||||
JFileChooser reader = new JFileChooser();
|
||||
int option = reader.showOpenDialog(m_Editor);
|
||||
if (option == JFileChooser.APPROVE_OPTION) {
|
||||
// now save the stuff to the file
|
||||
File file = reader.getSelectedFile();
|
||||
try {
|
||||
BufferedReader inputFile = new BufferedReader(new FileReader(file.getAbsolutePath()));
|
||||
String line;
|
||||
while ((line = inputFile.readLine()) != null) {
|
||||
text += line +"\n";
|
||||
}
|
||||
inputFile.close();
|
||||
m_RemoteServers.readFromText(text);
|
||||
// text = inputFile.readLine().read();
|
||||
// OutputFile.close();
|
||||
} catch (FileNotFoundException t) {
|
||||
System.out.println("Could not open output file! Filename: " + file.getName());
|
||||
} catch (java.io.IOException t) {
|
||||
System.out.println("Could not write to output file! Filename: " + file.getName());
|
||||
}
|
||||
}
|
||||
updateServerList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener reads all values
|
||||
*/
|
||||
KeyListener loginListener = new KeyListener() {
|
||||
public void keyPressed(KeyEvent event) {
|
||||
}
|
||||
public void keyTyped(KeyEvent event) {
|
||||
}
|
||||
public void keyReleased(KeyEvent event) {
|
||||
m_RemoteServers.setLogin(m_Login.getText());
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener reads all values
|
||||
*/
|
||||
KeyListener passwordListener = new KeyListener() {
|
||||
public void keyPressed(KeyEvent event) {
|
||||
}
|
||||
public void keyTyped(KeyEvent event) {
|
||||
}
|
||||
public void keyReleased(KeyEvent event) {
|
||||
m_RemoteServers.setPassword(m_Password.getPassword());
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener reads all values
|
||||
*/
|
||||
KeyListener serverNameListener = new KeyListener() {
|
||||
public void keyPressed(KeyEvent event) {
|
||||
}
|
||||
public void keyTyped(KeyEvent event) {
|
||||
}
|
||||
public void keyReleased(KeyEvent event) {
|
||||
for (int i = 0; i < m_Names.length; i++) {
|
||||
if (event.getSource().equals(m_Names[i])) m_RemoteServers.setNameFor(i, m_Names[i].getText());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener adds an element to DoubleArray
|
||||
*/
|
||||
ItemListener cpuStateListener = new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent event) {
|
||||
for (int i = 0; i < m_CPUs.length; i++) {
|
||||
if (event.getSource().equals(m_CPUs[i])) m_RemoteServers.setCPUsFor(i, m_CPUs[i].getSelectedIndex()+1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** The object may have changed update the editor.
|
||||
*/
|
||||
private void updateEditor() {
|
||||
if (this.m_Editor != null) {
|
||||
this.m_Editor.validate();
|
||||
this.m_Editor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof PropertyRemoteServers) {
|
||||
this.m_RemoteServers = (PropertyRemoteServers) o;
|
||||
this.updateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_RemoteServers;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/** This is used to hook an action listener to the ok button
|
||||
* @param a The action listener.
|
||||
*/
|
||||
public void addOkListener(ActionListener a) {
|
||||
//m_OKButton.addActionListener(a);
|
||||
}
|
||||
|
||||
/** This is used to remove an action listener from the ok button
|
||||
* @param a The action listener
|
||||
*/
|
||||
public void removeOkListener(ActionListener a) {
|
||||
//m_OKButton.removeActionListener(a);
|
||||
}
|
||||
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = "Remote Servers";
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (this.m_Editor == null) this.initCustomEditor();
|
||||
return m_Editor;
|
||||
}
|
||||
}
|
||||
164
src/javaeva/gui/GenericStringListEditor.java
Normal file
164
src/javaeva/gui/GenericStringListEditor.java
Normal file
@@ -0,0 +1,164 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javaeva.server.go.individuals.codings.gp.AbstractGPNode;
|
||||
import javaeva.server.go.individuals.codings.gp.GPArea;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 23.03.2004
|
||||
* Time: 15:03:29
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class GenericStringListEditor implements PropertyEditor {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The GPArea that is to be edited*/
|
||||
private PropertyStringList m_List;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JPanel m_CustomEditor, m_NodePanel;
|
||||
private JCheckBox[] m_BlackCheck;
|
||||
|
||||
public GenericStringListEditor() {
|
||||
// compiled code
|
||||
}
|
||||
|
||||
/** This method will init the CustomEditor Panel
|
||||
*/
|
||||
private void initCustomEditor() {
|
||||
this.m_CustomEditor = new JPanel();
|
||||
this.m_CustomEditor.setPreferredSize(new Dimension(200, 200));
|
||||
this.m_CustomEditor.setLayout(new BorderLayout());
|
||||
this.m_CustomEditor.add(new JLabel("Select:"), BorderLayout.NORTH);
|
||||
this.m_NodePanel = new JPanel();
|
||||
this.m_CustomEditor.add(new JScrollPane(this.m_NodePanel), BorderLayout.CENTER);
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
/** The object may have changed update the editor.
|
||||
*/
|
||||
private void updateEditor() {
|
||||
if (this.m_NodePanel != null) {
|
||||
String[] strings = this.m_List.getStrings();
|
||||
boolean[] booleans = this.m_List.getSelection();
|
||||
this.m_NodePanel.removeAll();
|
||||
this.m_NodePanel.setLayout(new GridLayout(strings.length, 1));
|
||||
this.m_BlackCheck = new JCheckBox[strings.length];
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
this.m_BlackCheck[i] = new JCheckBox(strings[i], booleans[i]);
|
||||
this.m_BlackCheck[i].addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
makeNodeList();
|
||||
}
|
||||
});
|
||||
this.m_NodePanel.add(this.m_BlackCheck[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method checks the current BlackList and compiles it
|
||||
* to a new ReducedList.
|
||||
*/
|
||||
private void makeNodeList() {
|
||||
for (int i = 0; i < this.m_BlackCheck.length; i++) {
|
||||
this.m_List.setSelectionForElement(i, this.m_BlackCheck[i].isSelected());
|
||||
}
|
||||
}
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof PropertyStringList) {
|
||||
this.m_List = (PropertyStringList) o;
|
||||
this.updateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/** Retruns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_List;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = "Select from available Elements";
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (this.m_CustomEditor == null) this.initCustomEditor();
|
||||
return m_CustomEditor;
|
||||
}
|
||||
}
|
||||
270
src/javaeva/gui/GenericWeigthedLPTchebycheffEditor.java
Normal file
270
src/javaeva/gui/GenericWeigthedLPTchebycheffEditor.java
Normal file
@@ -0,0 +1,270 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 15.07.2005
|
||||
* Time: 10:32:43
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class GenericWeigthedLPTchebycheffEditor extends JPanel implements PropertyEditor {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The FilePath that is to be edited*/
|
||||
private PropertyWeightedLPTchebycheff m_WLPT;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JPanel m_CustomEditor, m_DataPanel, m_ButtonPanel, m_TargetPanel;
|
||||
private JTextField[] m_IdealTextField, m_WeightTextField;
|
||||
private JTextField m_PValue;
|
||||
private JButton m_OKButton;
|
||||
|
||||
public GenericWeigthedLPTchebycheffEditor() {
|
||||
// compiled code
|
||||
}
|
||||
|
||||
/** This method will init the CustomEditor Panel
|
||||
*/
|
||||
private void initCustomEditor() {
|
||||
this.m_CustomEditor = new JPanel();
|
||||
this.m_CustomEditor.setLayout(new BorderLayout());
|
||||
|
||||
// target panel
|
||||
this.m_TargetPanel = new JPanel();
|
||||
this.m_TargetPanel.setLayout(new GridLayout(1, 2));
|
||||
this.m_TargetPanel.add(new JLabel("Choose P:"));
|
||||
this.m_PValue = new JTextField(""+this.m_WLPT.m_P);
|
||||
this.m_TargetPanel.add(this.m_PValue);
|
||||
this.m_PValue.addKeyListener(this.readDoubleAction);
|
||||
this.m_CustomEditor.add(this.m_TargetPanel, BorderLayout.NORTH);
|
||||
|
||||
// init data panel
|
||||
this.m_DataPanel = new JPanel();
|
||||
this.updateDataPanel();
|
||||
this.m_CustomEditor.add(this.m_DataPanel, BorderLayout.CENTER);
|
||||
|
||||
// init button panel
|
||||
this.m_ButtonPanel = new JPanel();
|
||||
this.m_OKButton = new JButton("OK");
|
||||
this.m_OKButton.setEnabled(true);
|
||||
this.m_OKButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//m_Backup = copyObject(m_Object);
|
||||
if ((m_CustomEditor.getTopLevelAncestor() != null) && (m_CustomEditor.getTopLevelAncestor() instanceof Window)) {
|
||||
Window w = (Window) m_CustomEditor.getTopLevelAncestor();
|
||||
w.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.m_ButtonPanel.add(this.m_OKButton);
|
||||
this.m_CustomEditor.add(this.m_ButtonPanel, BorderLayout.SOUTH);
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
/** This action listener reads all values
|
||||
*/
|
||||
KeyListener readDoubleAction = new KeyListener() {
|
||||
public void keyPressed(KeyEvent event) {
|
||||
}
|
||||
public void keyTyped(KeyEvent event) {
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent event) {
|
||||
try {
|
||||
int d = new Integer(m_PValue.getText()).intValue();
|
||||
m_WLPT.m_P = d;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener reads all values
|
||||
*/
|
||||
KeyListener readDoubleArrayAction = new KeyListener() {
|
||||
public void keyPressed(KeyEvent event) {
|
||||
}
|
||||
public void keyTyped(KeyEvent event) {
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent event) {
|
||||
double[] tmpT = m_WLPT.m_IdealValue;
|
||||
double[] tmpP = m_WLPT.m_Weights;
|
||||
|
||||
for (int i = 0; i < tmpT.length; i++) {
|
||||
|
||||
try {
|
||||
double d = 0;
|
||||
d = new Double(m_IdealTextField[i].getText()).doubleValue();
|
||||
tmpT[i] = d;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
try {
|
||||
double d = 0;
|
||||
d = new Double(m_WeightTextField[i].getText()).doubleValue();
|
||||
tmpP[i] = d;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
m_WLPT.m_IdealValue = tmpT;
|
||||
m_WLPT.m_Weights = tmpP;
|
||||
}
|
||||
};
|
||||
|
||||
/** The object may have changed update the editor.
|
||||
*/
|
||||
private void updateEditor() {
|
||||
if (this.m_CustomEditor != null) {
|
||||
this.updateDataPanel();
|
||||
this.m_CustomEditor.validate();
|
||||
this.m_CustomEditor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/** This method updates the data panel
|
||||
*/
|
||||
private void updateDataPanel() {
|
||||
double[] tmpT = this.m_WLPT.m_IdealValue;
|
||||
double[] tmpP = this.m_WLPT.m_Weights;
|
||||
int obj = this.m_WLPT.m_P;
|
||||
|
||||
this.m_PValue.setText(""+obj);
|
||||
this.m_DataPanel.removeAll();
|
||||
this.m_DataPanel.setLayout(new GridLayout(tmpT.length+1, 3));
|
||||
this.m_DataPanel.add(new JLabel());
|
||||
this.m_DataPanel.add(new JLabel("Ideal Value"));
|
||||
this.m_DataPanel.add(new JLabel("Weights"));
|
||||
this.m_IdealTextField = new JTextField[tmpT.length];
|
||||
this.m_WeightTextField = new JTextField[tmpT.length];
|
||||
for (int i = 0; i < tmpT.length; i++) {
|
||||
JLabel label = new JLabel("Objective "+i+": ");
|
||||
this.m_DataPanel.add(label);
|
||||
this.m_IdealTextField[i] = new JTextField();
|
||||
this.m_IdealTextField[i].setText(""+tmpT[i]);
|
||||
this.m_IdealTextField[i].addKeyListener(this.readDoubleArrayAction);
|
||||
this.m_DataPanel.add(this.m_IdealTextField[i]);
|
||||
this.m_WeightTextField[i] = new JTextField();
|
||||
this.m_WeightTextField[i].setText(""+tmpP[i]);
|
||||
this.m_WeightTextField[i].addKeyListener(this.readDoubleArrayAction);
|
||||
this.m_DataPanel.add(this.m_WeightTextField[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof PropertyWeightedLPTchebycheff) {
|
||||
this.m_WLPT = (PropertyWeightedLPTchebycheff) o;
|
||||
this.updateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_WLPT;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/** This is used to hook an action listener to the ok button
|
||||
* @param a The action listener.
|
||||
*/
|
||||
public void addOkListener(ActionListener a) {
|
||||
m_OKButton.addActionListener(a);
|
||||
}
|
||||
|
||||
/** This is used to remove an action listener from the ok button
|
||||
* @param a The action listener
|
||||
*/
|
||||
public void removeOkListener(ActionListener a) {
|
||||
m_OKButton.removeActionListener(a);
|
||||
}
|
||||
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = "Edit the ideal vector, p and ev. the weights.";
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (this.m_CustomEditor == null) this.initCustomEditor();
|
||||
return m_CustomEditor;
|
||||
}
|
||||
}
|
||||
109
src/javaeva/gui/Graph.java
Normal file
109
src/javaeva/gui/Graph.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 322 $
|
||||
* $Date: 2007-12-11 17:24:07 +0100 (Tue, 11 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
public class Graph implements Serializable {
|
||||
private PlotInterface m_Plotter;
|
||||
private int m_GraphLabel;
|
||||
private String m_Info;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Graph(String Info, PlotInterface Plotter,int x) {
|
||||
m_Info = Info;
|
||||
m_Plotter = Plotter;
|
||||
m_GraphLabel = x;
|
||||
if (m_Plotter==null)
|
||||
System.out.println("In constructor m_Plotter == null");
|
||||
m_Plotter.setInfoString(m_GraphLabel,Info, (float) 1.0 );
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param Info
|
||||
* @param stroke
|
||||
*/
|
||||
public String getInfo() {return m_Info;}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setInfoString(String Info,float stroke) {
|
||||
m_Plotter.setInfoString(m_GraphLabel, Info,stroke);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int getGraphLabel () {
|
||||
return m_GraphLabel;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setConnectedPoint(double x,double y) {
|
||||
m_Plotter.setConnectedPoint(x,y,m_GraphLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void clear() {
|
||||
m_Plotter.clearGraph(m_GraphLabel);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setUnconnectedPoint(double x,double y) {
|
||||
m_Plotter.setUnconnectedPoint(x,y,m_GraphLabel);
|
||||
}
|
||||
|
||||
public int getPointCount() {
|
||||
return m_Plotter.getPointCount(m_GraphLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a graph to this graph object. Uses "force" for mismatching point counts, but returns false
|
||||
* if force was used and points possibly have been lost.
|
||||
*
|
||||
* @return true if the graph could be added direcly or false if the graph was added by force losing some data points
|
||||
* @see PlotInterface.addGraph
|
||||
*/
|
||||
public boolean addGraph(Graph x) {
|
||||
boolean useForce = false;
|
||||
//System.out.println("adding graph " + x.getGraphLabel() + " to " + getGraphLabel());
|
||||
if ((getPointCount() != 0) && (getPointCount() != x.getPointCount())) {
|
||||
//System.err.println("mismatching graphs, point counts were " + getPointCount() + " " + x.getPointCount());
|
||||
useForce = true;
|
||||
}
|
||||
m_Plotter.jump();
|
||||
m_Plotter.addGraph(m_GraphLabel, x.getGraphLabel(), useForce);
|
||||
return !useForce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the PlotInterface to interrupt the connected painting at the
|
||||
* current position.
|
||||
*/
|
||||
public void jump() {
|
||||
m_Plotter.jump();
|
||||
}
|
||||
|
||||
// public boolean isValid() { // this was evil in RMI, use GraphWindow instead
|
||||
// //return true;
|
||||
// return (m_Plotter != null) && (m_Plotter.getFunctionArea() != null);
|
||||
// }
|
||||
}
|
||||
579
src/javaeva/gui/GraphPointSet.java
Normal file
579
src/javaeva/gui/GraphPointSet.java
Normal file
@@ -0,0 +1,579 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 305 $
|
||||
* $Date: 2007-12-04 12:10:04 +0100 (Tue, 04 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import wsi.ra.chart2d.*;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.BasicStroke;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class GraphPointSet {
|
||||
private String m_InfoString = "InfoString";
|
||||
private int m_GraphLabel;
|
||||
private ArrayList m_PointSetContainer = new ArrayList();
|
||||
private float m_Stroke = (float) 1.0;
|
||||
private boolean m_isStatisticsGraph = false;
|
||||
// private DPointSet m_PointSet_1;
|
||||
// private DPointSet m_PointSet_2;
|
||||
// private DPointSet m_PointSet_3;
|
||||
private DPointSetMultiIcon m_ConnectedPointSet;
|
||||
private DArea m_Area;
|
||||
private Color m_Color;
|
||||
private DPointIcon m_Icon;
|
||||
private int m_CacheIndex = 0;
|
||||
private int m_CacheSize = 1;
|
||||
private double [] m_cachex;
|
||||
private double [] m_cachey;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public GraphPointSet (/*int size*/int GraphLabel, DArea Area) {
|
||||
//System.out.println("Constructor GraphPointSet "+ GraphLabel);
|
||||
m_cachex = new double[m_CacheSize];
|
||||
m_cachey = new double[m_CacheSize];
|
||||
m_Area = Area;
|
||||
m_GraphLabel = GraphLabel;
|
||||
m_ConnectedPointSet = new DPointSetMultiIcon(100);
|
||||
// m_PointSet_1 = new DPointSet(100);
|
||||
// m_PointSet_2 = new DPointSet(100);
|
||||
// m_PointSet_3 = new DPointSet(100);
|
||||
//
|
||||
// DPointIcon icon1 = new DPointIcon(){
|
||||
// public void paint( Graphics g ){
|
||||
// g.drawLine(-2, 0, 2, 0);
|
||||
// g.drawLine(0, 0, 0, 4);
|
||||
// }
|
||||
// public DBorder getDBorder(){ return new DBorder(4, 4, 4, 4); }
|
||||
// };
|
||||
// DPointIcon icon2 = new DPointIcon(){
|
||||
// public void paint( Graphics g ){
|
||||
// g.drawLine(-2, 0, 2, 0);
|
||||
// g.drawLine(0, 0, 0, -4);
|
||||
// }
|
||||
// public DBorder getDBorder(){ return new DBorder(4, 4, 4, 4); }
|
||||
// };
|
||||
//
|
||||
m_ConnectedPointSet.setStroke(new BasicStroke( m_Stroke ));
|
||||
m_ConnectedPointSet.setConnected(true);
|
||||
// m_Color = Color.black;
|
||||
// int colors = 5;
|
||||
// int b = GraphLabel*(int)(255/10)%255;
|
||||
// int r = (GraphLabel-colors)*(int)(255/10)%255;
|
||||
// int g = (GraphLabel-2*colors)*(int)(255/10)%255;
|
||||
// if (r<0) r = 0;
|
||||
// if (g<0) g = 0;
|
||||
// m_Color = new Color(r,g,b);
|
||||
|
||||
// if (GraphLabel == 0) m_Color = (Color.black);
|
||||
// else
|
||||
// if (GraphLabel == 1) m_Color = (Color.red);
|
||||
// else
|
||||
// if (GraphLabel == 2) m_Color = (Color.blue);
|
||||
// else
|
||||
// if (GraphLabel == 3) m_Color = (Color.red);
|
||||
// else
|
||||
// if (GraphLabel == 4) m_Color = (Color.black);
|
||||
// else
|
||||
// if (GraphLabel == 5) m_Color = (Color.red);
|
||||
// else
|
||||
// if (GraphLabel == 6) m_Color = (Color.blue);
|
||||
// else
|
||||
// if (GraphLabel == 7) m_Color = (Color.red);
|
||||
// else
|
||||
// if (GraphLabel == 8) m_Color = (Color.blue);
|
||||
// else
|
||||
// if (GraphLabel == 9) m_Color = (Color.red);
|
||||
// else
|
||||
// if (GraphLabel == 10) m_Color = (Color.black);
|
||||
|
||||
int k = GraphLabel%10;
|
||||
switch(k) {
|
||||
case 0: m_Color = Color.black; break;
|
||||
case 1: m_Color = Color.red; break;
|
||||
case 2: m_Color = Color.blue; break;
|
||||
case 3: m_Color = Color.pink; break;
|
||||
case 4: m_Color = Color.orange; break;
|
||||
case 5: m_Color = Color.gray; break;
|
||||
case 6: m_Color = Color.green; break;
|
||||
case 7: m_Color = Color.magenta; break;
|
||||
case 8: m_Color = Color.cyan; break;
|
||||
case 9: m_Color = Color.darkGray; break;
|
||||
}
|
||||
|
||||
m_ConnectedPointSet.setColor(m_Color);
|
||||
// m_PointSet_1.setColor(m_Color);
|
||||
// m_PointSet_2.setColor(m_Color);
|
||||
// m_PointSet_3.setColor(m_Color);
|
||||
initGraph(Area);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private GraphPointSet (int size,int GraphLabel) {
|
||||
m_GraphLabel = GraphLabel;
|
||||
m_cachex = new double[m_CacheSize];
|
||||
m_cachey = new double[m_CacheSize];
|
||||
m_ConnectedPointSet = new DPointSetMultiIcon(100);
|
||||
// m_PointSet_1 = new DPointSet(100);
|
||||
// m_PointSet_2 = new DPointSet(100);
|
||||
// m_PointSet_3 = new DPointSet(100);
|
||||
//
|
||||
// DPointIcon icon1 = new DPointIcon(){
|
||||
// public void paint( Graphics g ){
|
||||
// g.drawLine(-2, 0, 2, 0);
|
||||
// g.drawLine(0, 0, 0, 4);
|
||||
// }
|
||||
// public DBorder getDBorder(){ return new DBorder(4, 4, 4, 4); }
|
||||
// };
|
||||
// DPointIcon icon2 = new DPointIcon(){
|
||||
// public void paint( Graphics g ){
|
||||
// g.drawLine(-2, 0, 2, 0);
|
||||
// g.drawLine(0, 0, 0, -4);
|
||||
// }
|
||||
// public DBorder getDBorder(){ return new DBorder(4, 4, 4, 4); }
|
||||
// };
|
||||
// m_PointSet_2.setIcon(icon1);
|
||||
// m_PointSet_3.setIcon(icon1);
|
||||
//
|
||||
m_ConnectedPointSet.setStroke(new BasicStroke( m_Stroke ));
|
||||
|
||||
m_ConnectedPointSet.setConnected(true);
|
||||
m_Color = Color.black;
|
||||
// int colors = 5;
|
||||
// int b = GraphLabel*(int)(255/10)%255;
|
||||
// int r = (GraphLabel-colors)*(int)(255/10)%255;
|
||||
// int g = (GraphLabel-2*colors)*(int)(255/10)%255;
|
||||
// if (r<0) r = 0;
|
||||
// if (g<0) g = 0;
|
||||
// m_Color = new Color(r,g,b);
|
||||
|
||||
if (GraphLabel == 0) m_Color = (Color.black);
|
||||
else
|
||||
if (GraphLabel == 1) m_Color = (Color.red);
|
||||
else
|
||||
if (GraphLabel == 2) m_Color = (Color.blue);
|
||||
else
|
||||
if (GraphLabel == 3) m_Color = (Color.red);
|
||||
else
|
||||
if (GraphLabel == 4) m_Color = (Color.black);
|
||||
else
|
||||
if (GraphLabel == 5) m_Color = (Color.red);
|
||||
else
|
||||
if (GraphLabel == 6) m_Color = (Color.blue);
|
||||
else
|
||||
if (GraphLabel == 7) m_Color = (Color.red);
|
||||
else
|
||||
if (GraphLabel == 8) m_Color = (Color.blue);
|
||||
else
|
||||
if (GraphLabel == 9) m_Color = (Color.red);
|
||||
else
|
||||
if (GraphLabel == 10) m_Color = (Color.black);
|
||||
|
||||
m_ConnectedPointSet.setColor(m_Color);
|
||||
// m_PointSet_1.setColor(m_Color);
|
||||
// m_PointSet_2.setColor(m_Color);
|
||||
// m_PointSet_3.setColor(m_Color);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DPointSet printPoints() {
|
||||
for (int i = 0; i < m_ConnectedPointSet.getSize();i++) {
|
||||
DPoint p = m_ConnectedPointSet.getDPoint(i);
|
||||
double x = p.x;
|
||||
double y = p.y;
|
||||
//System.out.println("point "+i+ " x= "+x+"y= "+y);
|
||||
}
|
||||
return m_ConnectedPointSet.getDPointSet();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Color getColor() {
|
||||
return m_ConnectedPointSet.getColor();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setColor(Color x) {
|
||||
m_ConnectedPointSet.setColor(x);
|
||||
// m_PointSet_1.setColor(x);
|
||||
// m_PointSet_2.setColor(x);
|
||||
// m_PointSet_3.setColor(x);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DPointSet getConnectedPointSet() {
|
||||
return m_ConnectedPointSet.getDPointSet();
|
||||
}
|
||||
public DPointSetMultiIcon getReference2ConnectedPointSet() {
|
||||
return m_ConnectedPointSet;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void initGraph (DArea Area) {
|
||||
m_Area = Area;
|
||||
m_Area.addDElement(m_ConnectedPointSet);
|
||||
((FunctionArea)m_Area).addGraphPointSet(this);
|
||||
// m_Area.addDElement(m_PointSet_1);
|
||||
// m_Area.addDElement(m_PointSet_2);
|
||||
// m_Area.addDElement(m_PointSet_3);
|
||||
// DPointIcon icon1 = new DPointIcon(){
|
||||
// public void paint( Graphics g ){
|
||||
// g.drawLine(-2, 0, 2, 0);
|
||||
// g.drawLine(0, 0, 0, 4);
|
||||
// }
|
||||
// public DBorder getDBorder(){ return new DBorder(4, 4, 4, 4); }
|
||||
// };
|
||||
// DPointIcon icon2 = new DPointIcon(){
|
||||
// public void paint( Graphics g ){
|
||||
// g.drawLine(-2, 0, 2, 0);
|
||||
// g.drawLine(0, 0, 0, -4);
|
||||
// }
|
||||
// public DBorder getDBorder(){ return new DBorder(4, 4, 4, 4); }
|
||||
// };
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DPoint getNearestDPoint(DPoint p) {
|
||||
return m_ConnectedPointSet.getNearestDPoint(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the PointSet to interupt the connected painting at the
|
||||
* current position.
|
||||
*/
|
||||
public void jump() {
|
||||
m_ConnectedPointSet.jump();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removeAllPoints() {
|
||||
m_ConnectedPointSet.removeAllPoints();
|
||||
// m_PointSet_1.removeAllPoints();
|
||||
// m_PointSet_2.removeAllPoints();
|
||||
// m_PointSet_3.removeAllPoints();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addDPoint(double x,double y) {
|
||||
//System.out.println(" "+x+" "+y);
|
||||
if (m_CacheIndex==m_CacheSize) {
|
||||
for (int i=0;i<m_CacheSize;i++) {
|
||||
m_ConnectedPointSet.addDPoint(m_cachex[i],m_cachey[i]);
|
||||
}
|
||||
m_ConnectedPointSet.addDPoint(x,y);
|
||||
m_CacheIndex=0;
|
||||
}
|
||||
else {
|
||||
m_cachex[m_CacheIndex]=x;
|
||||
m_cachey[m_CacheIndex]=y;
|
||||
m_CacheIndex++;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addDPoint(DPoint p) {
|
||||
m_ConnectedPointSet.addDPoint(p);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setIcon(DPointIcon p) {
|
||||
this.m_Icon = p;
|
||||
this.m_ConnectedPointSet.setIcon(p);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setConnectedMode(boolean p) {
|
||||
m_ConnectedPointSet.setConnected(p);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean isStatisticsGraph() {
|
||||
return m_isStatisticsGraph;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int getPointCount() {
|
||||
return m_ConnectedPointSet.getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PointSet getPointSet() {
|
||||
return new PointSet (this.m_ConnectedPointSet.getDPointSet());
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePoint(DPoint x) {
|
||||
System.out.println("removePoint "+x.x+ " "+ x.y);
|
||||
DPoint[] buf = new DPoint[m_ConnectedPointSet.getSize()];
|
||||
for (int i=0; i<m_ConnectedPointSet.getSize();i++) {
|
||||
buf[i] = m_ConnectedPointSet.getDPoint(i);
|
||||
}
|
||||
m_ConnectedPointSet.removeAllPoints();
|
||||
for (int i=0; i<buf.length;i++) {
|
||||
if(buf[i].x == x.x && buf[i].y == x.y)
|
||||
System.out.println("point found");
|
||||
else
|
||||
m_ConnectedPointSet.addDPoint(buf[i]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a graph to another one forming a statistics graph if it isnt one already.
|
||||
*
|
||||
* @param set
|
||||
* @param measures
|
||||
* @param useForce forces the add even if point counts mismatch, maybe losing some data points
|
||||
*/
|
||||
public void addGraph (GraphPointSet set,DMeasures measures, boolean useForce) {
|
||||
if (set.m_ConnectedPointSet.getSize()!=m_ConnectedPointSet.getSize() &&
|
||||
m_ConnectedPointSet.getSize()!=0 && !useForce) {
|
||||
System.err.println("WARNING addGraph not possible, lost last graph");
|
||||
System.err.println(" m_ConnectedPointSet.getSize() "+ m_ConnectedPointSet.getSize());
|
||||
return;
|
||||
}
|
||||
m_isStatisticsGraph = true;
|
||||
removeAllPoints();
|
||||
m_ConnectedPointSet.setColor(set.getColor());
|
||||
// m_PointSet_1.setColor(m_ConnectedPointSet.getColor());
|
||||
// m_PointSet_2.setColor(m_ConnectedPointSet.getColor());
|
||||
// m_PointSet_3.setColor(m_ConnectedPointSet.getColor());
|
||||
m_PointSetContainer.add(set.getPointSet());
|
||||
int[] index = new int[m_PointSetContainer.size()];
|
||||
int[] GraphSize = new int[m_PointSetContainer.size()];
|
||||
for (int i=0;i<m_PointSetContainer.size();i++)
|
||||
GraphSize[i] = ((PointSet) m_PointSetContainer.get(i)).getSize();
|
||||
boolean doit = true;
|
||||
double minx =0;
|
||||
while ( doit ) {
|
||||
minx = ((PointSet) m_PointSetContainer.get(0)).m_X[index[0]];
|
||||
int minindex = 0;
|
||||
//System.out.println("m_PointSetContainer.size()"+m_PointSetContainer.size());
|
||||
for (int i = 1;i<m_PointSetContainer.size();i++) {
|
||||
//System.out.println("i="+i);
|
||||
if (minx > ((PointSet) m_PointSetContainer.get(i)).m_X[index[i]]) {
|
||||
minindex = i;
|
||||
minx = ((PointSet) m_PointSetContainer.get(i)).m_X[index[i]];
|
||||
}
|
||||
}
|
||||
// Stelle minx wird gezeichnet. jetzt alle y werte dazu finden
|
||||
int numberofpoints =0;
|
||||
for (int i = 0;i<m_PointSetContainer.size();i++) {
|
||||
if (minx == ((PointSet) m_PointSetContainer.get(i)).m_X[index[i]])
|
||||
numberofpoints++;
|
||||
}
|
||||
double[] y = new double[numberofpoints];
|
||||
int c = 0;
|
||||
for (int i = 0;i<m_PointSetContainer.size();i++) {
|
||||
if (minx == ((PointSet) m_PointSetContainer.get(i)).m_X[index[i]]) {
|
||||
y[c]= ((PointSet) m_PointSetContainer.get(i)).m_Y[index[i]];
|
||||
c++;
|
||||
index[i]++;
|
||||
}
|
||||
}
|
||||
double ymean =0;
|
||||
for (int i = 0;i<y.length;i++)
|
||||
ymean = ymean + y[i];
|
||||
ymean = ymean / y.length;
|
||||
// compute median double median = getMedian(y);
|
||||
addDPoint(minx,ymean);// System.out.println("ymean "+ymean+" y.length "+ y.length);
|
||||
//addDPoint(minx,median);// System.out.println("ymean "+ymean+" y.length "+ y.length);
|
||||
doit = true;
|
||||
for (int i=0;i<m_PointSetContainer.size();i++) {
|
||||
if (GraphSize[i] <= index[i] ) {
|
||||
doit = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// doit = false;
|
||||
// for (int i=0;i<m_PointSetContainer.size();i++) {
|
||||
// if (GraphSize[i] > index[i] ) {
|
||||
// doit = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// m_PointSet_2.removeAllPoints();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private double getMedian(double[] in) {
|
||||
double[] x = (double[]) in.clone();
|
||||
double ret = 0;
|
||||
Arrays.sort(x);
|
||||
int m = (int)( x.length/2.0);
|
||||
return x[m];
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int getGraphLabel () {
|
||||
return m_GraphLabel;
|
||||
}
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// public void setUnconnectedPoint (double x, double y) {
|
||||
// m_PointSet_1.addDPoint(x,y);
|
||||
// }
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getInfoString () {
|
||||
return m_InfoString;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setInfoString (String x, float stroke ) {
|
||||
m_InfoString=x;
|
||||
m_Stroke = stroke;
|
||||
//setStroke(new BasicStroke( m_Stroke ));
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public SerPointSet getSerPointSet () {
|
||||
SerPointSet ret= new SerPointSet(this);
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class SerPointSet implements Serializable {
|
||||
private String m_InfoString;
|
||||
private int m_GraphLabel;
|
||||
private Color m_Color;
|
||||
private float m_Stroke;
|
||||
private PointSet m_PointSet_1;
|
||||
private PointSet m_PointSet_2;
|
||||
private PointSet m_PointSet_3;
|
||||
private PointSet m_ConnectedPointSet;
|
||||
private PointSet m_VarPointSetPlus;
|
||||
private PointSet m_VarPointSetMinus;
|
||||
private boolean m_isStatisticeGraph;
|
||||
private boolean m_showVarianz;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public SerPointSet (GraphPointSet Source) {
|
||||
m_InfoString = Source.m_InfoString;
|
||||
m_GraphLabel = Source.m_GraphLabel;
|
||||
m_Color = Source.m_Color;
|
||||
m_Stroke = Source.m_Stroke;
|
||||
m_isStatisticeGraph = Source.m_isStatisticsGraph;
|
||||
|
||||
// save the connected points
|
||||
m_ConnectedPointSet = new PointSet(Source.getConnectedPointSet());
|
||||
// m_PointSet_1 = new PointSet (Source.m_PointSet_1);
|
||||
// m_PointSet_2 = new PointSet (Source.m_PointSet_2);
|
||||
// m_PointSet_3 = new PointSet (Source.m_PointSet_3);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public GraphPointSet getGraphPointSet () {
|
||||
GraphPointSet ret = new GraphPointSet(10,m_GraphLabel);
|
||||
ret.setInfoString(this.m_InfoString,this.m_Stroke);
|
||||
ret.setColor(this.m_Color);
|
||||
ret.m_Color = m_Color;
|
||||
ret.m_Stroke = m_Stroke;
|
||||
ret.m_isStatisticsGraph = m_isStatisticeGraph;
|
||||
//@todo why doesn't that work!?
|
||||
// ret.m_ConnectedPointSet = (DPointSetMultiIcon)m_ConnectedPointSet;
|
||||
// ret.m_PointSet_1 = m_PointSet_1.getDPointSet();
|
||||
// ret.m_PointSet_2 = m_PointSet_2.getDPointSet();
|
||||
// ret.m_PointSet_3 = m_PointSet_3.getDPointSet();
|
||||
ret.m_ConnectedPointSet.setConnected(true);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class PointSet implements Serializable {
|
||||
private double[] m_X;
|
||||
private double[] m_Y;
|
||||
private Color m_Color;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PointSet (DPointSet pointset) {
|
||||
m_Color = pointset.getColor();
|
||||
m_X = new double[pointset.getSize()];
|
||||
m_Y = new double[pointset.getSize()];
|
||||
for (int i=0;i<pointset.getSize();i++) {
|
||||
DPoint point = pointset.getDPoint(i);
|
||||
m_X[i] = point.x;
|
||||
m_Y[i] = point.y;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DPointSet getDPointSet () {
|
||||
DPointSet ret = new DPointSet(100);
|
||||
ret.setColor(m_Color);
|
||||
for (int i=0;i<m_X.length;i++)
|
||||
ret.addDPoint(m_X[i],m_Y[i]);
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int getSize() {
|
||||
return m_X.length;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DPointSet printPoints() {
|
||||
for (int i = 0; i < m_ConnectedPointSet.getSize();i++) {
|
||||
DPoint p = m_ConnectedPointSet.getDPoint(i);
|
||||
double x = p.x;
|
||||
double y = p.y;
|
||||
//System.out.println("point "+i+ " x= "+x+"y= "+y);
|
||||
}
|
||||
return m_ConnectedPointSet.getDPointSet();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
158
src/javaeva/gui/GraphWindow.java
Normal file
158
src/javaeva/gui/GraphWindow.java
Normal file
@@ -0,0 +1,158 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 320 $
|
||||
* $Date: 2007-12-06 16:05:11 +0100 (Thu, 06 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wsi.ra.jproxy.MainAdapterClient;
|
||||
import wsi.ra.jproxy.RMIProxyRemote;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
* It represents one plot window in the client GUI.
|
||||
*/
|
||||
public class GraphWindow {
|
||||
public static boolean TRACE = false;
|
||||
|
||||
static private int m_GraphCounter = -1;
|
||||
static private PlotContainer m_PlotContainer;
|
||||
private MainAdapterClient m_MainAdapterClient;
|
||||
private PlotInterface m_Plotter;
|
||||
private String m_Name;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static GraphWindow getInstance (MainAdapterClient client,String GraphWindowName,
|
||||
String strx,String stry) {
|
||||
if (m_PlotContainer == null)
|
||||
m_PlotContainer = new PlotContainer();
|
||||
GraphWindow ret =null;
|
||||
try {
|
||||
// if (!m_PlotContainer.containsName(GraphWindowName)) {
|
||||
// ret = new GraphWindow(client,GraphWindowName,strx,stry);
|
||||
// m_PlotContainer.add(ret);
|
||||
// }
|
||||
// else {
|
||||
// ret = m_PlotContainer.getPlot(GraphWindowName);
|
||||
// }
|
||||
if (m_PlotContainer.containsName(GraphWindowName)) {
|
||||
ret = m_PlotContainer.getPlot(GraphWindowName);
|
||||
}
|
||||
if ((ret == null) || !(ret.isValid())) {
|
||||
if (ret != null) {
|
||||
m_PlotContainer.remove(ret); // remove if not valid any more
|
||||
}
|
||||
ret = new GraphWindow(client,GraphWindowName,strx,stry);
|
||||
m_PlotContainer.add(ret);
|
||||
}
|
||||
} catch (Exception ee) {
|
||||
System.out.println("GraphWindow ERROR : "+ee.getMessage());
|
||||
ee.printStackTrace();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return (m_Plotter != null) && (m_Plotter.isValid());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private GraphWindow(MainAdapterClient client,String PlotName,String strx,String stry){
|
||||
if (TRACE) System.out.println("Constructor GraphWindow");
|
||||
m_MainAdapterClient = client;
|
||||
m_Name = PlotName;
|
||||
try {
|
||||
if ((client==null) || client.getHostName().equals(InetAddress.getLocalHost().getHostName())) {
|
||||
if (TRACE) System.out.println("no RMI");
|
||||
m_Plotter = new Plot(PlotName,strx,stry);
|
||||
}
|
||||
else {
|
||||
m_Plotter = (PlotInterface) RMIProxyRemote.newInstance(new Plot(PlotName,strx,stry,false), m_MainAdapterClient);
|
||||
m_Plotter.init();
|
||||
if (TRACE) System.out.println("with RMI");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("InetAddress.getLocalHost().getHostAddress() --> ERROR" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getName () {
|
||||
return m_Name;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Graph getNewGraph(String InfoString) {
|
||||
m_GraphCounter++;
|
||||
if (TRACE) System.out.println("Graph.getNewGraph No:"+m_GraphCounter);
|
||||
return new Graph (InfoString,m_Plotter,m_GraphCounter);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class PlotContainer extends ArrayList<GraphWindow> {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 4194675772084989958L;
|
||||
private GraphWindow m_actualPlot;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PlotContainer() {}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean containsName (String name) {
|
||||
GraphWindow temp = null;
|
||||
for (int i=0;i<size();i++) {
|
||||
temp = (GraphWindow)(get(i));
|
||||
if (name.equals(temp.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void remove(GraphWindow gw) {
|
||||
super.remove(gw);
|
||||
if (m_actualPlot == gw) m_actualPlot=null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public GraphWindow getPlot (String name) {
|
||||
if ((m_actualPlot!=null) && m_actualPlot.isValid()) {
|
||||
if (m_actualPlot.getName().equals(name))
|
||||
return m_actualPlot;
|
||||
}
|
||||
GraphWindow temp = null;
|
||||
for (int i=0;i<size();i++) {
|
||||
temp = (GraphWindow)(get(i));
|
||||
if (name.equals(temp.getName())) {
|
||||
m_actualPlot = temp;
|
||||
return m_actualPlot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
132
src/javaeva/gui/HtmlDemo.java
Normal file
132
src/javaeva/gui/HtmlDemo.java
Normal file
@@ -0,0 +1,132 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 199 $
|
||||
* $Date: 2007-10-23 16:58:12 +0200 (Tue, 23 Oct 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javaeva.tools.EVAHELP;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JViewport;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.text.html.HTMLFrameHyperlinkEvent;
|
||||
import javax.swing.text.html.HTMLDocument;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.BorderLayout;
|
||||
import java.io.IOException;
|
||||
import java.applet.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.awt.Toolkit;
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
import javaeva.client.EvAClient;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class HtmlDemo {
|
||||
private JEditorPane m_html;
|
||||
private String m_name;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public HtmlDemo(String name) {
|
||||
m_name = name;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JEditorPane getPane() {
|
||||
return m_html;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
HtmlDemo demo = new HtmlDemo("ES.html");
|
||||
demo.show();
|
||||
}
|
||||
|
||||
public boolean resourceExists() {
|
||||
URL url = ClassLoader.getSystemResource("resources/"+m_name);
|
||||
return (url != null);
|
||||
}
|
||||
|
||||
public static boolean resourceExists(String mname) {
|
||||
URL url = ClassLoader.getSystemResource("resources/"+mname);
|
||||
return (url != null);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void show() {
|
||||
try {
|
||||
URL url = null;
|
||||
url = this.getClass().getClassLoader().getSystemResource("resources/"+m_name);
|
||||
|
||||
try {
|
||||
m_html = new JEditorPane(url);
|
||||
} catch (java.io.IOException ioe) {
|
||||
url = this.getClass().getClassLoader().getSystemResource("resources/Default.html");
|
||||
m_html = new JEditorPane(url);
|
||||
}
|
||||
//m_html = new JEditorPane(htmlDescription);
|
||||
m_html.setEditable(false);
|
||||
m_html.addHyperlinkListener(createHyperLinkListener());
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
System.out.println("Malformed URL: " + e);
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
System.out.println("IOException: " + e);
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
JFrame frame = new JFrame (m_name);
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAClient.iconLocation);
|
||||
try {
|
||||
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find JavaEvA icon, please move rescoure folder to working directory!");
|
||||
}
|
||||
JScrollPane scroller = new JScrollPane();
|
||||
JViewport vp = scroller.getViewport();
|
||||
vp.add(m_html);
|
||||
scroller.setPreferredSize( new Dimension(600,500) );
|
||||
frame.getContentPane().add(scroller, BorderLayout.CENTER);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public HyperlinkListener createHyperLinkListener() {
|
||||
return new HyperlinkListener() {
|
||||
public void hyperlinkUpdate(HyperlinkEvent e) {
|
||||
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
||||
if (e instanceof HTMLFrameHyperlinkEvent) {
|
||||
((HTMLDocument)m_html.getDocument()).processHTMLFrameHyperlinkEvent(
|
||||
(HTMLFrameHyperlinkEvent)e);
|
||||
} else {
|
||||
try {
|
||||
m_html.setPage(e.getURL());
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("IOE: " + ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
26
src/javaeva/gui/InterfaceDPointWithContent.java
Normal file
26
src/javaeva/gui/InterfaceDPointWithContent.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 08.09.2005
|
||||
* Time: 10:16:18
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public interface InterfaceDPointWithContent {
|
||||
public void setEAIndividual(AbstractEAIndividual indy);
|
||||
public AbstractEAIndividual getEAIndividual();
|
||||
|
||||
/** This method allows you to set the according optimization problem
|
||||
* @param problem InterfaceOptimizationProblem
|
||||
*/
|
||||
public void setProblem(InterfaceOptimizationProblem problem);
|
||||
public InterfaceOptimizationProblem getProblem();
|
||||
|
||||
/** This method allows you to draw additional data of the individual
|
||||
*/
|
||||
public void showIndividual();
|
||||
}
|
||||
40
src/javaeva/gui/InterfaceSelectablePointIcon.java
Normal file
40
src/javaeva/gui/InterfaceSelectablePointIcon.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.mocco.paretofrontviewer.InterfaceRefSolutionListener;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 25.08.2005
|
||||
* Time: 17:16:33
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public interface InterfaceSelectablePointIcon {
|
||||
|
||||
/** This method allows to add a selection listner to the PointIcon
|
||||
* it should need more than one listener to this abstruse event
|
||||
* @param a The selection listener
|
||||
*/
|
||||
public void addSelectionListener(InterfaceRefSolutionListener a);
|
||||
|
||||
/** This method allows to remove the selection listner to the PointIcon
|
||||
*/
|
||||
public void removeSelectionListeners();
|
||||
|
||||
/** This method returns the selection listner to the PointIcon
|
||||
* @return InterfacePointIconSelectionListener
|
||||
*/
|
||||
public InterfaceRefSolutionListener getSelectionListener();
|
||||
|
||||
/** Of course the PointIcon needs a reference to the individual
|
||||
* otherwise it can't tell the listener what has been selected.
|
||||
* @param indy
|
||||
*/
|
||||
public void setEAIndividual(AbstractEAIndividual indy);
|
||||
|
||||
/** This method allows you to get the EAIndividual the icon stands for
|
||||
* @return AbstractEAIndividual
|
||||
*/
|
||||
public AbstractEAIndividual getEAIndividual();
|
||||
}
|
||||
491
src/javaeva/gui/JClassTree.java
Normal file
491
src/javaeva/gui/JClassTree.java
Normal file
@@ -0,0 +1,491 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 201 $
|
||||
* $Date: 2007-10-25 16:11:23 +0200 (Thu, 25 Oct 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JClassTree extends JDialog {
|
||||
// private ESPara m_Para;
|
||||
JScrollPane jScrollPane1 = new JScrollPane();
|
||||
JTree treeView_ = new JTree();
|
||||
JPanel treeControlsPanel = new JPanel();
|
||||
JButton expandButton = new JButton();
|
||||
JButton collapseButton = new JButton();
|
||||
JButton editButton = new JButton();
|
||||
JButton cancelButton = new JButton();
|
||||
// Used for addNotify check.
|
||||
private boolean fComponentsAdjusted = false;
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public JClassTree() {
|
||||
getContentPane().setLayout(new BorderLayout(0, 0));
|
||||
setVisible(false);
|
||||
setSize(405, 362);
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
jScrollPane1.setOpaque(true);
|
||||
getContentPane().add(BorderLayout.CENTER, jScrollPane1);
|
||||
treeView_ = new JTree();
|
||||
treeView_.setBounds(0, 0, 402, 324);
|
||||
treeView_.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||
treeView_.setBackground(java.awt.Color.white);
|
||||
jScrollPane1.getViewport().add(treeView_);
|
||||
treeControlsPanel = new javax.swing.JPanel();
|
||||
treeControlsPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
||||
treeControlsPanel.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||
treeControlsPanel.setForeground(java.awt.Color.black);
|
||||
treeControlsPanel.setBackground(new java.awt.Color(204, 204, 204));
|
||||
getContentPane().add(BorderLayout.SOUTH, treeControlsPanel);
|
||||
expandButton = new javax.swing.JButton();
|
||||
expandButton.setText("Expand All");
|
||||
expandButton.setActionCommand("Expand All");
|
||||
expandButton.setFont(new Font("Dialog", Font.BOLD, 12));
|
||||
expandButton.setBackground(new java.awt.Color(204, 204, 204));
|
||||
treeControlsPanel.add(expandButton);
|
||||
collapseButton = new javax.swing.JButton();
|
||||
collapseButton.setText("Collapse All");
|
||||
collapseButton.setActionCommand("Collapse All");
|
||||
collapseButton.setFont(new Font("Dialog", Font.BOLD, 12));
|
||||
collapseButton.setBackground(new java.awt.Color(204, 204, 204));
|
||||
treeControlsPanel.add(collapseButton);
|
||||
editButton = new javax.swing.JButton();
|
||||
editButton.setText("Edit Selected");
|
||||
editButton.setActionCommand("Edit Selected");
|
||||
editButton.setFont(new Font("Dialog", Font.BOLD, 12));
|
||||
editButton.setBackground(new java.awt.Color(204, 204, 204));
|
||||
treeControlsPanel.add(editButton);
|
||||
cancelButton = new javax.swing.JButton();
|
||||
cancelButton.setText("Close");
|
||||
cancelButton.setActionCommand("Close");
|
||||
cancelButton.setFont(new Font("Dialog", Font.BOLD, 12));
|
||||
cancelButton.setBackground(new java.awt.Color(204, 204, 204));
|
||||
treeControlsPanel.add(cancelButton);
|
||||
setTitle("Class View");
|
||||
|
||||
SymWindow aSymWindow = new SymWindow();
|
||||
this.addWindowListener(aSymWindow);
|
||||
SymAction lSymAction = new SymAction();
|
||||
expandButton.addActionListener(lSymAction);
|
||||
collapseButton.addActionListener(lSymAction);
|
||||
editButton.addActionListener(lSymAction);
|
||||
cancelButton.addActionListener(lSymAction);
|
||||
|
||||
MouseListener ml =
|
||||
new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int selRow = treeView_.getRowForLocation(e.getX(), e.getY());
|
||||
TreePath selPath = treeView_.getPathForLocation(e.getX(), e.getY());
|
||||
if (selRow != -1) {
|
||||
if ((e.getClickCount() == 2) ||
|
||||
((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0)) {
|
||||
doubleClick(selRow, selPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
treeView_.addMouseListener(ml);
|
||||
//
|
||||
Insets inset = new Insets(0, 5, 0, 5);
|
||||
expandButton.setMargin(inset);
|
||||
collapseButton.setMargin(inset);
|
||||
editButton.setMargin(inset);
|
||||
cancelButton.setMargin(inset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
*@param selRow Description of the Parameter
|
||||
*@param selPath Description of the Parameter
|
||||
*/
|
||||
void doubleClick(int selRow, TreePath selPath) {
|
||||
System.out.println("row " + selRow + " selected");
|
||||
Object[] objs = selPath.getPath();
|
||||
Object thing = ((DefaultMutableTreeNode) objs[objs.length - 1]).getUserObject();
|
||||
showProperties(thing);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for the JClassTree object
|
||||
*
|
||||
*@param sTitle Description of the Parameter
|
||||
*/
|
||||
public JClassTree(String sTitle) {
|
||||
this();
|
||||
setTitle(sTitle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make the dialog visible.
|
||||
*
|
||||
*@param b The new visible value
|
||||
*/
|
||||
public void setVisible(boolean b) {
|
||||
if (b) {
|
||||
setLocation(50, 50);
|
||||
}
|
||||
super.setVisible(b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds a feature to the Notify attribute of the JClassTree object
|
||||
*/
|
||||
public void addNotify() {
|
||||
// Record the size of the window prior to calling parents addNotify.
|
||||
Dimension d = getSize();
|
||||
Insets in = getInsets();
|
||||
|
||||
super.addNotify();
|
||||
|
||||
if (fComponentsAdjusted) {
|
||||
return;
|
||||
}
|
||||
// Adjust components according to the insets
|
||||
setSize(in.left + in.right + d.width, in.top + in.bottom + d.height);
|
||||
Component components[] = getContentPane().getComponents();
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
Point p = components[i].getLocation();
|
||||
p.translate(in.left, in.top);
|
||||
components[i].setLocation(p);
|
||||
}
|
||||
fComponentsAdjusted = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The main program for the JClassTree class
|
||||
*
|
||||
*@param args The command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
JClassTree Main = new JClassTree();
|
||||
Main.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description of the Class
|
||||
*
|
||||
*@author ulmerh
|
||||
*@created 20. Januar 2003
|
||||
*/
|
||||
class SymWindow extends WindowAdapter {
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
*@param event Description of the Parameter
|
||||
*/
|
||||
public void windowClosing(java.awt.event.WindowEvent event) {
|
||||
Object object = event.getSource();
|
||||
if (object == JClassTree.this) {
|
||||
JClassTree_WindowClosing(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
*@param event Description of the Parameter
|
||||
*/
|
||||
void JClassTree_WindowClosing(WindowEvent event) {
|
||||
setVisible(false);
|
||||
// hide the Frame
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description of the Class
|
||||
*
|
||||
*@author ulmerh
|
||||
*@created 20. Januar 2003
|
||||
*/
|
||||
class SymAction implements ActionListener {
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
*@param event Description of the Parameter
|
||||
*/
|
||||
public void actionPerformed(java.awt.event.ActionEvent event) {
|
||||
Object object = event.getSource();
|
||||
if (object == expandButton) {
|
||||
expandButton_actionPerformed(event);
|
||||
} else if (object == collapseButton) {
|
||||
collapseButton_actionPerformed(event);
|
||||
} else if (object == editButton) {
|
||||
editButton_actionPerformed(event);
|
||||
} else if (object == cancelButton) {
|
||||
cancelButton_actionPerformed(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
*@param event Description of the Parameter
|
||||
*/
|
||||
void expandButton_actionPerformed(java.awt.event.ActionEvent event) {
|
||||
expandTree();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expand the tree to show all nodes.
|
||||
*/
|
||||
public void expandTree() {
|
||||
int row = 0;
|
||||
while (row < treeView_.getRowCount()) {
|
||||
if (treeView_.isCollapsed(row)) {
|
||||
treeView_.expandRow(row);
|
||||
}
|
||||
row++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
*@param event Description of the Parameter
|
||||
*/
|
||||
void collapseButton_actionPerformed(java.awt.event.ActionEvent event) {
|
||||
treeView_.collapseRow(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
*@param event Description of the Parameter
|
||||
*/
|
||||
void editButton_actionPerformed(java.awt.event.ActionEvent event) {
|
||||
Object[] objs = treeView_.getSelectionPath().getPath();
|
||||
showProperties(((DefaultMutableTreeNode) objs[objs.length - 1]).getUserObject());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
*@param event Description of the Parameter
|
||||
*/
|
||||
void cancelButton_actionPerformed(java.awt.event.ActionEvent event) {
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the <code>JPane</code> for which the <code>JTree</code> is to be
|
||||
* built.
|
||||
*
|
||||
*@param obj Description of the Parameter
|
||||
*/
|
||||
// public void setPara(JPane Para) {
|
||||
// Enumeration layers;
|
||||
// Layer ly;
|
||||
// LayerChild child;
|
||||
// Graph graph;
|
||||
// Axis axis;
|
||||
// CartesianRenderer rend;
|
||||
// LineAttribute attr;
|
||||
// GridAttribute gattr;
|
||||
// PointAttribute pattr;
|
||||
// //
|
||||
// DefaultTreeModel treeModel;
|
||||
// DefaultMutableTreeNode node;
|
||||
// DefaultMutableTreeNode paneNode;
|
||||
//
|
||||
// DefaultMutableTreeNode layerNode;
|
||||
// DefaultMutableTreeNode childNode;
|
||||
// DefaultMutableTreeNode graphNode;
|
||||
// DefaultMutableTreeNode attrNode;
|
||||
// DefaultMutableTreeNode gattrNode;
|
||||
// DefaultMutableTreeNode pattrNode;
|
||||
// DefaultMutableTreeNode axisNode;
|
||||
// DefaultMutableTreeNode titleNode;
|
||||
//
|
||||
// m_Para = Para;
|
||||
// paneNode = new DefaultMutableTreeNode(m_Para);
|
||||
// treeModel = new DefaultTreeModel(paneNode);
|
||||
// treeView_.setModel(treeModel);
|
||||
// //
|
||||
// Component[] comps = pane_.getComponents();
|
||||
// for(int il=0; il < comps.length; il++) {
|
||||
// if(comps[il] instanceof Layer) {
|
||||
// ly = (Layer)comps[il];
|
||||
// } else {
|
||||
// continue;
|
||||
// }
|
||||
// String name, className;
|
||||
// layerNode = new DefaultMutableTreeNode(ly);
|
||||
// treeModel.insertNodeInto(layerNode, paneNode, treeModel.getChildCount(paneNode));
|
||||
// for(Enumeration childs = ly.childElements(); childs.hasMoreElements();) {
|
||||
// child = (LayerChild)childs.nextElement();
|
||||
// className = child.getClass().getName();
|
||||
// name = className.substring(className.lastIndexOf(".")+1);
|
||||
// childNode = new DefaultMutableTreeNode(child);
|
||||
// treeModel.insertNodeInto(childNode,layerNode,treeModel.getChildCount(layerNode));
|
||||
// }
|
||||
// graph = ly.getGraph();
|
||||
// className = graph.getClass().getName();
|
||||
// name = className.substring(className.lastIndexOf(".")+1);
|
||||
// if(graph instanceof CartesianGraph) {
|
||||
// graphNode = new DefaultMutableTreeNode(graph);
|
||||
// treeModel.insertNodeInto(graphNode,layerNode,treeModel.getChildCount(layerNode));
|
||||
// rend = ((CartesianGraph)graph).getRenderer();
|
||||
// if(rend instanceof LineCartesianRenderer) {
|
||||
// attr = (LineAttribute)((LineCartesianRenderer)rend).getAttribute();
|
||||
// if(attr != null) {
|
||||
// className = attr.getClass().getName();
|
||||
// name = className.substring(className.lastIndexOf(".")+1);
|
||||
// attrNode = new DefaultMutableTreeNode(attr);
|
||||
// treeModel.insertNodeInto(attrNode,graphNode,treeModel.getChildCount(graphNode));
|
||||
// }
|
||||
// } else if(rend instanceof GridCartesianRenderer) {
|
||||
// gattr = (GridAttribute)((GridCartesianRenderer)rend).getAttribute();
|
||||
// if(gattr != null) {
|
||||
// className = gattr.getClass().getName();
|
||||
// name = className.substring(className.lastIndexOf(".")+1);
|
||||
// gattrNode = new DefaultMutableTreeNode(gattr);
|
||||
// treeModel.insertNodeInto(gattrNode,
|
||||
// graphNode,
|
||||
// treeModel.getChildCount(graphNode));
|
||||
// }
|
||||
// } else if(rend instanceof PointCartesianRenderer) {
|
||||
// pattr = (PointAttribute)((PointCartesianRenderer)rend).getAttribute();
|
||||
// if(pattr != null) {
|
||||
// className = pattr.getClass().getName();
|
||||
// name = className.substring(className.lastIndexOf(".")+1);
|
||||
// pattrNode = new DefaultMutableTreeNode(pattr);
|
||||
// treeModel.insertNodeInto(pattrNode,
|
||||
// graphNode,
|
||||
// treeModel.getChildCount(graphNode));
|
||||
// }
|
||||
// }
|
||||
// for(Enumeration axes = ((CartesianGraph)graph).xAxisElements();
|
||||
// axes.hasMoreElements();) {
|
||||
// axis = (Axis)axes.nextElement();
|
||||
// className = axis.getClass().getName();
|
||||
// name = className.substring(className.lastIndexOf(".")+1);
|
||||
// if(axis instanceof SpaceAxis) {
|
||||
// axisNode = new DefaultMutableTreeNode(axis);
|
||||
// treeModel.insertNodeInto(axisNode,
|
||||
// graphNode,
|
||||
// treeModel.getChildCount(graphNode));
|
||||
// SGLabel title = axis.getTitle();
|
||||
// if(title != null) {
|
||||
// titleNode = new DefaultMutableTreeNode(title);
|
||||
// treeModel.insertNodeInto(titleNode,
|
||||
// axisNode,
|
||||
// treeModel.getChildCount(axisNode));
|
||||
// }
|
||||
// } else { // not a SpaceAxis
|
||||
// axisNode = new DefaultMutableTreeNode(axis);
|
||||
// treeModel.insertNodeInto(axisNode,
|
||||
// graphNode,
|
||||
// treeModel.getChildCount(graphNode));
|
||||
// }
|
||||
// }
|
||||
// for(Enumeration axes = ((CartesianGraph)graph).yAxisElements();
|
||||
// axes.hasMoreElements();) {
|
||||
// axis = (Axis)axes.nextElement();
|
||||
// className = axis.getClass().getName();
|
||||
// name = className.substring(className.lastIndexOf(".")+1);
|
||||
// if(axis instanceof SpaceAxis) {
|
||||
// axisNode = new DefaultMutableTreeNode(axis);
|
||||
// treeModel.insertNodeInto(axisNode,
|
||||
// graphNode,
|
||||
// treeModel.getChildCount(graphNode));
|
||||
// SGLabel title = axis.getTitle();
|
||||
// if(title != null) {
|
||||
// titleNode = new DefaultMutableTreeNode(title);
|
||||
// treeModel.insertNodeInto(titleNode,
|
||||
// axisNode,
|
||||
// treeModel.getChildCount(axisNode));
|
||||
// }
|
||||
// } else { // not a SpaceAxis
|
||||
// axisNode = new DefaultMutableTreeNode(axis);
|
||||
// treeModel.insertNodeInto(axisNode,
|
||||
// graphNode,
|
||||
// treeModel.getChildCount(graphNode));
|
||||
// }
|
||||
// }
|
||||
// } else { // not a CartesianGraph
|
||||
// graphNode = new DefaultMutableTreeNode(graph);
|
||||
// treeModel.insertNodeInto(graphNode,
|
||||
// layerNode,
|
||||
// treeModel.getChildCount(layerNode));
|
||||
// }
|
||||
// } // for layers
|
||||
// int row=0;
|
||||
// while(row < treeView_.getRowCount()) {
|
||||
// if(treeView_.isCollapsed(row)) {
|
||||
// treeView_.expandRow(row);
|
||||
// }
|
||||
// row++;
|
||||
// }
|
||||
// }
|
||||
|
||||
void showProperties(Object obj) {
|
||||
System.out.println("showProperties obj=" + obj.getClass());
|
||||
// if(obj instanceof SGLabel) {
|
||||
// if(sg_ == (SGLabelDialog) null)
|
||||
// sg_ = new SGLabelDialog();
|
||||
//
|
||||
// sg_.setSGLabel((SGLabel) obj, pane_);
|
||||
// if(!sg_.isShowing())
|
||||
// sg_.setVisible(true);
|
||||
// }
|
||||
// else
|
||||
// if(obj instanceof Logo) {
|
||||
// if(lg_ == null) {
|
||||
// lg_ = new LogoDialog();
|
||||
// }
|
||||
// lg_.setLogo((Logo) obj, pane_);
|
||||
// if(!lg_.isShowing())
|
||||
// lg_.setVisible(true);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the frame attribute of the JClassTree object
|
||||
*
|
||||
*@return The frame value
|
||||
*/
|
||||
private Frame getFrame() {
|
||||
Container theFrame = this;
|
||||
do {
|
||||
theFrame = theFrame.getParent();
|
||||
} while ((theFrame != null) && !(theFrame instanceof Frame));
|
||||
if (theFrame == null) {
|
||||
theFrame = new Frame();
|
||||
}
|
||||
return (Frame) theFrame;
|
||||
}
|
||||
}
|
||||
92
src/javaeva/gui/JDocFrame.java
Normal file
92
src/javaeva/gui/JDocFrame.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javax.swing.JInternalFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JToolBar;
|
||||
import java.io.File;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public abstract class JDocFrame extends JInternalFrame{
|
||||
private File m_file;
|
||||
private String titleStr;
|
||||
protected boolean changed = false;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JDocFrame(String title){
|
||||
super(title, true, true /* not closable*/, true, true);
|
||||
titleStr = title;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JDocFrame(File file){
|
||||
this(file.getName());
|
||||
m_file = file;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public File getFile(){
|
||||
return m_file;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getFileTitle(){
|
||||
return titleStr;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void save(){
|
||||
if(m_file != null) save(m_file);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void save(File f){
|
||||
if(!f.equals(m_file)){
|
||||
m_file = f;
|
||||
titleStr = f.getName();
|
||||
}
|
||||
setChangedImpl(false);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void setChangedImpl(boolean value){
|
||||
changed = value;
|
||||
if(changed) setTitle(titleStr + " *");
|
||||
else setTitle(titleStr);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void setChanged(boolean value){
|
||||
if(changed != value) setChangedImpl(value);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean isChanged(){
|
||||
return changed;
|
||||
}
|
||||
public abstract String[] getActionGroups();
|
||||
public abstract JMenu getMenu(String group);
|
||||
public abstract JToolBar getToolBar(String group);
|
||||
}
|
||||
|
||||
101
src/javaeva/gui/JEFrame.java
Normal file
101
src/javaeva/gui/JEFrame.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Title: The JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company:
|
||||
* @author
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class JEFrame extends JFrame {
|
||||
|
||||
public JEFrame() {
|
||||
super();
|
||||
register();
|
||||
}
|
||||
|
||||
public JEFrame(String name) {
|
||||
super(name);
|
||||
register();
|
||||
}
|
||||
|
||||
private void register() {
|
||||
JEFrameRegister.register(this);
|
||||
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
JEFrameRegister.unregister((JEFrame) e.getWindow());
|
||||
}
|
||||
public void windowClosed(WindowEvent e) {
|
||||
JEFrameRegister.unregister((JEFrame) e.getWindow());
|
||||
}
|
||||
});
|
||||
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_F,Event.CTRL_MASK),
|
||||
"ctrlFpressed"
|
||||
);
|
||||
this.getRootPane().getActionMap().put(
|
||||
"ctrlFpressed",
|
||||
new AbstractAction("ctrlFpressed") {
|
||||
public void actionPerformed( ActionEvent actionEvent ) {
|
||||
((JEFrame) JEFrameRegister.getFrameList()[0]).setExtendedState(JEFrame.NORMAL);
|
||||
((JEFrame) JEFrameRegister.getFrameList()[0]).toFront();
|
||||
}
|
||||
}
|
||||
);
|
||||
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_O,Event.CTRL_MASK),
|
||||
"ctrlOpressed"
|
||||
);
|
||||
this.getRootPane().getActionMap().put(
|
||||
"ctrlOpressed",
|
||||
new AbstractAction("ctrlOpressed") {
|
||||
public void actionPerformed( ActionEvent actionEvent ) {
|
||||
Object[] fl = JEFrameRegister.getFrameList();
|
||||
for (int i = 0; i < fl.length; i++) {
|
||||
((JEFrame) JEFrameRegister.getFrameList()[i]).setExtendedState(JEFrame.NORMAL);
|
||||
((JEFrame) JEFrameRegister.getFrameList()[i]).toFront();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_LESS , Event.CTRL_MASK),
|
||||
"ctrlSmallerpressed"
|
||||
);
|
||||
final JEFrame self = this;
|
||||
this.getRootPane().getActionMap().put(
|
||||
"ctrlSmallerpressed",
|
||||
new AbstractAction("ctrlSmallerpressed") {
|
||||
public void actionPerformed( ActionEvent actionEvent ) {
|
||||
JEFrameRegister.setFocusToNext(self);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
47
src/javaeva/gui/JEFrameRegister.java
Normal file
47
src/javaeva/gui/JEFrameRegister.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package javaeva.gui;
|
||||
import java.util.ArrayList;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
|
||||
|
||||
public class JEFrameRegister {
|
||||
|
||||
private static ArrayList JEFrameList;
|
||||
|
||||
static {
|
||||
|
||||
JEFrameList = new ArrayList();
|
||||
}
|
||||
|
||||
public static void register(JEFrame jf) {
|
||||
JEFrameList.add(jf);
|
||||
// System.out.println("reg ! JEFSIZE :" + JEFrameList.size());
|
||||
}
|
||||
|
||||
public static void unregister(JEFrame jf) {
|
||||
JEFrameList.remove(jf);
|
||||
// System.out.println("unreg! JEFSIZE :" + JEFrameList.size());
|
||||
}
|
||||
|
||||
public static Object[] getFrameList() {
|
||||
return JEFrameList.toArray();
|
||||
}
|
||||
|
||||
public static void setFocusToNext(JEFrame jf) {
|
||||
int idx = JEFrameList.indexOf(jf);
|
||||
idx = (idx + 1) % JEFrameList.size();
|
||||
JEFrame toset = ((JEFrame) JEFrameList.get(idx));
|
||||
toset.setExtendedState(JEFrame.NORMAL);
|
||||
toset.toFront();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
261
src/javaeva/gui/JExtDesktopPane.java
Normal file
261
src/javaeva/gui/JExtDesktopPane.java
Normal file
@@ -0,0 +1,261 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javax.swing.*;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.awt.event.*;
|
||||
import java.awt.*;
|
||||
import java.util.Vector;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JExtDesktopPane extends JDesktopPane{
|
||||
private ActionListener m_actMenuFrame;
|
||||
private ExtDesktopManager m_manager;
|
||||
public JExtMenu m_mnuWindow;
|
||||
private ExtAction actWindowTileVert;
|
||||
private ExtAction actWindowTileHorz;
|
||||
private ExtAction actWindowOverlap;
|
||||
private ExtAction actWindowArrangeIcons;
|
||||
private ExtAction actWindowList;
|
||||
public final static int WINDOW_TILEVERT = 0;
|
||||
public final static int WINDOW_TILEHORZ = 1;
|
||||
public final static int WINDOW_OVERLAP = 2;
|
||||
public final static int WINDOW_ARRANGEICONS = 3;
|
||||
public final static int WINDOW_LIST = 4;
|
||||
public final static int TITLEBAR_HEIGHT = 25;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JExtDesktopPane(){
|
||||
super();
|
||||
m_mnuWindow = new JExtMenu("&Windows");
|
||||
m_manager = new ExtDesktopManager(this);
|
||||
setDesktopManager(m_manager);
|
||||
|
||||
m_actMenuFrame = new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if(!(e.getSource() instanceof JMenuItem)) return;
|
||||
JInternalFrame frame = (JInternalFrame)((JMenuItem)e.getSource()).getClientProperty(ExtDesktopManager.FRAME);
|
||||
selectFrame(frame);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
m_mnuWindow.add(actWindowTileVert = new ExtAction("&Nebeneinander", "Ordnet die Fenster nebeneinander an"){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
tileWindows(SwingConstants.HORIZONTAL);
|
||||
}
|
||||
});
|
||||
|
||||
m_mnuWindow.add(actWindowTileHorz = new ExtAction("&Untereinander", "Ordnet die Fenster untereinander an"){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
tileWindows(SwingConstants.VERTICAL);
|
||||
}
|
||||
});
|
||||
|
||||
m_mnuWindow.add(actWindowOverlap = new ExtAction("<EFBFBD>&berlappend", "Ordnet die Fenster <20>berlappend an"){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
overlapWindows();
|
||||
}
|
||||
});
|
||||
|
||||
m_mnuWindow.add(actWindowArrangeIcons = new ExtAction("&Symbole anordnen", "Ordnet die Symbole auf dem Desktop an"){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
}
|
||||
});
|
||||
|
||||
m_mnuWindow.add(actWindowList = new ExtAction("Fenster&liste...", "Zeigt eine Liste aller Fenster an", KeyStroke.getKeyStroke(KeyEvent.VK_0, Event.ALT_MASK)){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
Vector l = new Vector();
|
||||
JInternalFrame frames[] = getAllFrames();
|
||||
|
||||
for(int i = 0; i < frames.length; i++)
|
||||
l.add(frames[i].getTitle());
|
||||
|
||||
JList list = new JList(l);
|
||||
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
JScrollPane pane = new JScrollPane(list);
|
||||
pane.setPreferredSize(new Dimension(pane.getPreferredSize().width, 150));
|
||||
|
||||
if(JOptionPane.showOptionDialog(JExtDesktopPane.this, pane, "Fenster ausw<73>hlen", JOptionPane.OK_CANCEL_OPTION,
|
||||
JOptionPane.PLAIN_MESSAGE, null, null, null) == JOptionPane.OK_OPTION)
|
||||
if(list.getSelectedIndex() != -1) selectFrame(frames[list.getSelectedIndex()]);
|
||||
}
|
||||
});
|
||||
|
||||
m_mnuWindow.addSeparator();
|
||||
m_manager.WINDOW_LIST_START = 6;
|
||||
}
|
||||
|
||||
public ExtAction getWindowAction(int action){
|
||||
switch(action){
|
||||
case WINDOW_TILEVERT: return actWindowTileVert;
|
||||
case WINDOW_TILEHORZ: return actWindowTileHorz;
|
||||
case WINDOW_OVERLAP: return actWindowOverlap;
|
||||
case WINDOW_ARRANGEICONS: return actWindowArrangeIcons;
|
||||
case WINDOW_LIST: return actWindowList;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void overlapWindows(){
|
||||
final int minWidth = 150, minHeight = 100;
|
||||
int fWidth, fHeight,
|
||||
oCount, i, indent;
|
||||
|
||||
JInternalFrame[] frames = getOpenFrames();
|
||||
if(frames.length == 0) return;
|
||||
|
||||
oCount = Math.min(frames.length, Math.min((getWidth() - minWidth) / TITLEBAR_HEIGHT + 1, (getHeight() - minHeight) / TITLEBAR_HEIGHT + 1));
|
||||
fWidth = getWidth() - (oCount - 1) * TITLEBAR_HEIGHT;
|
||||
fHeight = getHeight() - (oCount - 1) * TITLEBAR_HEIGHT;
|
||||
|
||||
indent = 0;
|
||||
for(i = 0; i < frames.length; i++){
|
||||
frames[frames.length - i - 1].setLocation(indent * TITLEBAR_HEIGHT, indent * TITLEBAR_HEIGHT);
|
||||
frames[frames.length - i - 1].setSize(fWidth, fHeight);
|
||||
indent = (i + 1) % oCount == 0 ? 0 : indent + 1;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void tileWindows(int orientation){
|
||||
int rows, cols,
|
||||
rHeight, cWidth,
|
||||
row, col,
|
||||
i;
|
||||
|
||||
JInternalFrame[] frames = getOpenFrames();
|
||||
if(frames.length == 0) return;
|
||||
|
||||
if(orientation == SwingConstants.HORIZONTAL){
|
||||
rows = (int)(Math.rint(Math.sqrt(frames.length) - 0.49));
|
||||
cols = frames.length / rows;
|
||||
rHeight = getHeight() / rows;
|
||||
cWidth = getWidth() / cols;
|
||||
row = col = 0;
|
||||
for(i = 0; i < frames.length; i++){
|
||||
frames[i].setLocation(col * cWidth, row * rHeight);
|
||||
frames[i].setSize(cWidth, rHeight);
|
||||
if(col == cols - 1){
|
||||
row++;
|
||||
col = 0;
|
||||
}
|
||||
else col++;
|
||||
if(row > 0 && frames.length - i - (cols + 1) * (rows - row) > 0){
|
||||
cols++;
|
||||
cWidth = getWidth() / cols;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(orientation == SwingConstants.VERTICAL){
|
||||
cols = (int)(Math.rint(Math.sqrt(frames.length) - 0.49));
|
||||
rows = frames.length / cols;
|
||||
cWidth = getWidth() / cols;
|
||||
rHeight = getHeight() / rows;
|
||||
col = row = 0;
|
||||
for(i = 0; i < frames.length; i++){
|
||||
frames[i].setLocation(col * cWidth, row * rHeight);
|
||||
frames[i].setSize(cWidth, rHeight);
|
||||
if(row == rows - 1){
|
||||
col++;
|
||||
row = 0;
|
||||
}
|
||||
else row++;
|
||||
if(col > 0 && frames.length - i - (rows + 1) * (cols - col) > 0){
|
||||
rows++;
|
||||
rHeight = getHeight() / rows;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JInternalFrame[] getOpenFrames(){
|
||||
JInternalFrame[] result;
|
||||
Vector vResults = new Vector(10);
|
||||
Component tmp;
|
||||
|
||||
for(int i = 0; i < getComponentCount(); i++){
|
||||
tmp = getComponent(i);
|
||||
if(tmp instanceof JInternalFrame) vResults.addElement(tmp);
|
||||
}
|
||||
|
||||
result = new JInternalFrame[vResults.size()];
|
||||
vResults.copyInto(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
public int getFrameCount(){
|
||||
return getComponentCount(new ComponentFilter(){
|
||||
public boolean accept(Component c){
|
||||
return c instanceof JInternalFrame ||
|
||||
(c instanceof JInternalFrame.JDesktopIcon &&
|
||||
((JInternalFrame.JDesktopIcon)c).getInternalFrame() != null);
|
||||
}
|
||||
});
|
||||
}
|
||||
public int getComponentCount(ComponentFilter c){
|
||||
int result = 0;
|
||||
for(int i = 0; i < getComponentCount(); i++) if(c.accept(getComponent(i))) result++;
|
||||
return result;
|
||||
}
|
||||
public void selectFrame(JInternalFrame f){
|
||||
if(f != null){
|
||||
try{
|
||||
if(f.isIcon()) f.setIcon(false);
|
||||
else f.setSelected(true);
|
||||
}
|
||||
catch(PropertyVetoException exc){}
|
||||
}
|
||||
}
|
||||
public void addImpl(Component comp, Object constraints, int index){
|
||||
super.addImpl(comp, constraints, index);
|
||||
//System.out.println("JExtDesktopPane.addImpl");
|
||||
if(comp instanceof JDocFrame){
|
||||
JDocFrame f = (JDocFrame)comp;
|
||||
int frameIndex = m_mnuWindow.getItemCount() - m_manager.WINDOW_LIST_START + 1;
|
||||
if(f.getClientProperty(ExtDesktopManager.INDEX) != null) return;
|
||||
f.putClientProperty(ExtDesktopManager.INDEX, new Integer(frameIndex));
|
||||
JMenuItem m = new JMenuItem((frameIndex < 10 ? frameIndex + " " : "") + f.getTitle());
|
||||
if(frameIndex < 10){
|
||||
m.setMnemonic((char)(0x30 + frameIndex));
|
||||
m.setAccelerator(KeyStroke.getKeyStroke(0x30 + frameIndex, Event.ALT_MASK));
|
||||
}
|
||||
m.setToolTipText("Shows the window " + f.getTitle() + " an");
|
||||
m.putClientProperty(ExtDesktopManager.FRAME, f);
|
||||
m.addActionListener(m_actMenuFrame);
|
||||
m_mnuWindow.add(m);
|
||||
}
|
||||
// if(comp instanceof Plot){
|
||||
// Plot f = (Plot)comp;
|
||||
// int frameIndex = m_mnuWindow.getItemCount() - m_manager.WINDOW_LIST_START + 1;
|
||||
// if(f.getClientProperty(ExtDesktopManager.INDEX) != null) return;
|
||||
// f.putClientProperty(ExtDesktopManager.INDEX, new Integer(frameIndex));
|
||||
// JMenuItem m = new JMenuItem((frameIndex < 10 ? frameIndex + " " : "") + f.getTitle());
|
||||
// if(frameIndex < 10){
|
||||
// m.setMnemonic((char)(0x30 + frameIndex));
|
||||
// m.setAccelerator(KeyStroke.getKeyStroke(0x30 + frameIndex, Event.ALT_MASK));
|
||||
// }
|
||||
// m.setToolTipText("Shows the window " + f.getTitle() + " an");
|
||||
// m.putClientProperty(ExtDesktopManager.FRAME, f);
|
||||
// m.addActionListener(m_actMenuFrame);
|
||||
// m_mnuWindow.add(m);
|
||||
// }
|
||||
}
|
||||
public JMenu getWindowMenu(){
|
||||
return m_mnuWindow;
|
||||
}
|
||||
}
|
||||
39
src/javaeva/gui/JExtFileChooser.java
Normal file
39
src/javaeva/gui/JExtFileChooser.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
|
||||
public class JExtFileChooser extends JFileChooser{
|
||||
private boolean overwriteWarning = true;
|
||||
|
||||
public void setOverwriteWarning(boolean value){
|
||||
overwriteWarning = value;
|
||||
}
|
||||
|
||||
public boolean getOverwriteWarning(){
|
||||
return overwriteWarning;
|
||||
}
|
||||
|
||||
public void approveSelection(){
|
||||
if(getDialogType() == JFileChooser.SAVE_DIALOG && overwriteWarning){
|
||||
File f = getSelectedFile();
|
||||
|
||||
if(f != null && f.exists())
|
||||
if(JOptionPane.showConfirmDialog(this, "Die Datei " + f.getPath() + " existiert bereits.\nSoll sie <20>berschrieben werden?", "Achtung", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.NO_OPTION) return;
|
||||
}
|
||||
|
||||
super.approveSelection();
|
||||
}
|
||||
}
|
||||
81
src/javaeva/gui/JExtMenu.java
Normal file
81
src/javaeva/gui/JExtMenu.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.Action;
|
||||
import java.beans.*;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JExtMenu extends JMenu{
|
||||
public final static String ACTION = "Action";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JExtMenu(){
|
||||
//super();
|
||||
//Mnemonic m = new Mnemonic(s);
|
||||
//setText(m.getText());
|
||||
//setMnemonic(m.getMnemonic());
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JExtMenu(String s){
|
||||
super();
|
||||
Mnemonic m = new Mnemonic(s);
|
||||
setText(m.getText());
|
||||
setMnemonic(m.getMnemonic());
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JMenuItem add(Action a){
|
||||
JMenuItem item = super.add(a);
|
||||
Object o;
|
||||
o = a.getValue(ExtAction.MNEMONIC);
|
||||
if(o != null) item.setMnemonic(((Character)o).charValue());
|
||||
o = a.getValue(ExtAction.TOOLTIP);
|
||||
if(o != null) item.setToolTipText((String)o);
|
||||
o = a.getValue(ExtAction.KEYSTROKE);
|
||||
if(o != null) item.setAccelerator((KeyStroke)o);
|
||||
return item;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected PropertyChangeListener createActionChangeListener(JMenuItem b){
|
||||
return new ExtActionChangedListener(b){
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
JMenuItem menuItem = (JMenuItem)component;
|
||||
if(menuItem == null) return;
|
||||
String propertyName = e.getPropertyName();
|
||||
if(propertyName.equals(Action.NAME)) menuItem.setText((String)e.getNewValue());
|
||||
else if(propertyName.equals("enabled")) menuItem.setEnabled(((Boolean)e.getNewValue()).booleanValue());
|
||||
else if(propertyName.equals(Action.SMALL_ICON)){
|
||||
Icon icon = (Icon)e.getNewValue();
|
||||
menuItem.setIcon(icon);
|
||||
menuItem.invalidate();
|
||||
menuItem.repaint();
|
||||
}
|
||||
else if(propertyName.equals(ExtAction.MNEMONIC)) menuItem.setMnemonic(((Character)e.getNewValue()).charValue());
|
||||
else if(propertyName.equals(ExtAction.TOOLTIP)) menuItem.setToolTipText((String)e.getNewValue());
|
||||
else if(propertyName.equals(ExtAction.KEYSTROKE)) menuItem.setAccelerator((KeyStroke)e.getNewValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
83
src/javaeva/gui/JExtToolBar.java
Normal file
83
src/javaeva/gui/JExtToolBar.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javax.swing.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.Insets;
|
||||
import java.beans.*;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JExtToolBar extends JToolBar{
|
||||
public JButton add(Action a){
|
||||
JButton button = super.add(a);
|
||||
button.setText(null);
|
||||
button.setMargin(new Insets(0, 0, 0, 0));
|
||||
|
||||
Object o;
|
||||
o = a.getValue(ExtAction.TOOLTIP);
|
||||
String toolTip = o != null ? (String)o : "";
|
||||
|
||||
o = a.getValue(ExtAction.KEYSTROKE);
|
||||
button.setToolTipText(toolTip + getKeyText((KeyStroke)o));
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
private String getKeyText(KeyStroke k){
|
||||
StringBuffer result = new StringBuffer();
|
||||
|
||||
if(k != null){
|
||||
int modifiers = k.getModifiers();
|
||||
if(modifiers > 0) result.append(KeyEvent.getKeyModifiersText(modifiers) + "+");
|
||||
result.append(KeyEvent.getKeyText(k.getKeyCode()));
|
||||
}
|
||||
if(result.length() > 0){
|
||||
result.insert(0, " [");
|
||||
result.append("]");
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
protected PropertyChangeListener createActionChangeListener(JButton b){
|
||||
return new ExtActionChangedListener(b){
|
||||
public void propertyChange(PropertyChangeEvent e){
|
||||
JButton button = (JButton)component;
|
||||
|
||||
String propertyName = e.getPropertyName();
|
||||
if(propertyName.equals(Action.NAME)){
|
||||
/* Nichts tun! */
|
||||
}
|
||||
else if(propertyName.equals("enabled")){
|
||||
button.setEnabled(((Boolean)e.getNewValue()).booleanValue());
|
||||
button.repaint();
|
||||
}
|
||||
else if(e.getPropertyName().equals(Action.SMALL_ICON)){
|
||||
button.setIcon((Icon)e.getNewValue());
|
||||
button.invalidate();
|
||||
button.repaint();
|
||||
}
|
||||
else if(propertyName.equals(ExtAction.TOOLTIP) || propertyName.equals(ExtAction.KEYSTROKE)){
|
||||
Action source = (Action)e.getSource();
|
||||
|
||||
Object o = source.getValue(ExtAction.TOOLTIP);
|
||||
String toolTip = o != null ? (String)o : "";
|
||||
o = source.getValue(ExtAction.KEYSTROKE);
|
||||
button.setToolTipText(toolTip + getKeyText((KeyStroke)o));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
204
src/javaeva/gui/JModuleGeneralPanel.java
Normal file
204
src/javaeva/gui/JModuleGeneralPanel.java
Normal file
@@ -0,0 +1,204 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 284 $
|
||||
* $Date: 2007-11-27 14:37:05 +0100 (Tue, 27 Nov 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.io.Serializable;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import javaeva.server.modules.ModuleAdapter;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import wsi.ra.jproxy.RMIProxyLocal;
|
||||
import wsi.ra.jproxy.RemoteStateListener;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
|
||||
public static boolean TRACE = false;
|
||||
private String m_Name ="undefined";
|
||||
private ModuleAdapter m_Adapter;
|
||||
private boolean m_State;
|
||||
private JButton m_RunButton;
|
||||
// private JButton m_RestartButton;
|
||||
private JButton m_actStop;
|
||||
// private JButton m_actExitMod;
|
||||
private JButton m_JHelpButton;
|
||||
private JPanel m_Panel;
|
||||
private String m_HelperFileName;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JModuleGeneralPanel(ModuleAdapter Adapter, boolean state) {
|
||||
m_Name = "GENERAL";
|
||||
m_State = state;
|
||||
if (TRACE) System.out.println("Constructor JModuleGeneralPanel:");
|
||||
m_Adapter = Adapter;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JComponent installActions() {
|
||||
String myhostname = null;
|
||||
|
||||
m_Panel= new JPanel();
|
||||
if(TRACE) System.out.println("JModuleGeneral.installAction()");
|
||||
if (m_Adapter.hasConnection()) { // we might be in rmi mode
|
||||
try {
|
||||
myhostname = InetAddress.getLocalHost().getHostName();
|
||||
} catch (Exception e) {
|
||||
System.err.println("ERROR getting myhostname "+e.getMessage());
|
||||
}
|
||||
}
|
||||
if (!m_Adapter.hasConnection()) {
|
||||
m_Adapter.addRemoteStateListener((RemoteStateListener)(this));
|
||||
} else {// there is a network RMI connection
|
||||
m_Adapter.addRemoteStateListener((RemoteStateListener)RMIProxyLocal.newInstance(this));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
m_RunButton= new JButton("Start Optimization");
|
||||
m_RunButton.setToolTipText("Start the current optimization run.");
|
||||
//System.out.println("Start tm_RunButton.addActionListener Run Opt pressed ====================!!!!!!!!!!!!!!!!!!");
|
||||
m_RunButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
//System.out.println("Run Opt pressed !!!!!!!!!!!!!!!!======================!!");
|
||||
try {
|
||||
m_Adapter.startOpt();
|
||||
m_actStop.setEnabled(true);
|
||||
m_RunButton.setEnabled(false);
|
||||
// m_RestartButton.setEnabled(false);
|
||||
m_JHelpButton.setEnabled(true);
|
||||
} catch (Exception ee) {
|
||||
ee.printStackTrace();
|
||||
System.out.print ("Error in run: " +ee +" : " + ee.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (m_State == false )
|
||||
m_RunButton.setEnabled(true);
|
||||
else
|
||||
m_RunButton.setEnabled(false);
|
||||
m_Panel.add(m_RunButton);
|
||||
// m_Panel.setBorder(BorderFactory.createTitledBorder("general action buttons"));
|
||||
// //////////////////////////////////////////////////////////////
|
||||
// m_RestartButton= new JButton("Restart Optimization");
|
||||
// m_RestartButton.setToolTipText("Restart the current optimization run.");
|
||||
// m_RestartButton.addActionListener(new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent e){
|
||||
// try {
|
||||
// m_Adapter.restartOpt();
|
||||
// m_actStop.setEnabled(true);
|
||||
// m_RunButton.setEnabled(false);
|
||||
// m_RestartButton.setEnabled(false);
|
||||
// } catch (Exception ee) {
|
||||
// ee.printStackTrace();
|
||||
// System.out.println("Error in run: " +ee +" : " + ee.getMessage() );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// if (m_State == false )
|
||||
// m_RestartButton.setEnabled(false);
|
||||
// else
|
||||
// m_RestartButton.setEnabled(false);
|
||||
// m_Panel.add(m_RestartButton);
|
||||
//////////////////////////////////////////////////////////////
|
||||
m_actStop= new JButton("Stop");
|
||||
m_actStop.setToolTipText("Stop the current optimization run.");
|
||||
m_actStop.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
try {
|
||||
m_Adapter.stopOpt(); // this means user break
|
||||
} catch (Exception ee) { System.out.print ("Error in stop: " + ee.getMessage() ); }
|
||||
}
|
||||
}
|
||||
);
|
||||
// if (m_State == false )
|
||||
// m_RestartButton.setEnabled(false);
|
||||
// else
|
||||
// m_RestartButton.setEnabled(true);
|
||||
m_Panel.add(m_actStop);
|
||||
if (m_HelperFileName.equals("")== false) {
|
||||
m_JHelpButton= new JButton("Description");
|
||||
m_JHelpButton.setToolTipText("Description of the current optimization algorithm.");
|
||||
m_JHelpButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
//System.out.println("Run Opt pressed !!!!!!!!!!!!!!!!======================!!");
|
||||
try {
|
||||
if (m_HelperFileName!=null) {
|
||||
HtmlDemo temp = new HtmlDemo(m_HelperFileName);
|
||||
temp.show();
|
||||
}
|
||||
m_JHelpButton.setEnabled(true);
|
||||
} catch (Exception ee) {
|
||||
ee.printStackTrace();
|
||||
System.out.print ("Error in run: " +ee +" : " + ee.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
m_Panel.add(m_JHelpButton);
|
||||
}
|
||||
// m_actExitMod = new JButton("Exit Module");
|
||||
// m_actExitMod.setToolTipText("todo !!.");// TODO
|
||||
return m_Panel;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void performedStop() {
|
||||
if (TRACE) System.out.println("JModuleGeneralPanel.stopOptPerformed");
|
||||
m_RunButton.setEnabled(true);
|
||||
// m_RestartButton.setEnabled(true);
|
||||
m_RunButton.repaint();
|
||||
m_actStop.setEnabled(false);
|
||||
m_Panel.repaint();
|
||||
}
|
||||
|
||||
public void performedStart(String infoString) {
|
||||
}
|
||||
|
||||
|
||||
public void performedRestart(String infoString) {
|
||||
}
|
||||
|
||||
public void updateProgress(final int percent) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getName() {
|
||||
return m_Name;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setHelperFilename (String s) {
|
||||
m_HelperFileName = s;
|
||||
}
|
||||
}
|
||||
|
||||
89
src/javaeva/gui/JParaPanel.java
Normal file
89
src/javaeva/gui/JParaPanel.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package javaeva.gui;
|
||||
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyEditorManager;
|
||||
import java.io.Serializable;
|
||||
|
||||
/*
|
||||
* ==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
* ==========================================================================
|
||||
*/
|
||||
|
||||
public class JParaPanel implements Serializable {
|
||||
|
||||
public static boolean TRACE = false;
|
||||
protected String m_Name = "undefined";
|
||||
protected Object m_LocalParameter;
|
||||
protected Object m_ProxyParameter;
|
||||
protected PropertyEditor m_Editor;
|
||||
private JPanel m_Panel;
|
||||
|
||||
public JParaPanel() {
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public JParaPanel(Object Parameter, String name) {
|
||||
m_Name = name;
|
||||
m_LocalParameter = Parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public JComponent installActions() {
|
||||
m_Panel = new JPanel();
|
||||
//m_Panel.setPreferredSize(new Dimension(200, 200)); // MK: this was evil, killing all the auto-layout mechanisms
|
||||
PropertyEditorProvider.installEditors();
|
||||
|
||||
m_Editor = new GenericObjectEditor();
|
||||
((GenericObjectEditor) (m_Editor)).setClassType(m_LocalParameter.
|
||||
getClass());
|
||||
((GenericObjectEditor) (m_Editor)).setValue(m_LocalParameter);
|
||||
((GenericObjectEditor) (m_Editor)).disableOK();
|
||||
|
||||
m_Panel.setLayout(new BorderLayout());
|
||||
m_Panel.add(m_Editor.getCustomEditor(), BorderLayout.CENTER);
|
||||
|
||||
m_Panel.setLayout(new FlowLayout(FlowLayout.TRAILING, 10, 10));
|
||||
m_Panel.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7));
|
||||
m_Panel.setLayout(new GridBagLayout());
|
||||
m_Panel.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||
return m_Panel;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public String getName() {
|
||||
return m_Name;
|
||||
}
|
||||
|
||||
/** This method will allow you to add a new Editor to a given class
|
||||
* @param object
|
||||
* @param editor
|
||||
* @return False if failed true else.
|
||||
*/
|
||||
public boolean registerEditor(Class object, Class editor) {
|
||||
try {
|
||||
PropertyEditorManager.registerEditor(object, editor);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.err.println(ex.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
147
src/javaeva/gui/JTabbedModuleFrame.java
Normal file
147
src/javaeva/gui/JTabbedModuleFrame.java
Normal file
@@ -0,0 +1,147 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 272 $
|
||||
* $Date: 2007-11-21 18:06:36 +0100 (Wed, 21 Nov 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javaeva.gui.JModuleGeneralPanel;
|
||||
import javaeva.gui.JParaPanel;
|
||||
import javaeva.server.modules.ModuleAdapter;
|
||||
import javaeva.client.EvAClient;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.print.* ;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.event.*;
|
||||
import java.util.ArrayList;
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JTabbedModuleFrame implements Serializable {
|
||||
private ArrayList m_GUIContainer;
|
||||
// private JTabbedPane m_MainPanel;
|
||||
private ModuleAdapter m_ProxyModuleAdapter;
|
||||
private JPanel m_PanelTool;
|
||||
// private JPanel m_SuperPanel;
|
||||
private JExtToolBar m_BarStandard;
|
||||
private JFrame m_Frame;
|
||||
private String m_AdapterName;
|
||||
private String m_Host;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JTabbedModuleFrame(ModuleAdapter newModuleAdapter,String AdapterName,String Host,ArrayList GUIContainer) {
|
||||
m_ProxyModuleAdapter = newModuleAdapter;
|
||||
m_AdapterName = AdapterName;
|
||||
m_Host = Host;
|
||||
m_GUIContainer = GUIContainer;
|
||||
}
|
||||
|
||||
public JPanel createContentPane() {
|
||||
JPanel m_SuperPanel = new JPanel();
|
||||
m_SuperPanel.setLayout(new GridBagLayout());
|
||||
GridBagConstraints gbconst = new GridBagConstraints();
|
||||
gbconst.fill = GridBagConstraints.BOTH;
|
||||
gbconst.weightx = 1;
|
||||
gbconst.weighty = 1;
|
||||
gbconst.gridwidth = GridBagConstraints.REMAINDER;
|
||||
|
||||
JTabbedPane m_MainPanel = new JTabbedPane();
|
||||
buildToolBar();
|
||||
|
||||
for (int i=0;i<m_GUIContainer.size();i++) {
|
||||
Object TEMP = m_GUIContainer.get(i);
|
||||
if (TEMP instanceof JModuleGeneralPanel) {
|
||||
m_BarStandard.add((JPanel) ((JModuleGeneralPanel)TEMP).installActions());
|
||||
continue;
|
||||
}
|
||||
if (TEMP instanceof JParaPanel) {
|
||||
JPanel tmpPanel = (JPanel)((JParaPanel)TEMP).installActions();
|
||||
m_MainPanel.addTab (((JParaPanel)TEMP).getName(), tmpPanel);
|
||||
}
|
||||
}
|
||||
m_MainPanel.addChangeListener(new ChangeListener () {
|
||||
public void stateChanged (ChangeEvent evt) {
|
||||
//Dimension d = (m_MainPanel.getSelectedComponent()).getPreferredSize();
|
||||
//System.out.println("HERETETETETE " + d.height + " " + d.width + " " + m_MainPanel.getSelectedIndex());
|
||||
//m_Frame.setSize(d);
|
||||
//m_MainPanel.validate();
|
||||
//m_Frame.pack();
|
||||
//m_Frame.validate();
|
||||
}
|
||||
});
|
||||
m_SuperPanel.add(m_MainPanel, gbconst);
|
||||
|
||||
return m_SuperPanel;
|
||||
}
|
||||
|
||||
public JExtToolBar getToolBar() {
|
||||
return m_BarStandard;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void createGUI() {
|
||||
m_Frame = new JEFrame (m_AdapterName+" on "+m_Host);
|
||||
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAClient.iconLocation);
|
||||
try {
|
||||
m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find JavaEvA icon, please move resource folder to working directory!");
|
||||
}
|
||||
|
||||
JPanel m_SuperPanel = createContentPane();
|
||||
|
||||
m_Frame.getContentPane().add(m_SuperPanel);
|
||||
m_Frame.getContentPane().add(m_PanelTool, BorderLayout.NORTH);
|
||||
|
||||
m_Frame.pack();
|
||||
m_Frame.setVisible(true);
|
||||
System.out.println(m_Frame.getPreferredSize().toString());
|
||||
|
||||
m_Frame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
|
||||
m_Frame.toFront();
|
||||
}
|
||||
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// private void removeGUI() {
|
||||
// System.out.println("removeGUI");
|
||||
// for (int i=0;i< m_GUIContainer.size();i++) {
|
||||
// Object TEMP = m_GUIContainer.get(i);
|
||||
// if (TEMP instanceof JPanel)
|
||||
// m_MainPanel.remove((JPanel)TEMP);
|
||||
// }
|
||||
// m_Frame.repaint();
|
||||
// }
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void buildToolBar(){
|
||||
m_PanelTool = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
m_BarStandard = new JExtToolBar();
|
||||
m_BarStandard.setFloatable(false);
|
||||
// m_BarStandard.setBorder(BorderFactory.createRaisedBevelBorder());
|
||||
m_PanelTool.add(m_BarStandard);
|
||||
// m_Frame.getContentPane().add(m_PanelTool, BorderLayout.NORTH);
|
||||
}
|
||||
}
|
||||
284
src/javaeva/gui/JTextEditorInternalFrame.java
Normal file
284
src/javaeva/gui/JTextEditorInternalFrame.java
Normal file
@@ -0,0 +1,284 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.undo.*;
|
||||
import java.io.*;
|
||||
import java.util.Hashtable;
|
||||
import java.awt.event.* ;
|
||||
import java.awt.Event;
|
||||
|
||||
|
||||
public class JTextEditorInternalFrame extends JDocFrame{
|
||||
public final static String GROUP_EDIT = "Edit";
|
||||
private JTextArea textArea;
|
||||
private final String[] actionGroups = {GROUP_EDIT};
|
||||
protected UndoManager undo = new UndoManager();
|
||||
private class UndoAction extends ExtAction{
|
||||
public UndoAction(){
|
||||
super("R<EFBFBD>ckg<EFBFBD>ngig", new ImageIcon("images/EditUndo.gif"), "Macht die letzte Aktion r<>ckg<6B>ngig",
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK));
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e){
|
||||
try{
|
||||
undo.undo();
|
||||
}
|
||||
catch(CannotUndoException exc){}
|
||||
|
||||
update();
|
||||
actRedo.update();
|
||||
}
|
||||
|
||||
private void update() {
|
||||
if(undo.canUndo()){
|
||||
setEnabled(true);
|
||||
putValue(Action.NAME, undo.getUndoPresentationName());
|
||||
}
|
||||
else{
|
||||
setEnabled(false);
|
||||
putValue(Action.NAME, "R<EFBFBD>ckg<EFBFBD>ngig");
|
||||
}
|
||||
}
|
||||
} // end of inner class UndoAction
|
||||
///////////////////////////////////////////
|
||||
//
|
||||
///////////////////////////////////////////
|
||||
private class RedoAction extends ExtAction{
|
||||
public RedoAction(){
|
||||
super("Wiederholen", "Wiederholt die letzte Aktion", KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK|Event.SHIFT_MASK));
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try{
|
||||
undo.redo();
|
||||
}
|
||||
catch(CannotRedoException exc){}
|
||||
|
||||
update();
|
||||
actUndo.update();
|
||||
}
|
||||
|
||||
private void update() {
|
||||
if(undo.canRedo()){
|
||||
setEnabled(true);
|
||||
putValue(Action.NAME, undo.getRedoPresentationName());
|
||||
}
|
||||
else{
|
||||
setEnabled(false);
|
||||
putValue(Action.NAME, "Wiederholen");
|
||||
}
|
||||
}
|
||||
} // end of inner class RedoAction
|
||||
|
||||
private UndoAction actUndo;
|
||||
private RedoAction actRedo;
|
||||
public final static String undoAction = "undo";
|
||||
public final static String redoAction = "redo";
|
||||
///////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////
|
||||
public String[] getActionGroups(){
|
||||
return actionGroups;
|
||||
}
|
||||
|
||||
private JMenu mnuEdit;
|
||||
private JToolBar barEdit;
|
||||
public JMenu getMenu(String group){
|
||||
if(GROUP_EDIT.equals(group)) return mnuEdit;
|
||||
else return null;
|
||||
}
|
||||
public JToolBar getToolBar(String group){
|
||||
if(GROUP_EDIT.equals(group)) return barEdit;
|
||||
return null;
|
||||
}
|
||||
|
||||
private Hashtable hashActions = new Hashtable();
|
||||
|
||||
private Action cloneAction(Action a){
|
||||
Action result = null;
|
||||
|
||||
try{
|
||||
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(bOut);
|
||||
out.writeObject(a);
|
||||
ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
|
||||
ObjectInputStream in = new ObjectInputStream(bIn);
|
||||
result = (Action)in.readObject();
|
||||
}
|
||||
catch(Exception exc){}
|
||||
|
||||
return result;
|
||||
}
|
||||
///////////////////////////////////////////////
|
||||
//
|
||||
//////////////////////////////////////////////
|
||||
private void createActions(){
|
||||
hashActions.put(undoAction, actUndo = new UndoAction());
|
||||
hashActions.put(redoAction, actRedo = new RedoAction());
|
||||
|
||||
Action[] actions = textArea.getActions();
|
||||
for(int i = 0; i < actions.length; i++) hashActions.put((String)actions[i].getValue(Action.NAME), actions[i]);
|
||||
|
||||
mnuEdit = new JExtMenu("&Bearbeiten");
|
||||
barEdit = new JExtToolBar();
|
||||
|
||||
Action a;
|
||||
Keymap keys = textArea.getKeymap();
|
||||
KeyStroke[] keyActions;
|
||||
|
||||
mnuEdit.add(actUndo);
|
||||
barEdit.add(actUndo);
|
||||
mnuEdit.add(actRedo);
|
||||
mnuEdit.addSeparator();
|
||||
|
||||
a = (Action)hashActions.get(DefaultEditorKit.cutAction);
|
||||
keyActions = keys.getKeyStrokesForAction(a);
|
||||
if(keyActions != null && keyActions.length > 0) a.putValue(ExtAction.KEYSTROKE, keyActions[0]);
|
||||
a.putValue(Action.SMALL_ICON, new ImageIcon("images/EditCut.gif"));
|
||||
a.putValue(ExtAction.CAPTION, "Ausschneiden");
|
||||
a.putValue(ExtAction.MNEMONIC, new Character('a'));
|
||||
a.putValue(ExtAction.TOOLTIP, "Schneidet den markierten Text aus und setzt ihn in die Zwischenablage");
|
||||
mnuEdit.add(a);
|
||||
barEdit.add(a);
|
||||
|
||||
a = (Action)hashActions.get(DefaultEditorKit.copyAction);
|
||||
keyActions = keys.getKeyStrokesForAction(a);
|
||||
if(keyActions != null && keyActions.length > 0) a.putValue(ExtAction.KEYSTROKE, keyActions[0]);
|
||||
a.putValue(Action.SMALL_ICON, new ImageIcon("images/EditCopy.gif"));
|
||||
a.putValue(ExtAction.CAPTION, "Kopieren");
|
||||
a.putValue(ExtAction.MNEMONIC, new Character('k'));
|
||||
a.putValue(ExtAction.TOOLTIP, "Kopiert den markierten Text in die Zwischenablage");
|
||||
mnuEdit.add(a);
|
||||
barEdit.add(a);
|
||||
|
||||
a = (Action)hashActions.get(DefaultEditorKit.pasteAction);
|
||||
keyActions = keys.getKeyStrokesForAction(a);
|
||||
if(keyActions != null && keyActions.length > 0) a.putValue(ExtAction.KEYSTROKE, keyActions[0]);
|
||||
a.putValue(Action.SMALL_ICON, new ImageIcon("images/EditPaste.gif"));
|
||||
a.putValue(ExtAction.CAPTION, "Einf<EFBFBD>gen");
|
||||
a.putValue(ExtAction.MNEMONIC, new Character('e'));
|
||||
a.putValue(ExtAction.TOOLTIP, "F<EFBFBD>gt Text aus der Zwischenablage ein");
|
||||
mnuEdit.add(a);
|
||||
barEdit.add(a);
|
||||
|
||||
mnuEdit.addSeparator();
|
||||
|
||||
a = (Action)hashActions.get(DefaultEditorKit.selectAllAction);
|
||||
keyActions = keys.getKeyStrokesForAction(a);
|
||||
if(keyActions != null && keyActions.length > 0) a.putValue(ExtAction.KEYSTROKE, keyActions[0]);
|
||||
a.putValue(ExtAction.CAPTION, "Alles markieren");
|
||||
a.putValue(ExtAction.MNEMONIC, new Character('m'));
|
||||
a.putValue(ExtAction.TOOLTIP, "Markiert das ganze Dokument");
|
||||
mnuEdit.add(a);
|
||||
}
|
||||
//////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////
|
||||
private void createTextArea(){
|
||||
textArea = new JTextArea();
|
||||
getContentPane().add(new JScrollPane(textArea));
|
||||
}
|
||||
/////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////
|
||||
private void createListeners(){
|
||||
textArea.getDocument().addDocumentListener(new DocumentListener(){
|
||||
private void changed(){
|
||||
setChanged(true);
|
||||
}
|
||||
|
||||
public void changedUpdate(DocumentEvent e){
|
||||
changed();
|
||||
}
|
||||
|
||||
public void insertUpdate(DocumentEvent e){
|
||||
changed();
|
||||
}
|
||||
|
||||
public void removeUpdate(DocumentEvent e){
|
||||
changed();
|
||||
}
|
||||
});
|
||||
|
||||
textArea.getDocument().addUndoableEditListener(new UndoableEditListener(){
|
||||
public void undoableEditHappened(UndoableEditEvent e){
|
||||
undo.addEdit(e.getEdit());
|
||||
actUndo.update();
|
||||
actRedo.update();
|
||||
}
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
//
|
||||
///////////////////////////////////////////////////
|
||||
public JTextEditorInternalFrame(String title){
|
||||
super(title);
|
||||
createTextArea();
|
||||
createListeners();
|
||||
createActions();
|
||||
}
|
||||
//////////////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////////////
|
||||
public JTextEditorInternalFrame(File file){
|
||||
super(file);
|
||||
createTextArea();
|
||||
|
||||
if(file.exists()){
|
||||
FileReader in = null;
|
||||
try{
|
||||
in = new FileReader(file);
|
||||
textArea.read(in, null);
|
||||
}
|
||||
catch(IOException exc){}
|
||||
finally{
|
||||
if(in != null) try{
|
||||
in.close();
|
||||
}
|
||||
catch(IOException exc){}
|
||||
}
|
||||
}
|
||||
|
||||
createListeners();
|
||||
createActions();
|
||||
}
|
||||
|
||||
public void save(File f){
|
||||
FileWriter out = null;
|
||||
try{
|
||||
out = new FileWriter(f);
|
||||
textArea.write(out);
|
||||
}
|
||||
catch(IOException exc){}
|
||||
finally{
|
||||
if(out != null) try{
|
||||
out.close();
|
||||
}
|
||||
catch(IOException exc){}
|
||||
}
|
||||
|
||||
super.save(f);
|
||||
}
|
||||
|
||||
public void setSelected(boolean value) throws java.beans.PropertyVetoException{
|
||||
super.setSelected(value);
|
||||
|
||||
if(value) textArea.requestFocus();
|
||||
}
|
||||
}
|
||||
116
src/javaeva/gui/JTextoutputFrame.java
Normal file
116
src/javaeva/gui/JTextoutputFrame.java
Normal file
@@ -0,0 +1,116 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 255 $
|
||||
* $Date: 2007-11-15 14:58:12 +0100 (Thu, 15 Nov 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JViewport;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Toolkit;
|
||||
import java.io.Serializable;
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
import javaeva.client.EvAClient;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JTextoutputFrame implements JTextoutputFrameInterface,
|
||||
Serializable {
|
||||
public static boolean TRACE = false;
|
||||
protected String m_Name ="undefined";
|
||||
private transient JTextArea m_TextArea;
|
||||
private boolean m_firstprint = true;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JTextoutputFrame(String Title) {
|
||||
if (TRACE) System.out.println("JTextoutputFrame Constructor");
|
||||
m_Name = Title;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void print (String Text) {
|
||||
//System.out.println("Print:"+Text);
|
||||
if (m_firstprint==true) {
|
||||
m_firstprint = false;
|
||||
createFrame();
|
||||
}
|
||||
m_TextArea.append (Text+"\n");
|
||||
m_TextArea.repaint();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void createFrame() {
|
||||
if (TRACE) System.out.println("JTextoutputFrame createFrame");
|
||||
m_TextArea = new JTextArea(10,80);
|
||||
m_TextArea.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
m_TextArea.setLineWrap(true);
|
||||
m_TextArea.setWrapStyleWord(true);
|
||||
m_TextArea.setEditable(false);
|
||||
m_TextArea.setCaretPosition(0);
|
||||
final JFrame frame = new JEFrame(m_Name);
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAClient.iconLocation);
|
||||
try {
|
||||
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find JavaEvA icon, please move rescoure folder to working directory!");
|
||||
}
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
frame.dispose();
|
||||
}
|
||||
});
|
||||
frame.getContentPane().setLayout(new BorderLayout());
|
||||
//frame.getContentPane().add(new JScrollPane(m_TextArea), BorderLayout.CENTER);
|
||||
final JScrollPane scrollpane = new JScrollPane(m_TextArea);
|
||||
frame.getContentPane().add(scrollpane, BorderLayout.CENTER);
|
||||
scrollpane.getViewport().addChangeListener(new ChangeListener() {
|
||||
private int lastHeight;
|
||||
//
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
JViewport viewport = (JViewport)e.getSource();
|
||||
int Height = viewport.getViewSize().height;
|
||||
if (Height != lastHeight) {
|
||||
lastHeight = Height;
|
||||
int x = Height - viewport.getExtentSize().height;
|
||||
viewport.setViewPosition(new Point(0, x));
|
||||
}
|
||||
}
|
||||
});
|
||||
frame.pack();
|
||||
frame.setSize(800, 400);
|
||||
frame.setVisible(true);
|
||||
frame.setState(Frame.ICONIFIED);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void main( String[] args ){
|
||||
JTextoutputFrame test = new JTextoutputFrame("hi");
|
||||
while(true)
|
||||
test.print("Test 12345");
|
||||
}
|
||||
}
|
||||
23
src/javaeva/gui/JTextoutputFrameInterface.java
Normal file
23
src/javaeva/gui/JTextoutputFrameInterface.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
/*==========================================================================*
|
||||
* INTERFACE DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface JTextoutputFrameInterface {
|
||||
public void print (String Text);
|
||||
}
|
||||
121
src/javaeva/gui/LogPanel.java
Normal file
121
src/javaeva/gui/LogPanel.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 191 $
|
||||
* $Date: 2007-10-23 12:56:51 +0200 (Tue, 23 Oct 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.util.Date;
|
||||
import java.text.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.event.*;
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
import javaeva.client.EvAClient;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class LogPanel extends JPanel {
|
||||
// protected JLabel m_Message = new JLabel("OK");
|
||||
protected JTextArea m_LogText = new JTextArea(10,20);
|
||||
protected boolean m_first = true;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public LogPanel() {
|
||||
m_LogText.setEditable(false);
|
||||
m_LogText.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
|
||||
// m_Message.setBorder(BorderFactory.createCompoundBorder(
|
||||
// BorderFactory.createTitledBorder("Message"),
|
||||
// BorderFactory.createEmptyBorder(0,4,4,4)));
|
||||
JPanel panel_1 = new JPanel();
|
||||
panel_1.setBorder(BorderFactory.createTitledBorder("Info"));
|
||||
panel_1.setLayout(new BorderLayout());
|
||||
final JScrollPane scrollpane = new JScrollPane(m_LogText);
|
||||
panel_1.add(scrollpane, BorderLayout.CENTER);
|
||||
scrollpane.getViewport().addChangeListener(new ChangeListener() {
|
||||
private int lastHeight;
|
||||
//
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
JViewport viewport = (JViewport)e.getSource();
|
||||
int Height = viewport.getViewSize().height;
|
||||
if (Height != lastHeight) {
|
||||
lastHeight = Height;
|
||||
int x = Height - viewport.getExtentSize().height;
|
||||
viewport.setViewPosition(new Point(0, x));
|
||||
}
|
||||
}
|
||||
});
|
||||
setLayout(new BorderLayout());
|
||||
add(panel_1, BorderLayout.CENTER);
|
||||
JPanel panel_2 = new JPanel();
|
||||
panel_2.setLayout(new BorderLayout());
|
||||
// panel_2.add(m_Message,BorderLayout.CENTER);
|
||||
add(panel_2, BorderLayout.SOUTH);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static String getTimestamp() {
|
||||
return (new SimpleDateFormat("HH:mm:ss:")).format(new Date());
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void logMessage(String message) {
|
||||
if (m_first)
|
||||
m_first = false;
|
||||
m_LogText.append("\n");
|
||||
m_LogText.append(LogPanel.getTimestamp() + ' ' + message);
|
||||
}
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// public void statusMessage(String message) {
|
||||
// m_Message.setText(message);
|
||||
// }
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void main(String [] args) {
|
||||
try {
|
||||
final JFrame frame = new JFrame("Log_Panel_Test");
|
||||
frame.getContentPane().setLayout(new BorderLayout());
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAClient.iconLocation);
|
||||
try {
|
||||
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find JavaEvA icon, please move rescoure folder to working directory!");
|
||||
}
|
||||
LogPanel panel = new LogPanel();
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
frame.dispose();
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
panel.logMessage("HI!");
|
||||
// panel.statusMessage("Hi JavaEvA");
|
||||
panel.logMessage("Test");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
47
src/javaeva/gui/Mnemonic.java
Normal file
47
src/javaeva/gui/Mnemonic.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package javaeva.gui;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 12.05.2003
|
||||
* Time: 18:30:44
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Mnemonic{
|
||||
private char mnemonic;
|
||||
private String text;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Mnemonic(String s){
|
||||
setString(s);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setString(String s){
|
||||
StringBuffer buf = new StringBuffer(s);
|
||||
for(int i = 0; i < buf.length(); i++)
|
||||
if(buf.charAt(i) == '&'){
|
||||
buf.deleteCharAt(i);
|
||||
i++;
|
||||
if(i < buf.length() && buf.charAt(i) != '&') mnemonic = buf.charAt(i - 1);
|
||||
}
|
||||
text = buf.toString();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public char getMnemonic(){
|
||||
return mnemonic;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getText(){
|
||||
return text;
|
||||
}
|
||||
}
|
||||
29
src/javaeva/gui/MultiLineString.java
Normal file
29
src/javaeva/gui/MultiLineString.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package javaeva.gui;
|
||||
|
||||
/**
|
||||
* <p>Title: The JavaEvA</p>
|
||||
* <p>Description: </p>
|
||||
* <p>Copyright: Copyright (c) 2003</p>
|
||||
* <p>Company: </p>
|
||||
* @author not attributable
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class MultiLineString {
|
||||
|
||||
String string = "";
|
||||
|
||||
public MultiLineString() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
MultiLineString multiLineString1 = new MultiLineString();
|
||||
}
|
||||
public String getString() {
|
||||
return string;
|
||||
}
|
||||
public void setString(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
}
|
||||
68
src/javaeva/gui/MultiLineStringEditor.java
Normal file
68
src/javaeva/gui/MultiLineStringEditor.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import java.beans.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Title: The JavaEvA</p>
|
||||
* <p>Description: </p>
|
||||
* <p>Copyright: Copyright (c) 2003</p>
|
||||
* <p>Company: </p>
|
||||
* @author not attributable
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class MultiLineStringEditor implements PropertyEditor {
|
||||
protected MultiLineString value; // The value we will be editing.
|
||||
|
||||
public void setValue(Object o) { value=(MultiLineString) o;}
|
||||
public Object getValue() { return value; }
|
||||
public void setAsText(String s) { value.setString(s); }
|
||||
public String getAsText() { return value.getString(); }
|
||||
public String[] getTags() { return null; } // not enumerated; no tags
|
||||
|
||||
// Say that we allow custom editing.
|
||||
public boolean supportsCustomEditor() { return true; }
|
||||
|
||||
// Return the custom editor. This just creates and returns a TextArea
|
||||
// to edit the multi-line text. But it also registers a listener on the
|
||||
// text area to update the value as the user types and to fire the
|
||||
// property change events that property editors are required to fire.
|
||||
public Component getCustomEditor() {
|
||||
final TextArea t = new TextArea(value.string);
|
||||
t.setSize(300, 150); // TextArea doesn't have a preferred size, so set one
|
||||
t.addTextListener(new TextListener() {
|
||||
public void textValueChanged(TextEvent e) {
|
||||
value.setString(t.getText());
|
||||
listeners.firePropertyChange(null, null, null);
|
||||
}
|
||||
});
|
||||
return t;
|
||||
}
|
||||
|
||||
// Visual display of the value, for use with the custom editor.
|
||||
// Just print some instructions and hope they fit in the in the box.
|
||||
// This could be more sophisticated.
|
||||
public boolean isPaintable() { return true; }
|
||||
|
||||
public void paintValue(Graphics g, Rectangle r) {
|
||||
g.setClip(r);
|
||||
g.drawString("Click to edit...", r.x+5, r.y+15);
|
||||
}
|
||||
|
||||
// Important method for code generators. Note that it
|
||||
// ought to add any necessary escape sequences.
|
||||
public String getJavaInitializationString() { return "\"" + value + "\""; }
|
||||
|
||||
// This code uses the PropertyChangeSupport class to maintain a list of
|
||||
// listeners interested in the edits we make to the value.
|
||||
protected PropertyChangeSupport listeners = new PropertyChangeSupport(this);
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
listeners.addPropertyChangeListener(l);
|
||||
}
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
listeners.removePropertyChangeListener(l);
|
||||
}
|
||||
}
|
||||
429
src/javaeva/gui/Plot.java
Normal file
429
src/javaeva/gui/Plot.java
Normal file
@@ -0,0 +1,429 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 322 $
|
||||
* $Date: 2007-12-11 17:24:07 +0100 (Tue, 11 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.awt.AWTException;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.print.PageFormat;
|
||||
import java.awt.print.PrinterException;
|
||||
import java.awt.print.PrinterJob;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import javaeva.client.EvAClient;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import com.sun.image.codec.jpeg.JPEGCodec;
|
||||
import com.sun.image.codec.jpeg.JPEGImageEncoder;
|
||||
import wsi.ra.chart2d.DPointSet;
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Plot implements PlotInterface, Serializable {
|
||||
|
||||
public static boolean TRACE = false;
|
||||
private JFileChooser m_FileChooser;
|
||||
private JPanel m_ButtonPanel;
|
||||
private String m_PlotName;
|
||||
private String m_xname;
|
||||
private String m_yname;
|
||||
protected FunctionArea m_PlotArea;
|
||||
protected JFrame m_Frame;
|
||||
|
||||
/**
|
||||
* You might want to try to assign the x-range as x and y-range as y array parameters.
|
||||
*/
|
||||
public Plot(String PlotName,String xname,String yname,double[] x,double[] y) {
|
||||
if (TRACE) System.out.println("Constructor Plot "+PlotName);
|
||||
m_xname = xname;
|
||||
m_yname = yname;
|
||||
m_PlotName = PlotName;
|
||||
init();
|
||||
DPointSet points = new DPointSet();
|
||||
for (int i=0;i<x.length;i++) {
|
||||
points.addDPoint(x[i],y[i]);
|
||||
}
|
||||
m_PlotArea.addDElement(points);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Plot(String PlotName,String xname,String yname, boolean init) {
|
||||
if (TRACE) System.out.println("Constructor Plot "+PlotName);
|
||||
m_xname = xname;
|
||||
m_yname = yname;
|
||||
m_PlotName = PlotName;
|
||||
if (init)
|
||||
init();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Plot(String PlotName,String xname,String yname) {
|
||||
if (TRACE) System.out.println("Constructor Plot "+PlotName);
|
||||
m_xname = xname;
|
||||
m_yname = yname;
|
||||
m_PlotName = PlotName;
|
||||
init();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void init() {
|
||||
m_Frame = new JEFrame("Plot: "+m_PlotName);
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAClient.iconLocation);
|
||||
try {
|
||||
m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find JavaEvA icon, please move rescoure folder to working directory!");
|
||||
}
|
||||
|
||||
m_ButtonPanel = new JPanel();
|
||||
m_PlotArea = new FunctionArea(m_xname,m_yname);
|
||||
m_ButtonPanel.setLayout( new FlowLayout(FlowLayout.LEFT, 10,10));
|
||||
JButton ClearButton = new JButton ("Clear");
|
||||
ClearButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
clearAll();
|
||||
}
|
||||
});
|
||||
JButton LOGButton = new JButton ("Log/Lin");
|
||||
LOGButton.setToolTipText("Toggle between a linear and a log scale on the y-axis.");
|
||||
LOGButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
m_PlotArea.toggleLog();
|
||||
}
|
||||
});
|
||||
JButton ExportButton = new JButton ("Export");
|
||||
ExportButton.setToolTipText("Exports the graph data to a simple ascii file.");
|
||||
ExportButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
m_PlotArea.exportToAscii();
|
||||
}
|
||||
});
|
||||
// Test Thomas start
|
||||
|
||||
// Test Thomas end
|
||||
JButton PrintButton = new JButton ("Print");
|
||||
PrintButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
Robot robot = new Robot();
|
||||
// Capture a particular area on the screen
|
||||
int x = 100;
|
||||
int y = 100;
|
||||
int width = 200;
|
||||
int height = 200;
|
||||
Rectangle area = new Rectangle(x, y, width, height);
|
||||
BufferedImage bufferedImage = robot.createScreenCapture(area);
|
||||
|
||||
// Capture the whole screen
|
||||
area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
|
||||
bufferedImage = robot.createScreenCapture(area);
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream("test.jpeg");
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
|
||||
encoder.encode(bufferedImage);
|
||||
bos.close();
|
||||
} catch (Exception eee) {}
|
||||
|
||||
|
||||
} catch (AWTException ee) {
|
||||
ee.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
PrinterJob job = PrinterJob.getPrinterJob();
|
||||
// PageFormat format = job.defaultPage();
|
||||
// job.setPrintable(m_PlotArea, format);
|
||||
// if (job.printDialog()) {
|
||||
// // If not cancelled, start printing! This will call the print()
|
||||
// // method defined by the Printable interface.
|
||||
// try { job.print(); }
|
||||
// catch (PrinterException ee) {
|
||||
// System.out.println(ee);
|
||||
// ee.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
///////////////////////////////////////////////
|
||||
//PagePrinter pp = new PagePrinter(m_PlotArea,m_PlotArea.getGraphics(),job.defaultPage());
|
||||
//pp.print();
|
||||
// public int print( Graphics g, PageFormat pf, int pi ){
|
||||
// m_PlotArea.print(m_PlotArea.getGraphics(), new PageFormat(),0);
|
||||
// Obtain a java.awt.print.PrinterJob (not java.awt.PrintJob)
|
||||
//PrinterJob job = PrinterJob.getPrinterJob();
|
||||
// Tell the PrinterJob to print us (since we implement Printable)
|
||||
// using the default page layout
|
||||
PageFormat page = job.defaultPage();
|
||||
|
||||
job.setPrintable(m_PlotArea, page);
|
||||
// Display the print dialog that allows the user to set options.
|
||||
// The method returns false if the user cancelled the print request
|
||||
if (job.printDialog()) {
|
||||
// If not cancelled, start printing! This will call the print()
|
||||
// method defined by the Printable interface.
|
||||
try { job.print(); }
|
||||
catch (PrinterException ee) {
|
||||
System.out.println(ee);
|
||||
ee.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
JButton OpenButton = new JButton ("Open..");
|
||||
OpenButton.setToolTipText("Load a old plot");
|
||||
OpenButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
m_PlotArea.openObject();
|
||||
}
|
||||
});
|
||||
JButton SaveButton = new JButton ("Save..");
|
||||
SaveButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
m_PlotArea.saveObject();
|
||||
}
|
||||
});
|
||||
JButton SaveJPGButton = new JButton ("Save as JPG");
|
||||
SaveJPGButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String outfile ="";
|
||||
try {
|
||||
Robot robot = new Robot();
|
||||
Rectangle area;
|
||||
area = m_Frame.getBounds();
|
||||
BufferedImage bufferedImage = robot.createScreenCapture(area);
|
||||
JFileChooser fc = new JFileChooser();
|
||||
if (fc.showSaveDialog(m_Frame) != JFileChooser.APPROVE_OPTION) return;
|
||||
System.out.println("Name " + outfile);
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(fc.getSelectedFile().getAbsolutePath()+".jpeg");
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
|
||||
encoder.encode(bufferedImage);
|
||||
bos.close();
|
||||
} catch (Exception eee) {}
|
||||
|
||||
|
||||
} catch (AWTException ee) {
|
||||
ee.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
m_ButtonPanel.add(ClearButton);
|
||||
m_ButtonPanel.add(LOGButton);
|
||||
m_ButtonPanel.add(ExportButton);
|
||||
m_ButtonPanel.add(PrintButton);
|
||||
m_ButtonPanel.add(OpenButton);
|
||||
m_ButtonPanel.add(SaveButton);
|
||||
m_ButtonPanel.add(SaveJPGButton);
|
||||
// getContentPane().smultetLayout( new GridLayout(1, 4) );
|
||||
m_Frame.getContentPane().add(m_ButtonPanel,"South");
|
||||
m_Frame.getContentPane().add(m_PlotArea,"North");
|
||||
m_Frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
m_PlotArea.clearAll(); // this was a memory leak
|
||||
m_PlotArea = null;
|
||||
m_Frame.dispose();
|
||||
}
|
||||
});
|
||||
m_Frame.pack();
|
||||
m_Frame.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the Plot object is valid.
|
||||
*
|
||||
* @return true if the Plot object is valid
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return (m_Frame != null) && (m_PlotArea != null);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setConnectedPoint (double x,double y,int func) {
|
||||
if (TRACE) System.out.println("size before is " + m_PlotArea.getPointCount(func));
|
||||
m_PlotArea.setConnectedPoint(x,y,func);
|
||||
if (TRACE) {
|
||||
System.out.println("added "+x+"/" + y + " to graph "+ func);
|
||||
System.out.println("size is now " + m_PlotArea.getPointCount(func));
|
||||
}
|
||||
}
|
||||
|
||||
public int getPointCount(int graphLabel) {
|
||||
return m_PlotArea.getPointCount(graphLabel);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addGraph (int g1,int g2, boolean forceAdd) {
|
||||
m_PlotArea.addGraph(g1, g2, forceAdd);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setUnconnectedPoint (double x, double y,int GraphLabel) {
|
||||
m_PlotArea.setUnconnectedPoint(x,y,GraphLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void clearAll () {
|
||||
m_PlotArea.clearAll();
|
||||
m_PlotArea.removeAllDElements();
|
||||
m_Frame.repaint();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void clearGraph (int GraphNumber) {
|
||||
m_PlotArea.clearGraph(GraphNumber);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setInfoString (int GraphLabel, String Info, float stroke) {
|
||||
m_PlotArea.setInfoString(GraphLabel,Info,stroke);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void jump () {
|
||||
m_PlotArea.jump();
|
||||
}
|
||||
/**
|
||||
*/
|
||||
protected Object openObject() {
|
||||
if (m_FileChooser == null)
|
||||
createFileChooser();
|
||||
int returnVal = m_FileChooser.showOpenDialog(m_Frame);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File selected = m_FileChooser.getSelectedFile();
|
||||
try {
|
||||
ObjectInputStream oi = new ObjectInputStream(new BufferedInputStream(new FileInputStream(selected)));
|
||||
Object obj = oi.readObject();
|
||||
oi.close();
|
||||
Class ClassType = Class.forName("FunctionArea");
|
||||
if (!ClassType.isAssignableFrom(obj.getClass()))
|
||||
throw new Exception("Object not of type: " + ClassType.getName());
|
||||
return obj;
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(m_Frame,
|
||||
"Couldn't read object: "
|
||||
+ selected.getName()
|
||||
+ "\n" + ex.getMessage(),
|
||||
"Open object file",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void saveObject(Object object) {
|
||||
if (m_FileChooser == null)
|
||||
createFileChooser();
|
||||
int returnVal = m_FileChooser.showSaveDialog(m_Frame);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File sFile = m_FileChooser.getSelectedFile();
|
||||
try {
|
||||
ObjectOutputStream oo = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(sFile)));
|
||||
oo.writeObject(object);
|
||||
oo.close();
|
||||
} catch (IOException ex) {
|
||||
JOptionPane.showMessageDialog(m_Frame,
|
||||
"Couldn't write to file: "
|
||||
+ sFile.getName()
|
||||
+ "\n" + ex.getMessage(),
|
||||
"Save object",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void createFileChooser() {
|
||||
m_FileChooser = new JFileChooser(new File("/resources"));
|
||||
m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getName() {
|
||||
return this.m_PlotName;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public FunctionArea getFunctionArea() {
|
||||
return m_PlotArea;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void dispose() {
|
||||
m_Frame.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Just for testing the Plot class.
|
||||
*/
|
||||
public static void main( String[] args ){
|
||||
Plot plot = new Plot("Plot-Test","x-value","y-value");
|
||||
plot.init();
|
||||
double x;
|
||||
for (x= 0; x <6000; x++) {
|
||||
//double y = SpecialFunction.getnormcdf(x);
|
||||
// double yy = 0.5*SpecialFunction.getnormpdf(x);
|
||||
double n = Math.sin(((double)x/1000*Math.PI));
|
||||
//plot.setConnectedPoint(x,Math.sin(x),0);
|
||||
//plot.setConnectedPoint(x,Math.cos(x),1);
|
||||
//plot.setConnectedPoint(x,y,0);
|
||||
plot.setConnectedPoint(x,n,1);
|
||||
}
|
||||
//plot.addGraph(1,2);
|
||||
}
|
||||
}
|
||||
|
||||
37
src/javaeva/gui/PlotInterface.java
Normal file
37
src/javaeva/gui/PlotInterface.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 322 $
|
||||
* $Date: 2007-12-11 17:24:07 +0100 (Tue, 11 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
public interface PlotInterface {
|
||||
public void setConnectedPoint (double x,double y,int GraphLabel);
|
||||
|
||||
/**
|
||||
* Add two graphs to form an average graph
|
||||
*
|
||||
* @param g1 graph object one
|
||||
* @param g2 graph object two
|
||||
* @param forceAdd if the graph mismatch in point counts, try to add them anyway in a useful manner.
|
||||
*/
|
||||
public void addGraph (int g1,int g2, boolean forceAdd);
|
||||
public void setUnconnectedPoint (double x, double y,int GraphLabel);
|
||||
public void clearAll ();
|
||||
public void clearGraph (int GraphNumber);
|
||||
public void setInfoString (int GraphLabel, String Info, float stroke);
|
||||
public void jump ();
|
||||
public String getName();
|
||||
public int getPointCount(int graphLabel);
|
||||
// public FunctionArea getFunctionArea(); // this is bad for RMI
|
||||
public boolean isValid();
|
||||
public void init();
|
||||
}
|
||||
|
||||
50
src/javaeva/gui/PropertyBoolSelector.java
Normal file
50
src/javaeva/gui/PropertyBoolSelector.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.*;
|
||||
import javax.swing.*;
|
||||
import sun.beans.editors.BoolEditor;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PropertyBoolSelector extends JCheckBox {
|
||||
private BoolEditor m_Editor;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PropertyBoolSelector(PropertyEditor pe) {
|
||||
super();
|
||||
m_Editor = (BoolEditor) pe;
|
||||
if (m_Editor.getAsText().equals("True"))
|
||||
setSelected(true);
|
||||
else
|
||||
setSelected(false);
|
||||
|
||||
addItemListener(new ItemListener () {
|
||||
public void itemStateChanged (ItemEvent evt) {
|
||||
if (evt.getStateChange() == evt.SELECTED) {
|
||||
m_Editor.setValue(Boolean.TRUE);
|
||||
}
|
||||
if (evt.getStateChange() == evt.DESELECTED) {
|
||||
m_Editor.setValue(Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
67
src/javaeva/gui/PropertyDialog.java
Normal file
67
src/javaeva/gui/PropertyDialog.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 14 $
|
||||
* $Date: 2006-12-18 16:32:23 +0100 (Mon, 18 Dec 2006) $
|
||||
* $Author: marcekro $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javaeva.tools.EVAHELP;
|
||||
import java.awt.Component;
|
||||
import java.awt.Toolkit;
|
||||
import java.beans.PropertyEditor;
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.BorderLayout;
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
import javaeva.client.EvAClient;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PropertyDialog extends JEFrame {
|
||||
private PropertyEditor m_Editor;
|
||||
private Component m_EditorComponent;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PropertyDialog (PropertyEditor Editor,String Title, int x, int y) {
|
||||
super(EVAHELP.cutClassName (Editor.getValue().getClass().getName())); // that was the long class name !!
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAClient.iconLocation);
|
||||
try {
|
||||
setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find JavaEvA icon, please move rescoure folder to working directory!");
|
||||
}
|
||||
//System.out.println("PropertyDialog.Constructor of "+ Title);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
e.getWindow().dispose();
|
||||
}
|
||||
});
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
m_Editor = Editor;
|
||||
m_EditorComponent = Editor.getCustomEditor();
|
||||
getContentPane().add(m_EditorComponent, BorderLayout.CENTER);
|
||||
pack();
|
||||
setLocation(x, y);
|
||||
setVisible(true);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PropertyEditor getEditor() {
|
||||
return m_Editor;
|
||||
}
|
||||
}
|
||||
|
||||
40
src/javaeva/gui/PropertyDoubleArray.java
Normal file
40
src/javaeva/gui/PropertyDoubleArray.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package javaeva.gui;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 05.03.2004
|
||||
* Time: 13:48:47
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class PropertyDoubleArray implements java.io.Serializable {
|
||||
public double[] m_DoubleArray;
|
||||
|
||||
public PropertyDoubleArray(double[] d) {
|
||||
this.m_DoubleArray = d;
|
||||
}
|
||||
|
||||
public PropertyDoubleArray(PropertyDoubleArray d) {
|
||||
this.m_DoubleArray = new double[d.m_DoubleArray.length];
|
||||
System.arraycopy(d.m_DoubleArray, 0, this.m_DoubleArray, 0, this.m_DoubleArray.length);
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return (Object) new PropertyDoubleArray(this);
|
||||
}
|
||||
|
||||
/** This method will allow you to set the value of the double array
|
||||
* @param d The double[]
|
||||
*/
|
||||
public void setDoubleArray(double[] d) {
|
||||
this.m_DoubleArray = d;
|
||||
}
|
||||
|
||||
/** This method will return the complete name of the file
|
||||
* which filepath
|
||||
* @return The complete filename with path.
|
||||
*/
|
||||
public double[] getDoubleArray() {
|
||||
return this.m_DoubleArray;
|
||||
}
|
||||
}
|
||||
167
src/javaeva/gui/PropertyEditorProvider.java
Normal file
167
src/javaeva/gui/PropertyEditorProvider.java
Normal file
@@ -0,0 +1,167 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyEditorManager;
|
||||
|
||||
import javaeva.server.go.TerminatorInterface;
|
||||
import javaeva.server.go.individuals.codings.gp.GPArea;
|
||||
import javaeva.tools.SelectedTag;
|
||||
|
||||
import sun.beans.editors.DoubleEditor;
|
||||
import sun.beans.editors.IntEditor;
|
||||
import sun.beans.editors.BoolEditor;
|
||||
import sun.beans.editors.ByteEditor;
|
||||
import sun.beans.editors.ColorEditor;
|
||||
import sun.beans.editors.ShortEditor;
|
||||
import sun.beans.editors.FloatEditor;
|
||||
import sun.beans.editors.LongEditor;
|
||||
import sun.beans.editors.StringEditor;
|
||||
|
||||
public class PropertyEditorProvider {
|
||||
final static boolean TRACE = false;
|
||||
// if true, we use the GenericObjectEditor whenever no specific one is registered, so keep it true
|
||||
// unless you want to register every single possibility.
|
||||
public static boolean useDefaultGOE = true;
|
||||
|
||||
public static PropertyEditor findEditor(Class cls) {
|
||||
PropertyEditor editor = null;
|
||||
editor = PropertyEditorManager.findEditor(cls);
|
||||
|
||||
if (TRACE) System.out.println((editor == null ) ? "No editor from PEM" : ("Found " + editor.getClass()));
|
||||
if ((editor == null) && useDefaultGOE ) {
|
||||
editor = new GenericObjectEditor();
|
||||
if (TRACE) System.out.println("using GOE");
|
||||
}
|
||||
return editor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
private PropertyEditor makeEditor(PropertyDescriptor prop, Object value) {
|
||||
Class type = prop.getPropertyType();
|
||||
Class pec = prop.getPropertyEditorClass();
|
||||
|
||||
PropertyEditor editor = null;
|
||||
//Class pec = m_Properties[i].getPropertyEditorClass();
|
||||
if (pec != null) {
|
||||
try {
|
||||
editor = (PropertyEditor)pec.newInstance();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
if (editor == null) {
|
||||
if (TRACE) System.out.println("PropertySheetPanel.setTarget(): No editor from pec.");
|
||||
if (STREICHE) {
|
||||
//@todo Streiche: Here i'm looking for a specialized editor
|
||||
//if (TRACE) System.out.println("PropertySheetPanel.setTarget(): trying to find specialised editor for "+value.getClass()+".");
|
||||
if (value != null) editor = PropertyEditorManager.findEditor(value.getClass());
|
||||
if (TRACE) {
|
||||
if (editor == null) System.out.println("PropertySheetPanel.setTarget(): Found no editor.");
|
||||
else System.out.println("PropertySheetPanel.setTarget(): Found " + editor.getClass()+".");
|
||||
}
|
||||
if (editor == null) editor = PropertyEditorManager.findEditor(type);
|
||||
} else {
|
||||
editor = PropertyEditorManager.findEditor(type);
|
||||
}
|
||||
}
|
||||
if ((TRACE) && (editor != null)) System.out.println("PropertySheetPanel.setTarget(): editor="+editor.getClass().getName());
|
||||
if (editor == null) {
|
||||
// If it's a user-defined property we give a warning.
|
||||
String getterClass = prop.getReadMethod().getDeclaringClass().getName();
|
||||
if (getterClass.indexOf("java.") != 0) {
|
||||
System.err.println("Warning: Can't find public property editor"
|
||||
+ " for property \"" + prop.getDisplayName() + "\" (class \""
|
||||
+ type.getName() + "\"). Skipping.");
|
||||
}
|
||||
} else if (editor instanceof GenericObjectEditor) ((GenericObjectEditor) editor).setClassType(type);
|
||||
|
||||
return editor;
|
||||
}
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @param prop
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static PropertyEditor findEditor(PropertyDescriptor prop, Object value) {
|
||||
PropertyEditor editor = null;
|
||||
Class pec = prop.getPropertyEditorClass();
|
||||
Class type = prop.getPropertyType();
|
||||
|
||||
try {
|
||||
if (pec != null) editor = (PropertyEditor)pec.newInstance();
|
||||
} catch (Exception e) {
|
||||
editor = null;
|
||||
}
|
||||
|
||||
if (editor == null) {
|
||||
if (TRACE) System.out.println("PropertySheetPanel.makeEditor(): No editor from PEC.");
|
||||
|
||||
//@todo Streiche: Here i'm looking for a specialized editor
|
||||
//if (TRACE) System.out.println("PropertySheetPanel.setTarget(): trying to find specialised editor for "+value.getClass()+".");
|
||||
if (value != null) editor = PropertyEditorManager.findEditor(value.getClass());
|
||||
if (TRACE) System.out.println((editor == null ) ? "No editor from PEM" : ("Found " + editor.getClass()));
|
||||
|
||||
if (editor == null) editor = PropertyEditorManager.findEditor(type);
|
||||
if (TRACE) System.out.println((editor == null ) ? "No editor from PEM by type" : ("Found " + editor.getClass()));
|
||||
if ((editor == null) && useDefaultGOE ) {
|
||||
editor = new GenericObjectEditor();
|
||||
if (TRACE) System.out.println("using GOE");
|
||||
}
|
||||
}
|
||||
if (editor == null) {
|
||||
// If it's a user-defined property we give a warning.
|
||||
String getterClass = prop.getReadMethod().getDeclaringClass().getName();
|
||||
if (getterClass.indexOf("java.") != 0) {
|
||||
System.err.println("Warning: Can't find public property editor"
|
||||
+ " for property \"" + prop.getDisplayName() + "\" (class \""
|
||||
+ type.getName() + "\"). Skipping.");
|
||||
}
|
||||
} else if (editor instanceof GenericObjectEditor) {
|
||||
// hier erst noch das object setzen?
|
||||
// ((GenericObjectEditor) editor).getCustomEditor();
|
||||
((GenericObjectEditor) editor).setClassType(type);
|
||||
}
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static void installEditors() {
|
||||
PropertyEditorManager.registerEditor(SelectedTag.class, TagEditor.class);
|
||||
PropertyEditorManager.registerEditor(double[].class, GenericArrayEditor.class);
|
||||
PropertyEditorManager.registerEditor(TerminatorInterface[].class, GenericArrayEditor.class);
|
||||
|
||||
PropertyEditorManager.registerEditor(Double.class, DoubleEditor.class);
|
||||
PropertyEditorManager.registerEditor(Integer.class, IntEditor.class);
|
||||
PropertyEditorManager.registerEditor(Boolean.class, BoolEditor.class);
|
||||
PropertyEditorManager.registerEditor(byte.class, ByteEditor.class);
|
||||
PropertyEditorManager.registerEditor(Color.class, ColorEditor.class);
|
||||
PropertyEditorManager.registerEditor(short.class, ShortEditor.class);
|
||||
PropertyEditorManager.registerEditor(float.class, FloatEditor.class);
|
||||
PropertyEditorManager.registerEditor(long.class, LongEditor.class);
|
||||
PropertyEditorManager.registerEditor(String.class, StringEditor.class);
|
||||
|
||||
// The Editor for the new GO
|
||||
|
||||
// // Traveling Salesman problem
|
||||
PropertyEditorManager.registerEditor(GPArea.class , GenericAreaEditor.class);
|
||||
PropertyEditorManager.registerEditor(PropertyDoubleArray.class , GenericDoubleArrayEditor.class);
|
||||
PropertyEditorManager.registerEditor(PropertyIntArray.class , GenericIntArrayEditor.class);
|
||||
PropertyEditorManager.registerEditor(PropertyEpsilonThreshold.class , GenericEpsilonThresholdEditor.class);
|
||||
PropertyEditorManager.registerEditor(PropertyEpsilonConstraint.class , GenericEpsilonConstraintEditor.class);
|
||||
PropertyEditorManager.registerEditor(PropertyWeightedLPTchebycheff.class, GenericWeigthedLPTchebycheffEditor.class);
|
||||
PropertyEditorManager.registerEditor(PropertyStringList.class , GenericStringListEditor.class);
|
||||
PropertyEditorManager.registerEditor(PropertyFilePath.class , GenericFilePathEditor.class);
|
||||
PropertyEditorManager.registerEditor(PropertyRemoteServers.class , GenericRemoteServersEditor.class);
|
||||
PropertyEditorManager.registerEditor(PropertyOptimizationObjectives.class , GenericOptimizationObjectivesEditor.class);
|
||||
PropertyEditorManager.registerEditor(PropertyOptimizationObjectivesWithParam.class , GenericOptimizationObjectivesWithParamEditor.class);
|
||||
PropertyEditorManager.registerEditor(javaeva.gui.MultiLineString.class, javaeva.gui.MultiLineStringEditor.class);
|
||||
}
|
||||
}
|
||||
29
src/javaeva/gui/PropertyEpsilonConstraint.java
Normal file
29
src/javaeva/gui/PropertyEpsilonConstraint.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package javaeva.gui;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 14.07.2005
|
||||
* Time: 16:15:47
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class PropertyEpsilonConstraint implements java.io.Serializable {
|
||||
|
||||
public double[] m_TargetValue;
|
||||
public int m_OptimizeObjective;
|
||||
|
||||
public PropertyEpsilonConstraint() {
|
||||
}
|
||||
|
||||
public PropertyEpsilonConstraint(PropertyEpsilonConstraint e) {
|
||||
if (e.m_TargetValue != null) {
|
||||
this.m_TargetValue = new double[e.m_TargetValue.length];
|
||||
System.arraycopy(e.m_TargetValue, 0, this.m_TargetValue, 0, this.m_TargetValue.length);
|
||||
}
|
||||
this.m_OptimizeObjective = e.m_OptimizeObjective;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return (Object) new PropertyEpsilonConstraint(this);
|
||||
}
|
||||
}
|
||||
34
src/javaeva/gui/PropertyEpsilonThreshold.java
Normal file
34
src/javaeva/gui/PropertyEpsilonThreshold.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package javaeva.gui;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 05.03.2004
|
||||
* Time: 14:56:58
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class PropertyEpsilonThreshold implements java.io.Serializable {
|
||||
|
||||
public double[] m_Punishment;
|
||||
public double[] m_TargetValue;
|
||||
public int m_OptimizeObjective;
|
||||
|
||||
public PropertyEpsilonThreshold() {
|
||||
}
|
||||
|
||||
public PropertyEpsilonThreshold(PropertyEpsilonThreshold e) {
|
||||
if (e.m_TargetValue != null) {
|
||||
this.m_TargetValue = new double[e.m_TargetValue.length];
|
||||
System.arraycopy(e.m_TargetValue, 0, this.m_TargetValue, 0, this.m_TargetValue.length);
|
||||
}
|
||||
if (e.m_Punishment != null) {
|
||||
this.m_Punishment = new double[e.m_Punishment.length];
|
||||
System.arraycopy(e.m_Punishment, 0, this.m_Punishment, 0, this.m_Punishment.length);
|
||||
}
|
||||
this.m_OptimizeObjective = e.m_OptimizeObjective;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return (Object) new PropertyEpsilonThreshold(this);
|
||||
}
|
||||
}
|
||||
62
src/javaeva/gui/PropertyFilePath.java
Normal file
62
src/javaeva/gui/PropertyFilePath.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package javaeva.gui;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 28.08.2003
|
||||
* Time: 11:10:28
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class PropertyFilePath implements java.io.Serializable {
|
||||
|
||||
public String FileName = "";
|
||||
public String FilePath = "";
|
||||
public String FileExtension = "";
|
||||
|
||||
public PropertyFilePath(String s) {
|
||||
this.setCompleteFilePath(s);
|
||||
}
|
||||
|
||||
public PropertyFilePath(PropertyFilePath d) {
|
||||
this.FileName = d.FileName;
|
||||
this.FilePath = d.FilePath;
|
||||
this.FileExtension = d.FileExtension;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return (Object) new PropertyFilePath(this);
|
||||
}
|
||||
|
||||
/** This method will allow you to set a complete string
|
||||
* which will be separated into Path, Name and extension
|
||||
* @param s The complete filepath and filename
|
||||
*/
|
||||
public void setCompleteFilePath(String s) {
|
||||
boolean trace = false;
|
||||
String filesep;
|
||||
|
||||
String old = this.getCompleteFilePath();
|
||||
try {
|
||||
if (trace) System.out.println("Complete Filename: " +s);
|
||||
filesep = System.getProperty("file.separator");
|
||||
if (trace) System.out.println("File.Separator: " +filesep);
|
||||
this.FileName = s.substring(s.lastIndexOf(filesep)+1);
|
||||
this.FileExtension = this.FileName.substring(this.FileName.lastIndexOf("."));
|
||||
this.FilePath = s.substring(0, s.lastIndexOf(filesep)+1);
|
||||
|
||||
if (trace) System.out.println("FilePath: " +this.FilePath);
|
||||
if (trace) System.out.println("Filename: " + this.FileName);
|
||||
if (trace) System.out.println("Fileext.: " + this.FileExtension);
|
||||
} catch (Exception e) {
|
||||
this.setCompleteFilePath(old);
|
||||
}
|
||||
}
|
||||
|
||||
/** This method will return the complete name of the file
|
||||
* which filepath
|
||||
* @return The complete filename with path.
|
||||
*/
|
||||
public String getCompleteFilePath() {
|
||||
return this.FilePath + this.FileName;
|
||||
}
|
||||
}
|
||||
39
src/javaeva/gui/PropertyIntArray.java
Normal file
39
src/javaeva/gui/PropertyIntArray.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package javaeva.gui;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 12.09.2005
|
||||
* Time: 10:18:50
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class PropertyIntArray implements java.io.Serializable {
|
||||
public int[] m_IntArray;
|
||||
|
||||
public PropertyIntArray(int[] d) {
|
||||
this.m_IntArray = d;
|
||||
}
|
||||
|
||||
public PropertyIntArray(PropertyIntArray d) {
|
||||
this.m_IntArray = new int[d.m_IntArray.length];
|
||||
System.arraycopy(d.m_IntArray, 0, this.m_IntArray, 0, this.m_IntArray.length);
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return (Object) new PropertyIntArray(this);
|
||||
}
|
||||
|
||||
/** This method will allow you to set the value of the double array
|
||||
* @param d The int[]
|
||||
*/
|
||||
public void setIntArray(int[] d) {
|
||||
this.m_IntArray = d;
|
||||
}
|
||||
|
||||
/** This method will return the int array
|
||||
* @return The int array
|
||||
*/
|
||||
public int[] getIntArray() {
|
||||
return this.m_IntArray;
|
||||
}
|
||||
}
|
||||
84
src/javaeva/gui/PropertyOptimizationObjectives.java
Normal file
84
src/javaeva/gui/PropertyOptimizationObjectives.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javaeva.server.go.problems.InterfaceOptimizationObjective;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 14.01.2005
|
||||
* Time: 17:11:31
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class PropertyOptimizationObjectives implements java.io.Serializable {
|
||||
public InterfaceOptimizationObjective[] m_AvailableObjectives;
|
||||
public InterfaceOptimizationObjective[] m_SelectedObjectives;
|
||||
|
||||
public PropertyOptimizationObjectives(InterfaceOptimizationObjective[] d) {
|
||||
this.m_AvailableObjectives = d;
|
||||
this.m_SelectedObjectives = null;
|
||||
}
|
||||
public PropertyOptimizationObjectives(PropertyOptimizationObjectives d) {
|
||||
this.m_AvailableObjectives = new InterfaceOptimizationObjective[d.m_AvailableObjectives.length];
|
||||
for (int i = 0; i < this.m_AvailableObjectives.length; i++) {
|
||||
this.m_AvailableObjectives[i] = (InterfaceOptimizationObjective)d.m_AvailableObjectives[i].clone();
|
||||
}
|
||||
this.m_SelectedObjectives = new InterfaceOptimizationObjective[d.m_SelectedObjectives.length];
|
||||
for (int i = 0; i < this.m_SelectedObjectives.length; i++) {
|
||||
this.m_SelectedObjectives[i] = (InterfaceOptimizationObjective)d.m_SelectedObjectives[i].clone();
|
||||
}
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return (Object) new PropertyOptimizationObjectives(this);
|
||||
}
|
||||
|
||||
/** This method will allow you to set the value of the InterfaceOptimizationTarget array
|
||||
* @param d The InterfaceOptimizationTarget[]
|
||||
*/
|
||||
public void setSelectedTargets(InterfaceOptimizationObjective[] d) {
|
||||
this.m_SelectedObjectives = d;
|
||||
}
|
||||
|
||||
/** This method will return the InterfaceOptimizationTarget array
|
||||
* @return The InterfaceOptimizationTarget[].
|
||||
*/
|
||||
public InterfaceOptimizationObjective[] getSelectedTargets() {
|
||||
return this.m_SelectedObjectives;
|
||||
}
|
||||
|
||||
/** This method will return the InterfaceOptimizationTarget array
|
||||
* @return The InterfaceOptimizationTarget[].
|
||||
*/
|
||||
public InterfaceOptimizationObjective[] getAvailableTargets() {
|
||||
return this.m_AvailableObjectives;
|
||||
}
|
||||
|
||||
/** This method allows you to remove a Target from the list
|
||||
* @param index The index of the target to be removed.
|
||||
*/
|
||||
public void removeTarget(int index) {
|
||||
if ((index < 0) || (index >= this.m_SelectedObjectives.length)) return;
|
||||
|
||||
InterfaceOptimizationObjective[] newList = new InterfaceOptimizationObjective[this.m_SelectedObjectives.length-1];
|
||||
int j = 0;
|
||||
for (int i = 0; i < this.m_SelectedObjectives.length; i++) {
|
||||
if (index != i) {
|
||||
newList[j] = this.m_SelectedObjectives[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
this.m_SelectedObjectives = newList;
|
||||
}
|
||||
|
||||
/** This method allows you to add a new target to the list
|
||||
* @param optTarget
|
||||
*/
|
||||
public void addTarget(InterfaceOptimizationObjective optTarget) {
|
||||
InterfaceOptimizationObjective[] newList = new InterfaceOptimizationObjective[this.m_SelectedObjectives.length+1];
|
||||
for (int i = 0; i < this.m_SelectedObjectives.length; i++) {
|
||||
newList[i] = this.m_SelectedObjectives[i];
|
||||
}
|
||||
newList[this.m_SelectedObjectives.length] = optTarget;
|
||||
this.m_SelectedObjectives = newList;
|
||||
}
|
||||
}
|
||||
161
src/javaeva/gui/PropertyOptimizationObjectivesWithParam.java
Normal file
161
src/javaeva/gui/PropertyOptimizationObjectivesWithParam.java
Normal file
@@ -0,0 +1,161 @@
|
||||
package javaeva.gui;
|
||||
|
||||
import javaeva.server.go.problems.InterfaceOptimizationObjective;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 18.01.2005
|
||||
* Time: 13:35:24
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class PropertyOptimizationObjectivesWithParam implements java.io.Serializable {
|
||||
|
||||
public InterfaceOptimizationObjective[] m_AvailableObjectives;
|
||||
public InterfaceOptimizationObjective[] m_SelectedObjectives;
|
||||
public double[] m_Weights;
|
||||
public String m_DescriptiveString = "No Description given.";
|
||||
public String m_WeightsLabel = "-";
|
||||
public boolean m_NormalizationEnabled = true;
|
||||
|
||||
public PropertyOptimizationObjectivesWithParam(InterfaceOptimizationObjective[] d) {
|
||||
this.m_AvailableObjectives = d;
|
||||
this.m_SelectedObjectives = null;
|
||||
}
|
||||
public PropertyOptimizationObjectivesWithParam(PropertyOptimizationObjectivesWithParam d) {
|
||||
this.m_DescriptiveString = d.m_DescriptiveString;
|
||||
this.m_WeightsLabel = d.m_WeightsLabel;
|
||||
this.m_NormalizationEnabled = d.m_NormalizationEnabled;
|
||||
this.m_AvailableObjectives = new InterfaceOptimizationObjective[d.m_AvailableObjectives.length];
|
||||
for (int i = 0; i < this.m_AvailableObjectives.length; i++) {
|
||||
this.m_AvailableObjectives[i] = (InterfaceOptimizationObjective)d.m_AvailableObjectives[i].clone();
|
||||
}
|
||||
this.m_SelectedObjectives = new InterfaceOptimizationObjective[d.m_SelectedObjectives.length];
|
||||
for (int i = 0; i < this.m_SelectedObjectives.length; i++) {
|
||||
this.m_SelectedObjectives[i] = (InterfaceOptimizationObjective)d.m_SelectedObjectives[i].clone();
|
||||
}
|
||||
if (d.m_Weights != null) {
|
||||
this.m_Weights = new double[d.m_Weights.length];
|
||||
System.arraycopy(d.m_Weights, 0, this.m_Weights, 0, this.m_Weights.length);
|
||||
}
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return (Object) new PropertyOptimizationObjectivesWithParam(this);
|
||||
}
|
||||
|
||||
/** This method will allow you to set the value of the InterfaceOptimizationTarget array
|
||||
* @param d The InterfaceOptimizationTarget[]
|
||||
*/
|
||||
public void setSelectedTargets(InterfaceOptimizationObjective[] d) {
|
||||
this.m_SelectedObjectives = d;
|
||||
|
||||
if (this.m_Weights == null) {
|
||||
this.m_Weights = new double[d.length];
|
||||
for (int i = 0; i < this.m_Weights.length; i++) this.m_Weights[i] = 1.0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (d.length == this.m_Weights.length) return;
|
||||
|
||||
if (d.length > this.m_Weights.length) {
|
||||
double[] newWeights = new double[d.length];
|
||||
for (int i = 0; i < this.m_Weights.length; i++) newWeights[i] = this.m_Weights[i];
|
||||
this.m_Weights = newWeights;
|
||||
} else {
|
||||
double[] newWeights = new double[d.length];
|
||||
for (int i = 0; i < d.length; i++) newWeights[i] = this.m_Weights[i];
|
||||
this.m_Weights = newWeights;
|
||||
}
|
||||
}
|
||||
|
||||
/** This method will return the InterfaceOptimizationTarget array
|
||||
* @return The InterfaceOptimizationTarget[].
|
||||
*/
|
||||
public InterfaceOptimizationObjective[] getSelectedTargets() {
|
||||
return this.m_SelectedObjectives;
|
||||
}
|
||||
|
||||
/** This method will return the InterfaceOptimizationTarget array
|
||||
* @return The InterfaceOptimizationTarget[].
|
||||
*/
|
||||
public InterfaceOptimizationObjective[] getAvailableTargets() {
|
||||
return this.m_AvailableObjectives;
|
||||
}
|
||||
|
||||
/** This method allows you to read the weights
|
||||
* @return the weights
|
||||
*/
|
||||
public double[] getWeights() {
|
||||
return this.m_Weights;
|
||||
}
|
||||
public void setWeights(double[] d) {
|
||||
this.m_Weights = d;
|
||||
}
|
||||
|
||||
/** This method allows you to set/get the descriptive string
|
||||
* @return the string
|
||||
*/
|
||||
public String getDescriptiveString() {
|
||||
return this.m_DescriptiveString;
|
||||
}
|
||||
public void setDescriptiveString(String d) {
|
||||
this.m_DescriptiveString = d;
|
||||
}
|
||||
|
||||
/** This method allows you to set/get the weights label
|
||||
* @return the string
|
||||
*/
|
||||
public String getWeigthsLabel() {
|
||||
return this.m_WeightsLabel;
|
||||
}
|
||||
public void setWeightsLabel(String d) {
|
||||
this.m_WeightsLabel = d;
|
||||
}
|
||||
|
||||
/** This method allows you to set/get the weights label
|
||||
* @return the string
|
||||
*/
|
||||
public boolean isNormalizationEnabled() {
|
||||
return this.m_NormalizationEnabled;
|
||||
}
|
||||
public void enableNormalization(boolean d) {
|
||||
this.m_NormalizationEnabled = d;
|
||||
}
|
||||
|
||||
/** This method allows you to remove a Target from the list
|
||||
* @param index The index of the target to be removed.
|
||||
*/
|
||||
public void removeTarget(int index) {
|
||||
if ((index < 0) || (index >= this.m_SelectedObjectives.length)) return;
|
||||
|
||||
InterfaceOptimizationObjective[] newList = new InterfaceOptimizationObjective[this.m_SelectedObjectives.length-1];
|
||||
double[] newWeights = new double[this.m_Weights.length - 1];
|
||||
int j = 0;
|
||||
for (int i = 0; i < this.m_SelectedObjectives.length; i++) {
|
||||
if (index != i) {
|
||||
newList[j] = this.m_SelectedObjectives[i];
|
||||
newWeights[j] = this.m_Weights[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
this.m_SelectedObjectives = newList;
|
||||
this.m_Weights = newWeights;
|
||||
}
|
||||
|
||||
/** This method allows you to add a new target to the list
|
||||
* @param optTarget
|
||||
*/
|
||||
public void addTarget(InterfaceOptimizationObjective optTarget) {
|
||||
InterfaceOptimizationObjective[] newList = new InterfaceOptimizationObjective[this.m_SelectedObjectives.length+1];
|
||||
double[] newWeights = new double[this.m_Weights.length + 1];
|
||||
for (int i = 0; i < this.m_SelectedObjectives.length; i++) {
|
||||
newList[i] = this.m_SelectedObjectives[i];
|
||||
newWeights[i] = this.m_Weights[i];
|
||||
}
|
||||
newList[this.m_SelectedObjectives.length] = optTarget;
|
||||
newWeights[this.m_SelectedObjectives.length] = 1.0;
|
||||
this.m_SelectedObjectives = newList;
|
||||
this.m_Weights = newWeights;
|
||||
}
|
||||
}
|
||||
88
src/javaeva/gui/PropertyPanel.java
Normal file
88
src/javaeva/gui/PropertyPanel.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.beans.PropertyEditor;
|
||||
import javaeva.tools.EVAHELP;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JPanel;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PropertyPanel extends JPanel {
|
||||
private PropertyEditor m_PropertyEditor;
|
||||
private PropertyDialog m_PropertyDialog;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PropertyPanel(PropertyEditor Editor) {
|
||||
setBorder(BorderFactory.createEtchedBorder());
|
||||
setToolTipText("Click to edit properties for this object");
|
||||
setOpaque(true);
|
||||
m_PropertyEditor = Editor;
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (m_PropertyEditor.getValue() != null) {
|
||||
if (m_PropertyDialog == null) {
|
||||
int x = getLocationOnScreen().x;
|
||||
int y = getLocationOnScreen().y;
|
||||
m_PropertyDialog = new PropertyDialog(m_PropertyEditor, EVAHELP.cutClassName(m_PropertyEditor.getClass().getName()) , x, y);
|
||||
}
|
||||
else
|
||||
m_PropertyDialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
Dimension newPref = getPreferredSize();
|
||||
newPref.height = getFontMetrics(getFont()).getHeight() * 6 / 4; //6 / 4;
|
||||
newPref.width = newPref.height * 6; //5
|
||||
setPreferredSize(newPref);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removeNotify() {
|
||||
if (m_PropertyDialog != null) {
|
||||
//System.out.println(" m_PropertyDialog.dispose();");
|
||||
m_PropertyDialog.dispose();
|
||||
m_PropertyDialog = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void paintComponent(Graphics g) {
|
||||
Insets i = getInsets();
|
||||
Rectangle box = new Rectangle(i.left, i.top,
|
||||
getSize().width - i.left - i.right ,
|
||||
getSize().height - i.top - i.bottom);
|
||||
g.clearRect(i.left, i.top,
|
||||
getSize().width - i.right - i.left,
|
||||
getSize().height - i.bottom - i.top);
|
||||
m_PropertyEditor.paintValue(g, box);
|
||||
|
||||
// Rectangle box = new Rectangle(i.left,i.top,
|
||||
// this.getWidth() - i.right,
|
||||
// this.getHeight() - i.bottom );
|
||||
}
|
||||
}
|
||||
306
src/javaeva/gui/PropertyRemoteServers.java
Normal file
306
src/javaeva/gui/PropertyRemoteServers.java
Normal file
@@ -0,0 +1,306 @@
|
||||
package javaeva.gui;
|
||||
|
||||
//import javaeva.tools.ServerStarter;
|
||||
import javaeva.server.go.strategies.GeneticAlgorithm;
|
||||
import javaeva.server.go.strategies.InterfaceOptimizer;
|
||||
import javaeva.server.EvAMainAdapterImpl;
|
||||
import javaeva.server.EvAMainAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.rmi.Naming;
|
||||
|
||||
import wsi.ra.jproxy.RMIProxyRemoteThread;
|
||||
import wsi.ra.jproxy.RMIInvocationHandler;
|
||||
import wsi.ra.jproxy.RMIServer;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 14.12.2004
|
||||
* Time: 11:33:10
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
class ServerNode implements java.io.Serializable {
|
||||
public String m_ServerName;
|
||||
public int m_CPUs;
|
||||
|
||||
public ServerNode(String name, int cpus) {
|
||||
m_ServerName = name;
|
||||
m_CPUs = cpus;
|
||||
}
|
||||
public ServerNode(ServerNode a) {
|
||||
this.m_CPUs = a.m_CPUs;
|
||||
this.m_ServerName = a.m_ServerName;
|
||||
}
|
||||
public Object clone() {
|
||||
return (Object) new ServerNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class PropertyRemoteServers implements java.io.Serializable {
|
||||
|
||||
private ServerNode[] m_AvailableNodes;
|
||||
private String m_ClassToStart = "wsi.ra.jproxy.RMIServer";
|
||||
private transient String m_password = "";
|
||||
private String m_Login = "streiche";
|
||||
private boolean m_DeployJar = true;
|
||||
private String m_JarToDeploy = "JOpt.jar";
|
||||
|
||||
public PropertyRemoteServers() {
|
||||
this.m_AvailableNodes = new ServerNode[0];
|
||||
this.addServerNode("raold1.informatik.uni-tuebingen.de", 2);
|
||||
this.addServerNode("raold2.informatik.uni-tuebingen.de", 2);
|
||||
this.setLogin("streiche");
|
||||
this.setPassword("Kuskus");
|
||||
}
|
||||
|
||||
public PropertyRemoteServers(PropertyRemoteServers e) {
|
||||
if (e.m_AvailableNodes != null) {
|
||||
this.m_AvailableNodes = new ServerNode[e.m_AvailableNodes.length];
|
||||
for (int i = 0; i < e.m_AvailableNodes.length; i++) {
|
||||
this.m_AvailableNodes[i] = (ServerNode)e.m_AvailableNodes[i].clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return (Object) new PropertyRemoteServers(this);
|
||||
}
|
||||
|
||||
/** This method adds a server to the server nodes list
|
||||
* It will check whether or not the given name is already
|
||||
* in the current list of nodes is so it breaks.
|
||||
* @param name The name of the server
|
||||
* @param cpus The number of cpus on the server
|
||||
*/
|
||||
|
||||
public void addServerNode(String name, int cpus) {
|
||||
// first check for double instances
|
||||
for (int i = 0; i < this.m_AvailableNodes.length; i++) {
|
||||
if (this.m_AvailableNodes[i].m_ServerName.equalsIgnoreCase(name)) {
|
||||
if (cpus > this.m_AvailableNodes[i].m_CPUs) this.m_AvailableNodes[i].m_CPUs = cpus;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// now add the guy
|
||||
ServerNode[] newList = new ServerNode[this.m_AvailableNodes.length+1];
|
||||
ServerNode newNode = new ServerNode(name, cpus);
|
||||
for (int i = 0; i < this.m_AvailableNodes.length; i++) {
|
||||
newList[i] = this.m_AvailableNodes[i];
|
||||
}
|
||||
newList[this.m_AvailableNodes.length] = newNode;
|
||||
this.m_AvailableNodes = newList;
|
||||
}
|
||||
|
||||
/** This method removes a surplus node from the current list
|
||||
* @param name The name of the server to remove
|
||||
*/
|
||||
public void removeServerNode(String name) {
|
||||
ArrayList newList = new ArrayList();
|
||||
for (int i = 0; i < this.m_AvailableNodes.length; i++) {
|
||||
if (!this.m_AvailableNodes[i].m_ServerName.equalsIgnoreCase(name)) {
|
||||
newList.add(this.m_AvailableNodes[i]);
|
||||
} else {
|
||||
this.killServer(this.m_AvailableNodes[i].m_ServerName);
|
||||
}
|
||||
}
|
||||
this.m_AvailableNodes = new ServerNode[newList.size()];
|
||||
for (int i = 0; i < this.m_AvailableNodes.length; i++) {
|
||||
this.m_AvailableNodes[i] = (ServerNode)newList.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
/** This method removes and deactivates all servers
|
||||
*
|
||||
*/
|
||||
public void removeAll() {
|
||||
for (int i = 0; i < this.m_AvailableNodes.length; i++) {
|
||||
this.killServer(this.m_AvailableNodes[i].m_ServerName);
|
||||
}
|
||||
this.m_AvailableNodes = new ServerNode[0];
|
||||
}
|
||||
|
||||
/** This method returns an unchecked list of server instances
|
||||
* an server with n nodes will occur n times in the returned
|
||||
* server list
|
||||
* @return A list of server instances, with double instances.
|
||||
*/
|
||||
public String[] getServerNodes() {
|
||||
String[] result;
|
||||
ArrayList tmpList = new ArrayList();
|
||||
for (int i = 0; i < this.m_AvailableNodes.length; i++) {
|
||||
for (int j = 0; j < this.m_AvailableNodes[i].m_CPUs; i++) {
|
||||
tmpList.add(this.m_AvailableNodes[i].m_ServerName);
|
||||
}
|
||||
}
|
||||
result = new String[tmpList.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = (String) tmpList.get(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** This method returns an checked list of server instances
|
||||
* an server with n nodes will occur n times in the returned
|
||||
* server list
|
||||
* @return A list of server instances, with double instances.
|
||||
*/
|
||||
public String[] getCheckedServerNodes() {
|
||||
String[] result;
|
||||
ArrayList tmpList = new ArrayList();
|
||||
for (int i = 0; i < this.m_AvailableNodes.length; i++) {
|
||||
if (this.isServerOnline(this.m_AvailableNodes[i].m_ServerName)) {
|
||||
for (int j = 0; j < this.m_AvailableNodes[i].m_CPUs; j++) {
|
||||
tmpList.add(this.m_AvailableNodes[i].m_ServerName);
|
||||
}
|
||||
}
|
||||
}
|
||||
result = new String[tmpList.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = (String) tmpList.get(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** This method will check whether or not a given server is online
|
||||
* @param name The name of the server to check
|
||||
* @return true if server is online, false else
|
||||
*/
|
||||
public boolean isServerOnline(String name) {
|
||||
try {
|
||||
String[] list = Naming.list("rmi://" + name + ":" + 1099);
|
||||
if (list == null) return false;
|
||||
else return true;
|
||||
} catch (Exception et) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** This method will try to start all server in the current list
|
||||
*/
|
||||
public void startServers() {
|
||||
/* ServerStarter serverstarter;
|
||||
for (int i = 0; i < this.m_AvailableNodes.length; i++) {
|
||||
if (!this.isServerOnline(this.m_AvailableNodes[i].m_ServerName)) {
|
||||
serverstarter = new ServerStarter();
|
||||
serverstarter.setPasswd(this.m_password);
|
||||
serverstarter.setClass2Run(this.m_ClassToStart);
|
||||
serverstarter.setDeployJarFile(this.m_DeployJar);
|
||||
serverstarter.setJarfilename(this.m_JarToDeploy);
|
||||
serverstarter.setHostname(this.m_AvailableNodes[i].m_ServerName);
|
||||
serverstarter.setLogin(this.m_Login);
|
||||
try {
|
||||
serverstarter.startServer();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Problems starting the server: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/** This method kills the servers
|
||||
* previously started
|
||||
*/
|
||||
public void killServers() {
|
||||
for (int i = 0; i < this.m_AvailableNodes.length; i++) {
|
||||
this.killServer(this.m_AvailableNodes[i].m_ServerName);
|
||||
}
|
||||
}
|
||||
|
||||
/** This method kills a single server
|
||||
* @param name The name of the server to kill
|
||||
*/
|
||||
public void killServer(String name) {
|
||||
if (this.isServerOnline(name)) {
|
||||
try {
|
||||
String[] list = Naming.list("rmi://" + name + ":" + 1099);
|
||||
for (int j = 0; j < list.length; j++) {
|
||||
System.out.println(""+list[j]);
|
||||
if (list[j].indexOf(this.m_Login) > 0) {
|
||||
RMIInvocationHandler x = (RMIInvocationHandler) Naming.lookup("rmi:"+list[j]);
|
||||
//x.invoke("killThread", null);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error : "+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method returns the number of servers
|
||||
* @return the size
|
||||
*/
|
||||
public int size() {
|
||||
return this.m_AvailableNodes.length;
|
||||
}
|
||||
|
||||
public ServerNode get(int i) {
|
||||
if ((i >= 0) && (i < this.m_AvailableNodes.length))
|
||||
return this.m_AvailableNodes[i];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public String writeToText() {
|
||||
String result = "";
|
||||
for (int i = 0; i < this.m_AvailableNodes.length; i++) {
|
||||
result += this.m_AvailableNodes[i].m_ServerName +"\t"+this.m_AvailableNodes[i].m_CPUs+"\n";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setNameFor(int i, String name) {
|
||||
if ((i >= 0) && (i < this.m_AvailableNodes.length)) this.m_AvailableNodes[i].m_ServerName = name;
|
||||
}
|
||||
|
||||
public void setCPUsFor(int i, int c) {
|
||||
if ((i >= 0) && (i < this.m_AvailableNodes.length)) this.m_AvailableNodes[i].m_CPUs = c;
|
||||
}
|
||||
|
||||
public void readFromText(String text) {
|
||||
String[] lines = text.split("\n");
|
||||
this.removeAll();
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String[] rickel = lines[i].split("\t");
|
||||
this.addServerNode(rickel[0].trim(), new Integer(rickel[1].trim()).intValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
PropertyRemoteServers test = new PropertyRemoteServers();
|
||||
test.m_password = "";
|
||||
test.addServerNode("raold1.informatik.uni-tuebingen.de", 2);
|
||||
//test.addServerNode("raold2.informatik.uni-tuebingen.de", 2);
|
||||
System.out.println(" Getting running Servers:");
|
||||
String[] servers = test.getCheckedServerNodes();
|
||||
for (int i = 0; i < servers.length; i++) {
|
||||
System.out.println("Server "+i+": "+servers[i]);
|
||||
}
|
||||
System.out.println("\n Starting Servers: ");
|
||||
test.startServers();
|
||||
System.out.println(" Getting running Servers:");
|
||||
servers = test.getCheckedServerNodes();
|
||||
for (int i = 0; i < servers.length; i++) {
|
||||
System.out.println("Server "+i+": "+servers[i]);
|
||||
}
|
||||
test.killServers();
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return this.m_Login;
|
||||
}
|
||||
public void setLogin(String l) {
|
||||
this.m_Login = l;
|
||||
}
|
||||
public String getPassword() {
|
||||
return this.m_password;
|
||||
}
|
||||
public void setPassword(String l) {
|
||||
this.m_password = l;
|
||||
}
|
||||
public void setPassword(char[] l) {
|
||||
this.m_password = new String(l);
|
||||
}
|
||||
}
|
||||
740
src/javaeva/gui/PropertySheetPanel.java
Normal file
740
src/javaeva/gui/PropertySheetPanel.java
Normal file
@@ -0,0 +1,740 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 319 $
|
||||
* $Date: 2007-12-05 11:29:32 +0100 (Wed, 05 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.util.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.*;
|
||||
import java.lang.reflect.*;
|
||||
import javax.swing.*;
|
||||
import sun.beans.editors.*;
|
||||
import javaeva.tools.EVAHELP;
|
||||
import javaeva.tools.SelectedTag;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PropertySheetPanel extends JPanel implements PropertyChangeListener {
|
||||
public final static boolean TRACE = false;
|
||||
/** The target object being edited */
|
||||
private Object m_Target;
|
||||
/** Holds properties of the target */
|
||||
private PropertyDescriptor m_Properties[];
|
||||
/** Holds the methods of the target */
|
||||
private MethodDescriptor m_Methods[];
|
||||
/** Holds property editors of the object */
|
||||
private PropertyEditor m_Editors[];
|
||||
/** Holds current object values for each property */
|
||||
private Object m_Values[];
|
||||
/** Stores GUI components containing each editing component */
|
||||
private JComponent m_Views[];
|
||||
private JComponent m_ViewWrapper[];
|
||||
/** The labels for each property */
|
||||
private JLabel m_Labels[];
|
||||
/** The tool tip text for each property */
|
||||
private String m_TipTexts[];
|
||||
/** StringBuffer containing help text for the object being edited */
|
||||
// private StringBuffer m_HelpText;
|
||||
private String m_ClassName;
|
||||
/** Button to pop up the full help text in a separate frame */
|
||||
private JButton m_HelpBut;
|
||||
/** A count of the number of properties we have an editor for */
|
||||
private int m_NumEditable = 0;
|
||||
/** A support object for handling property change listeners */
|
||||
private PropertyChangeSupport m_support = new PropertyChangeSupport(this);
|
||||
/** set true to use the GOE by default if no other editor is registered **/
|
||||
|
||||
/** Creates the property sheet panel.
|
||||
*/
|
||||
public PropertySheetPanel() {
|
||||
// setBorder(BorderFactory.createLineBorder(Color.red));
|
||||
setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
|
||||
if (TRACE) System.out.println("PropertySheetPanel(): NEW PropertySheetPanel");
|
||||
}
|
||||
|
||||
/** Updates the property sheet panel with a changed property and also passed
|
||||
* the event along.
|
||||
* @param evt a value of type 'PropertyChangeEvent'
|
||||
*/
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (TRACE) System.out.println("PropertySheetPanel.propertyChange() "+m_Target.getClass()+": calling wasModified");
|
||||
wasModified(evt); // Let our panel update before guys downstream
|
||||
m_support.removePropertyChangeListener(this);
|
||||
m_support.firePropertyChange("", null, m_Target);
|
||||
m_support.addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
/** Adds a PropertyChangeListener.
|
||||
* @param l a value of type 'PropertyChangeListener'
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/** Removes a PropertyChangeListener.
|
||||
* @param l a value of type 'PropertyChangeListener'
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_support.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
|
||||
/** Sets a new target object for customisation.
|
||||
* @param targ a value of type 'Object'
|
||||
*/
|
||||
public synchronized void setTarget(Object targ) {
|
||||
if (TRACE) System.out.println("PropertySheetPanel.setTarget(): "+targ.getClass().getName());
|
||||
int componentOffset = 0;
|
||||
GridBagLayout gbLayout = new GridBagLayout();
|
||||
|
||||
// Close any child windows at this point
|
||||
removeAll();
|
||||
setLayout(gbLayout);
|
||||
setVisible(false);
|
||||
m_NumEditable = 0;
|
||||
m_Target = targ;
|
||||
try {
|
||||
BeanInfo bi = Introspector.getBeanInfo(m_Target.getClass());
|
||||
m_Properties = bi.getPropertyDescriptors();
|
||||
m_Methods = bi.getMethodDescriptors();
|
||||
} catch (IntrospectionException ex) {
|
||||
System.err.println("PropertySheetPanel.setTarget(): Couldn't introspect");
|
||||
return;
|
||||
}
|
||||
|
||||
int rowHeight = 12;
|
||||
// JScrollPane js = null;
|
||||
JTextArea jt = new JTextArea();
|
||||
// m_HelpText = null;
|
||||
|
||||
// Look for a globalInfo method that returns a string
|
||||
// describing the target
|
||||
int methsFound = 0; // dont loop too long, so count until all found
|
||||
for (int i = 0; i < m_Methods.length; i++) {
|
||||
String name = m_Methods[i].getDisplayName();
|
||||
Method meth = m_Methods[i].getMethod();
|
||||
if (name.equals("globalInfo")) {
|
||||
if (meth.getReturnType().equals(String.class)) {
|
||||
try {
|
||||
Object args[] = { };
|
||||
String globalInfo = (String)(meth.invoke(m_Target, args));
|
||||
String summary = globalInfo;
|
||||
// int ci = globalInfo.indexOf('.');
|
||||
// if (ci != -1) {
|
||||
// // this shortens the displayed text, using only the first "sentence".
|
||||
// // May cause problems, if the dot belongs to a number, for example,
|
||||
// // so I deactivated it (MK).
|
||||
// summary = globalInfo.substring(0, ci + 1);
|
||||
// }
|
||||
m_ClassName = targ.getClass().getName();
|
||||
// m_HelpText = new StringBuffer("NAME\n");
|
||||
// m_HelpText.append(m_ClassName).append("\n\n");
|
||||
// m_HelpText.append("SYNOPSIS\n").append(globalInfo).append("\n\n");
|
||||
m_HelpBut = new JButton("Help");
|
||||
m_HelpBut.setToolTipText("More information about " + m_ClassName);
|
||||
m_HelpBut.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent a) {
|
||||
openHelpFrame();
|
||||
//m_HelpBut.setEnabled(false);
|
||||
}
|
||||
});
|
||||
|
||||
jt.setText(summary);
|
||||
jt.setFont(new Font("SansSerif", Font.PLAIN, rowHeight));
|
||||
jt.setEditable(false);
|
||||
jt.setLineWrap(true);
|
||||
jt.setWrapStyleWord(true);
|
||||
jt.setBackground(getBackground());
|
||||
jt.setSize(jt.getPreferredSize());
|
||||
|
||||
JPanel jp = new JPanel();
|
||||
jp.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder("Info"),
|
||||
BorderFactory.createEmptyBorder(0, 5, 5, 5)
|
||||
));
|
||||
jp.setLayout(new BorderLayout());
|
||||
jp.add(jt, BorderLayout.CENTER);
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new BorderLayout());
|
||||
|
||||
if (HtmlDemo.resourceExists(getHelpFileName())) {
|
||||
// this means that the expected URL really exists
|
||||
p2.add(m_HelpBut, BorderLayout.NORTH);
|
||||
} else {
|
||||
if (TRACE) System.out.println("not adding help button because of missing " + getHelpFileName());
|
||||
}
|
||||
jp.add(p2, BorderLayout.EAST);
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
//gbConstraints.anchor = GridBagConstraints.EAST;
|
||||
gbConstraints.fill = GridBagConstraints.BOTH;
|
||||
//gbConstraints.gridy = 0;
|
||||
//gbConstraints.gridx = 0;
|
||||
gbConstraints.gridwidth = 2;
|
||||
gbConstraints.insets = new Insets(0,5,0,5);
|
||||
gbLayout.setConstraints(jp, gbConstraints);
|
||||
add(jp);
|
||||
componentOffset = 1;
|
||||
methsFound++;
|
||||
if (methsFound == 2) break; // small speed-up
|
||||
} catch (Exception ex) {
|
||||
} // end try
|
||||
} // end if (meth.getReturnType().equals(String.class)) {
|
||||
} // end if (name.equals("globalInfo")) {
|
||||
else if (name.equals("hideHideable")) {
|
||||
Object args[] = { };
|
||||
try {
|
||||
meth.invoke(m_Target, args);
|
||||
methsFound++;
|
||||
if (methsFound == 2) break; // small speed-up
|
||||
} catch(Exception ex) {}
|
||||
}
|
||||
} // end for (int i = 0; i < m_Methods.length; i++) {
|
||||
|
||||
// Now lets search for the individual properties their
|
||||
// values, views and editors...
|
||||
m_Editors = new PropertyEditor[m_Properties.length];
|
||||
m_Values = new Object[m_Properties.length];
|
||||
m_Views = new JComponent[m_Properties.length];
|
||||
m_ViewWrapper= new JComponent[m_Properties.length];
|
||||
m_Labels = new JLabel[m_Properties.length];
|
||||
m_TipTexts = new String[m_Properties.length];
|
||||
// boolean firstTip = true;
|
||||
for (int i = 0; i < m_Properties.length; i++) {
|
||||
// For each property do this
|
||||
// Don't display hidden or expert properties.
|
||||
//if (m_Properties[i].isHidden() || m_Properties[i].isExpert()) continue;
|
||||
// we now display hidden properties (MK)
|
||||
String name = m_Properties[i].getDisplayName();
|
||||
if (TRACE) System.out.println("PSP looking at "+ name);
|
||||
|
||||
if (m_Properties[i].isExpert()) continue;
|
||||
Method getter = m_Properties[i].getReadMethod();
|
||||
Method setter = m_Properties[i].getWriteMethod();
|
||||
// Only display read/write properties.
|
||||
if (getter == null || setter == null) continue;
|
||||
JComponent NewView = null;
|
||||
try {
|
||||
Object args[] = { };
|
||||
Object value = getter.invoke(m_Target, args);
|
||||
PropertyEditor editor = null;
|
||||
//Class pec = m_Properties[i].getPropertyEditorClass();
|
||||
m_Values[i] = value;
|
||||
// ////////////////// refactored by MK
|
||||
|
||||
editor = PropertyEditorProvider.findEditor(m_Properties[i], value);
|
||||
m_Editors[i] = editor;
|
||||
if (editor == null) continue;
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
// Don't try to set null values:
|
||||
if (value == null) {
|
||||
// If it's a user-defined property we give a warning.
|
||||
String getterClass = m_Properties[i].getReadMethod().getDeclaringClass().getName();
|
||||
if (getterClass.indexOf("java.") != 0) System.out.println("Warning: Property \"" + name+ "\" has null initial value. Skipping.");
|
||||
continue;
|
||||
}
|
||||
editor.setValue(value);
|
||||
|
||||
// now look for a TipText method for this property
|
||||
String tipName = name + "TipText";
|
||||
for (int j = 0; j < m_Methods.length; j++) {
|
||||
String mname = m_Methods[j].getDisplayName();
|
||||
Method meth = m_Methods[j].getMethod();
|
||||
if (mname.equals(tipName)) {
|
||||
if (meth.getReturnType().equals(String.class)) {
|
||||
try {
|
||||
String tempTip = (String)(meth.invoke(m_Target, args));
|
||||
int ci = tempTip.indexOf('.');
|
||||
if (ci < 0) m_TipTexts[i] = tempTip;
|
||||
else m_TipTexts[i] = tempTip.substring(0, ci);
|
||||
// if (m_HelpText != null) {
|
||||
// if (firstTip) {
|
||||
// m_HelpText.append("OPTIONS\n");
|
||||
// firstTip = false;
|
||||
// }
|
||||
// m_HelpText.append(name).append(" -- ");
|
||||
// m_HelpText.append(tempTip).append("\n\n");
|
||||
// //jt.setText(m_HelpText.toString());
|
||||
// }
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // end searching for (int j = 0; j < m_Methods.length; j++) {
|
||||
|
||||
// Now figure out how to display it...
|
||||
if (editor instanceof sun.beans.editors.BoolEditor) {
|
||||
NewView = new PropertyBoolSelector(editor);
|
||||
} else {
|
||||
if (editor instanceof sun.beans.editors.DoubleEditor) {
|
||||
NewView = new PropertyText(editor);
|
||||
} else {
|
||||
if (editor.isPaintable() && editor.supportsCustomEditor()) {
|
||||
NewView = new PropertyPanel(editor);
|
||||
} else {
|
||||
if (editor.getTags() != null ) {
|
||||
NewView = new PropertyValueSelector(editor);
|
||||
} else {
|
||||
if (editor.getAsText() != null) {
|
||||
NewView = new PropertyText(editor);
|
||||
} else {
|
||||
System.out.println("Warning: Property \"" + name
|
||||
+ "\" has non-displayabale editor. Skipping.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
editor.addPropertyChangeListener(this);
|
||||
} catch (InvocationTargetException ex) {
|
||||
System.out.println("InvocationTargetException " + name
|
||||
+ " on target: "
|
||||
+ ex.getTargetException());
|
||||
ex.getTargetException().printStackTrace();
|
||||
continue;
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Skipping property "+name+" ; exception: " + ex);
|
||||
ex.printStackTrace();
|
||||
continue;
|
||||
} // end try
|
||||
|
||||
// Add some specific display for some greeks here
|
||||
if (name.equalsIgnoreCase("alpha"))
|
||||
name = "\u03B1";
|
||||
if (name.equalsIgnoreCase("beta"))
|
||||
name = "\u03B2";
|
||||
if (name.equalsIgnoreCase("gamma"))
|
||||
name = "\u03B3";
|
||||
if (name.equalsIgnoreCase("gammab"))
|
||||
name = "\u0393";
|
||||
if (name.equalsIgnoreCase("delta"))
|
||||
name = "\u03B4";
|
||||
if (name.equalsIgnoreCase("deltab"))
|
||||
name = "\u0394";
|
||||
if ((name.equalsIgnoreCase("epsi")) || (name.equalsIgnoreCase("epsilon")))
|
||||
name = "\u03B5";
|
||||
if (name.equalsIgnoreCase("zeta"))
|
||||
name = "\u03B6";
|
||||
if (name.equalsIgnoreCase("theta"))
|
||||
name = "\u03D1";
|
||||
if (name.equalsIgnoreCase("thetab"))
|
||||
name = "\u0398";
|
||||
if (name.equalsIgnoreCase("iota"))
|
||||
name = "\u03B9";
|
||||
if (name.equalsIgnoreCase("kappa"))
|
||||
name = "\u03BA";
|
||||
if (name.equalsIgnoreCase("lambda"))
|
||||
name = "\u03BB";
|
||||
if (name.equalsIgnoreCase("lambdab"))
|
||||
name = "\u039B";
|
||||
if (name.equalsIgnoreCase("rho"))
|
||||
name = "\u03C1";
|
||||
if (name.equalsIgnoreCase("sigma"))
|
||||
name = "\u03C3";
|
||||
if (name.equalsIgnoreCase("sigmab"))
|
||||
name = "\u03A3";
|
||||
if (name.equalsIgnoreCase("tau"))
|
||||
name = "\u03C4";
|
||||
if (name.equalsIgnoreCase("upsilon"))
|
||||
name = "\u03C5";
|
||||
if (name.equalsIgnoreCase("upsilonb"))
|
||||
name = "\u03D2";
|
||||
if (name.equalsIgnoreCase("omega"))
|
||||
name = "\u03C9";
|
||||
if (name.equalsIgnoreCase("omegab"))
|
||||
name = "\u03A9";
|
||||
|
||||
// these are too small
|
||||
if (name.equalsIgnoreCase("eta"))
|
||||
name = "\u03B7";
|
||||
if (name.equalsIgnoreCase("psi"))
|
||||
name = "\u03C8";
|
||||
if (name.equalsIgnoreCase("psib"))
|
||||
name = "\u03A8";
|
||||
if (name.equalsIgnoreCase("phi"))
|
||||
name = "\u03D5";
|
||||
if (name.equalsIgnoreCase("phib"))
|
||||
name = "\u03A6";
|
||||
if (name.equalsIgnoreCase("chi"))
|
||||
name = "\u03C7";
|
||||
if ((name.equalsIgnoreCase("mu")) || (name.equalsIgnoreCase("my")) || (name.equalsIgnoreCase("myu")))
|
||||
name = "\u03BC";
|
||||
if (name.equalsIgnoreCase("nu"))
|
||||
name = "\u03BD";
|
||||
if (name.equalsIgnoreCase("xi"))
|
||||
name = "\u03BE";
|
||||
if (name.equalsIgnoreCase("xib"))
|
||||
name = "\u039E";
|
||||
if (name.equalsIgnoreCase("pi"))
|
||||
name = "\u03C0";
|
||||
if (name.equalsIgnoreCase("pib"))
|
||||
name = "\u03A0";
|
||||
|
||||
|
||||
m_Labels[i] = new JLabel(name, SwingConstants.RIGHT);
|
||||
m_Labels[i].setBorder(BorderFactory.createEmptyBorder(10,10,0,5));
|
||||
m_Views[i] = NewView;
|
||||
m_ViewWrapper[i] = new JPanel();
|
||||
m_ViewWrapper[i].setLayout(new BorderLayout());
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
gbConstraints.anchor = GridBagConstraints.EAST;
|
||||
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbConstraints.gridy = i+componentOffset;
|
||||
gbConstraints.gridx = 0;
|
||||
gbLayout.setConstraints(m_Labels[i], gbConstraints);
|
||||
add(m_Labels[i]);
|
||||
JPanel newPanel = new JPanel();
|
||||
if (m_TipTexts[i] != null) {
|
||||
m_Views[i].setToolTipText(m_TipTexts[i]);
|
||||
m_Labels[i].setToolTipText(m_TipTexts[i]);
|
||||
}
|
||||
newPanel.setBorder(BorderFactory.createEmptyBorder(10,5,0,10));
|
||||
newPanel.setLayout(new BorderLayout());
|
||||
// @todo: Streiche here i could add the ViewWrapper
|
||||
m_ViewWrapper[i].add(m_Views[i], BorderLayout.CENTER);
|
||||
newPanel.add(m_ViewWrapper[i], BorderLayout.CENTER);
|
||||
gbConstraints = new GridBagConstraints();
|
||||
gbConstraints.anchor = GridBagConstraints.WEST;
|
||||
gbConstraints.fill = GridBagConstraints.BOTH;
|
||||
gbConstraints.gridy = i+componentOffset;
|
||||
gbConstraints.gridx = 1;
|
||||
gbConstraints.weightx = 100;
|
||||
gbLayout.setConstraints(newPanel, gbConstraints);
|
||||
add(newPanel);
|
||||
m_NumEditable++;
|
||||
if (m_Properties[i].isHidden()) {
|
||||
m_ViewWrapper[i].setVisible(false);
|
||||
m_Labels[i].setVisible(false);
|
||||
}
|
||||
}
|
||||
if (m_NumEditable == 0) {
|
||||
JLabel empty = new JLabel("No editable properties",SwingConstants.CENTER);
|
||||
Dimension d = empty.getPreferredSize();
|
||||
empty.setPreferredSize(new Dimension(d.width * 2, d.height * 2));
|
||||
empty.setBorder(BorderFactory.createEmptyBorder(10, 5, 0, 10));
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
gbConstraints.anchor = GridBagConstraints.CENTER;
|
||||
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbConstraints.gridy = componentOffset;
|
||||
gbConstraints.gridx = 0;
|
||||
gbLayout.setConstraints(empty, gbConstraints);
|
||||
add(empty);
|
||||
}
|
||||
// Container p=this;
|
||||
// while (p != null) {
|
||||
// p.setSize(p.getPreferredSize());
|
||||
// p = p.getParent();
|
||||
// }
|
||||
validate();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the html help file name.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected String getHelpFileName() {
|
||||
return EVAHELP.cutClassName(m_ClassName)+".html";
|
||||
}
|
||||
|
||||
/** This method opens a help frame.
|
||||
*/
|
||||
protected void openHelpFrame() {
|
||||
HtmlDemo temp = new HtmlDemo(getHelpFileName());
|
||||
temp.show();
|
||||
// JTextArea ta = new JTextArea();
|
||||
// ta.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
// ta.setLineWrap(true);
|
||||
// ta.setWrapStyleWord(true);
|
||||
// ta.setEditable(false);
|
||||
// ta.setText(m_HelpText.toString());
|
||||
// ta.setCaretPosition(0);
|
||||
// final JFrame jf = new JFrame("Information");
|
||||
// jf.addWindowListener(new WindowAdapter() {
|
||||
// public void windowClosing(WindowEvent e) {
|
||||
// jf.dispose();
|
||||
// if (m_HelpFrame == jf) {
|
||||
// m_HelpBut.setEnabled(true);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// jf.getContentPane().setLayout(new BorderLayout());
|
||||
// jf.getContentPane().add(new JScrollPane(ta), BorderLayout.CENTER);
|
||||
// jf.pack();
|
||||
// jf.setSize(400, 350);
|
||||
// jf.setLocation(getTopLevelAncestor().getLocationOnScreen().x
|
||||
// + getTopLevelAncestor().getSize().width,
|
||||
// getTopLevelAncestor().getLocationOnScreen().y);
|
||||
// jf.setVisible(true);
|
||||
// m_HelpFrame = jf;
|
||||
}
|
||||
|
||||
/** Gets the number of editable properties for the current target.
|
||||
* @return the number of editable properties.
|
||||
*/
|
||||
public int editableProperties() {
|
||||
return m_NumEditable;
|
||||
}
|
||||
|
||||
/** Updates the propertysheet when a value has been changed (from outside
|
||||
* the propertysheet?).
|
||||
* @param evt a value of type 'PropertyChangeEvent'
|
||||
*/
|
||||
synchronized void wasModified(PropertyChangeEvent evt) {
|
||||
if (TRACE) {
|
||||
System.out.println("PropertySheetPanel.wasModified(): My Target is "+this.m_Target.getClass());
|
||||
System.out.println("PropertySheetPanel.wasModified(): "+evt.toString()+" - "+evt.getNewValue());
|
||||
}
|
||||
if (evt.getSource() instanceof PropertyEditor) {
|
||||
PropertyEditor editor = (PropertyEditor) evt.getSource();
|
||||
for (int i = 0 ; i < m_Editors.length; i++) {
|
||||
if (m_Editors[i] == editor) {
|
||||
PropertyDescriptor property = m_Properties[i];
|
||||
Method getter = m_Properties[i].getReadMethod();
|
||||
Object value = editor.getValue();
|
||||
m_Values[i] = value;
|
||||
Method setter = property.getWriteMethod();
|
||||
// @todo: Streiche so something was changed, i could check if i have to change the editor
|
||||
|
||||
PropertyEditor tmpEdit = null;
|
||||
Object newValue = evt.getNewValue();
|
||||
if (newValue == null) newValue = editor.getValue();
|
||||
tmpEdit = PropertyEditorProvider.findEditor(newValue.getClass());
|
||||
if (tmpEdit == null) tmpEdit = PropertyEditorProvider.findEditor(m_Properties[i].getPropertyType());
|
||||
if (tmpEdit.getClass() != m_Editors[i].getClass()) {
|
||||
value = newValue;
|
||||
m_Values[i] = newValue;
|
||||
m_Editors[i] = tmpEdit;
|
||||
if (tmpEdit instanceof GenericObjectEditor) ((GenericObjectEditor) tmpEdit).setClassType(m_Properties[i].getPropertyType());
|
||||
m_Editors[i].setValue(newValue);
|
||||
JComponent NewView = null;
|
||||
if (tmpEdit instanceof sun.beans.editors.BoolEditor) {
|
||||
NewView = new PropertyBoolSelector(tmpEdit);
|
||||
} else {
|
||||
if (tmpEdit instanceof sun.beans.editors.DoubleEditor) {
|
||||
NewView = new PropertyText(tmpEdit);
|
||||
} else {
|
||||
if (tmpEdit.isPaintable() && tmpEdit.supportsCustomEditor()) {
|
||||
NewView = new PropertyPanel(tmpEdit);
|
||||
} else {
|
||||
if (tmpEdit.getTags() != null ) {
|
||||
NewView = new PropertyValueSelector(tmpEdit);
|
||||
} else {
|
||||
if (tmpEdit.getAsText() != null) {
|
||||
NewView = new PropertyText(tmpEdit);
|
||||
} else {
|
||||
System.out.println("Warning: Property \"" + m_Properties[i].getDisplayName()
|
||||
+ "\" has non-displayabale editor. Skipping.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m_Editors[i].addPropertyChangeListener(this);
|
||||
m_Views[i] = NewView;
|
||||
if (m_TipTexts[i] != null) m_Views[i].setToolTipText(m_TipTexts[i]);
|
||||
m_ViewWrapper[i].removeAll();
|
||||
m_ViewWrapper[i].setLayout(new BorderLayout());
|
||||
m_ViewWrapper[i].add(m_Views[i], BorderLayout.CENTER);
|
||||
m_ViewWrapper[i].repaint();
|
||||
}
|
||||
|
||||
// System.out.println("Value: "+value +" / m_Values[i]: " + m_Values[i]);
|
||||
// Now try to update the target with the new value of the property
|
||||
// and allow the target to do some changes to the value, therefore
|
||||
// reread the new value from the target
|
||||
try {
|
||||
Object args[] = { value };
|
||||
args[0] = value;
|
||||
Object args2[] = { };
|
||||
// setting the current value to the target object
|
||||
setter.invoke(m_Target, args);
|
||||
// i could also get the new value
|
||||
//value = getter.invoke(m_Target, args2);
|
||||
// Now i'm reading the set value from the target to my local values
|
||||
m_Values[i] = getter.invoke(m_Target, args2);
|
||||
|
||||
if (value instanceof Integer) {
|
||||
// This could check whether i have to set the value back to
|
||||
// the editor, this would allow to check myu and lambda
|
||||
// why shouldn't i do this for every property!?
|
||||
// System.out.println("value: "+((Integer)value).intValue());
|
||||
// System.out.println(" m_Values[i]: "+ ((Integer) m_Values[i]).intValue());
|
||||
if (((Integer)value).intValue() != ((Integer) m_Values[i]).intValue()) {
|
||||
editor.setValue(m_Values[i]);
|
||||
}
|
||||
}
|
||||
} catch (InvocationTargetException ex) {
|
||||
if (ex.getTargetException() instanceof PropertyVetoException) {
|
||||
System.out.println("PropertySheetPanel.wasModified(): WARNING: Vetoed; reason is: " + ex.getTargetException().getMessage());
|
||||
} else {
|
||||
System.out.println("PropertySheetPanel.wasModified(): InvocationTargetException while updating " + property.getName());
|
||||
System.out.println("PropertySheetPanel.wasModified(): "+ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("PropertySheetPanel.wasModified(): Unexpected exception while updating " + property.getName());
|
||||
}
|
||||
//revalidate();
|
||||
if (m_Views[i] != null && m_Views[i] instanceof PropertyPanel) {
|
||||
//System.err.println("Trying to repaint the property canvas");
|
||||
m_Views[i].repaint();
|
||||
revalidate();
|
||||
}
|
||||
break;
|
||||
} // end if (m_Editors[i] == editor)
|
||||
} // end for (int i = 0 ; i < m_Editors.length; i++) {
|
||||
boolean doRepaint = false;
|
||||
for (int i = 0 ; i < m_Editors.length; i++) { // check the views for out-of-date information. this is different than checking the editors
|
||||
if (m_Editors[i] != editor) {
|
||||
// looking at another field (not changed explicitly, maybe implicitely
|
||||
boolean valChanged = false;
|
||||
Object args[] = { };
|
||||
Method getter = m_Properties[i].getReadMethod();
|
||||
if (m_Properties[i].isHidden() || m_Properties[i].isExpert()) {
|
||||
if ((m_Labels[i] != null) && (m_Labels[i].isVisible())) {
|
||||
// something is set to hidden but was visible up to now
|
||||
m_ViewWrapper[i].setVisible(false);
|
||||
m_Labels[i].setVisible(false);
|
||||
doRepaint = true;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
if ((m_Labels[i] != null) && !(m_Labels[i].isVisible())) {
|
||||
// something is invisible but set to not hidden in the mean time
|
||||
m_ViewWrapper[i].setVisible(true);
|
||||
m_Labels[i].setVisible(true);
|
||||
doRepaint = true;
|
||||
}
|
||||
}
|
||||
try { // check if view i is up to date and in sync with the value of the getter
|
||||
if (m_Views[i] != null) {
|
||||
Object val = getter.invoke(m_Target, args);
|
||||
if (m_Views[i] instanceof PropertyBoolSelector) {
|
||||
valChanged = (((PropertyBoolSelector)m_Views[i]).isSelected() != ((Boolean)val));
|
||||
if (valChanged) ((PropertyBoolSelector)m_Views[i]).setSelected(((Boolean)val));
|
||||
} else if (m_Views[i] instanceof PropertyText) {
|
||||
valChanged = !(((PropertyText)m_Views[i]).getText()).equals(val.toString());
|
||||
if (valChanged) ((PropertyText)m_Views[i]).setText(val.toString());
|
||||
} else if (m_Views[i] instanceof PropertyPanel) {
|
||||
valChanged = false;//!((PropertyPanel)m_Views[i]).equals(value);
|
||||
// disregard whole panels and hope for the best
|
||||
if (TRACE) System.out.println("not checking for internal change of PropertyPanel");
|
||||
} else if (m_Views[i] instanceof PropertyValueSelector) {
|
||||
//changed = !((SelectedTag)val).isSelectedString((String)((PropertyValueSelector)m_Views[i]).getSelectedItem());
|
||||
// interestingly there seems to be an implicit update of the ValueSelector, possible changes
|
||||
// are already applied, all we need to see it is a repaint
|
||||
m_Views[i].repaint();
|
||||
} else {
|
||||
System.out.println("Warning: Property \"" + i
|
||||
+ "\" not recognized. Skipping.");
|
||||
}
|
||||
}
|
||||
} catch(Exception exc) {
|
||||
System.err.println("Exception in PropertySheetPanel");
|
||||
}
|
||||
}// end if (m_Editors[i] == editor) {
|
||||
} // end for (int i = 0 ; i < m_Editors.length; i++) {
|
||||
if (doRepaint) { // some components have been hidden or reappeared
|
||||
// MK this finally seems to work right
|
||||
Container p=this;
|
||||
while (p != null) {
|
||||
p.setSize(p.getPreferredSize());
|
||||
p = p.getParent();
|
||||
}
|
||||
}
|
||||
} // end if (evt.getSource() instanceof PropertyEditor) {
|
||||
|
||||
// Now re-read all the properties and update the editors
|
||||
// for any other properties that have changed.
|
||||
for (int i = 0; i < m_Properties.length; i++) {
|
||||
Object o;
|
||||
Method getter = null;
|
||||
if (m_Editors[i]==null) continue; /// TODO: MK: Im not quite sure this is all good, but it avoids a latency problem
|
||||
try {
|
||||
getter = m_Properties[i].getReadMethod();
|
||||
Object args[] = { };
|
||||
o = getter.invoke(m_Target, args);
|
||||
} catch (Exception ex) {
|
||||
o = null;
|
||||
}
|
||||
if (o == m_Values[i]) {
|
||||
// The property is equal to its old value.
|
||||
continue;
|
||||
}
|
||||
if (o != null && o.equals(m_Values[i])) {
|
||||
// The property is equal to its old value.
|
||||
continue;
|
||||
}
|
||||
m_Values[i] = o;
|
||||
// Make sure we have an editor for this property...
|
||||
if (m_Editors[i] == null) {
|
||||
continue;
|
||||
}
|
||||
// The property has changed! Update the editor.
|
||||
m_Editors[i].removePropertyChangeListener(this);
|
||||
m_Editors[i].setValue(o);
|
||||
m_Editors[i].addPropertyChangeListener(this);
|
||||
if (m_Views[i] != null) {
|
||||
//System.out.println("Trying to repaint " + (i + 1));
|
||||
m_Views[i].repaint();
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure the target bean gets repainted.
|
||||
if (Beans.isInstanceOf(m_Target, Component.class)) {
|
||||
//System.out.println("Beans.getInstanceOf repaint ");
|
||||
((Component)(Beans.getInstanceOf(m_Target, Component.class))).repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/** This method simply looks for an appropriate tiptext
|
||||
* @param name The name of the property
|
||||
* @param methods A list of methods to search.
|
||||
* @param target The target object
|
||||
* @return String for the tooltip.
|
||||
*/
|
||||
private String getToolTipText(String name, MethodDescriptor[] methods, Object target) {
|
||||
String result = "No tooltip available.";
|
||||
String tipName = name + "TipText";
|
||||
for (int j = 0; j < methods.length; j++) {
|
||||
String mname = methods[j].getDisplayName();
|
||||
Method meth = methods[j].getMethod();
|
||||
if (mname.equals(tipName)) {
|
||||
if (meth.getReturnType().equals(String.class)) {
|
||||
try {
|
||||
Object args[] = { };
|
||||
String tempTip = (String)(meth.invoke(target, args));
|
||||
int ci = tempTip.indexOf('.');
|
||||
if (ci < 0) result = tempTip;
|
||||
else result = tempTip.substring(0, ci);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} // end for looking for tiptext
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
124
src/javaeva/gui/PropertySheetPanelStat.java
Normal file
124
src/javaeva/gui/PropertySheetPanelStat.java
Normal file
@@ -0,0 +1,124 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.util.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.*;
|
||||
import java.lang.reflect.*;
|
||||
import javax.swing.*;
|
||||
import sun.beans.editors.*;
|
||||
import javaeva.tools.EVAHELP;
|
||||
import java.io.Serializable;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PropertySheetPanelStat extends JPanel implements Serializable {
|
||||
public final static boolean TRACE = false;
|
||||
private Object[] m_Values;
|
||||
private JCheckBoxFlag[] m_Views;
|
||||
private JLabel[] m_Labels;
|
||||
private boolean[] m_flag;
|
||||
/**
|
||||
* Creates the property sheet panel.
|
||||
*/
|
||||
public PropertySheetPanelStat() {
|
||||
// setBorder(BorderFactory.createLineBorder(Color.red));
|
||||
setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
|
||||
}
|
||||
/** A support object for handling property change listeners */
|
||||
private PropertyChangeSupport m_support = new PropertyChangeSupport(this);
|
||||
|
||||
|
||||
|
||||
public synchronized void setTarget(String[] names, boolean[] flag) {
|
||||
int componentOffset = 0;
|
||||
// Close any child windows at this point
|
||||
removeAll();
|
||||
GridBagLayout gbLayout = new GridBagLayout();
|
||||
setLayout(gbLayout);
|
||||
setVisible(false);
|
||||
|
||||
int rowHeight = 12;
|
||||
JTextArea jt = new JTextArea();
|
||||
JScrollPane js = null;
|
||||
|
||||
m_Values = new Object[flag.length];
|
||||
m_Views = new JCheckBoxFlag[flag.length];
|
||||
m_Labels = new JLabel[names.length];
|
||||
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
m_Labels[i] = new JLabel(names[i], SwingConstants.RIGHT);
|
||||
m_Labels[i].setBorder(BorderFactory.createEmptyBorder(10,10,0,5));
|
||||
m_Views[i] = new JCheckBoxFlag(flag[i]);
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
gbConstraints.anchor = GridBagConstraints.EAST;
|
||||
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbConstraints.gridy = i+componentOffset; gbConstraints.gridx = 0;
|
||||
gbLayout.setConstraints(m_Labels[i], gbConstraints);
|
||||
add(m_Labels[i]);
|
||||
JPanel newPanel = new JPanel();
|
||||
newPanel.setBorder(BorderFactory.createEmptyBorder(10,5,0,10));
|
||||
|
||||
newPanel.setLayout(new BorderLayout());
|
||||
newPanel.add(m_Views[i], BorderLayout.CENTER);
|
||||
gbConstraints = new GridBagConstraints();
|
||||
gbConstraints.anchor = GridBagConstraints.WEST;
|
||||
gbConstraints.fill = GridBagConstraints.BOTH;
|
||||
gbConstraints.gridy = i+componentOffset; gbConstraints.gridx = 1;
|
||||
gbConstraints.weightx = 100;
|
||||
gbLayout.setConstraints(newPanel, gbConstraints);
|
||||
add(newPanel);
|
||||
}
|
||||
validate();
|
||||
setVisible(true);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean[] getState() {
|
||||
boolean[] ret = new boolean[this.m_Views.length];
|
||||
for (int i=0;i<ret.length;i++) {
|
||||
ret[i] = m_Views[i].isSelected();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class JCheckBoxFlag extends JCheckBox {
|
||||
private boolean m_Flag = true;
|
||||
public JCheckBoxFlag (boolean flag) {
|
||||
super();
|
||||
m_Flag = flag;
|
||||
addItemListener(new ItemListener () {
|
||||
public void itemStateChanged (ItemEvent evt) {
|
||||
if (evt.getStateChange() == evt.SELECTED) {
|
||||
m_Flag = true;
|
||||
}
|
||||
if (evt.getStateChange() == evt.DESELECTED) {
|
||||
m_Flag = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
98
src/javaeva/gui/PropertySlider.java
Normal file
98
src/javaeva/gui/PropertySlider.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.border.*;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class PropertySlider extends JPanel {
|
||||
private PropertyEditor m_Editor;
|
||||
private JSlider m_Slider;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
PropertySlider(PropertyEditor pe) {
|
||||
//super(pe.getAsText());
|
||||
m_Editor = pe;
|
||||
//setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
|
||||
//setBorder(new TitledBorder(getString("SliderDemo.plain")));
|
||||
m_Slider = new JSlider(-10, 90, 20);
|
||||
//s.getAccessibleContext().setAccessibleName(getString("SliderDemo.plain"));
|
||||
//s.getAccessibleContext().setAccessibleDescription(getString("SliderDemo.a_plain_slider"));
|
||||
m_Slider.addChangeListener(new SliderListener());
|
||||
m_Slider.setValue(((Integer)m_Editor.getValue()).intValue());
|
||||
m_Slider.setPaintTicks(true);
|
||||
m_Slider.setMajorTickSpacing(20);
|
||||
m_Slider.setMinorTickSpacing(5);
|
||||
m_Slider.setPaintLabels( true );
|
||||
this.add(m_Slider);
|
||||
m_Editor.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
updateUs();
|
||||
}
|
||||
});
|
||||
addKeyListener(new KeyAdapter() {
|
||||
public void keyReleased(KeyEvent e) {
|
||||
// if (e.getKeyCode() == KeyEvent.VK_ENTER)
|
||||
updateEditor();
|
||||
}
|
||||
});
|
||||
addFocusListener(new FocusAdapter() {
|
||||
public void focusLost(FocusEvent e) {
|
||||
updateEditor();
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void updateUs() {
|
||||
try {
|
||||
//String x = m_Editor.getAsText();
|
||||
m_Slider.setValue(((Integer)m_Editor.getValue()).intValue());
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void updateEditor() {
|
||||
try {
|
||||
m_Editor.setValue(new Integer (m_Slider.getValue()));
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class SliderListener implements ChangeListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public SliderListener() {}
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
JSlider s1 = (JSlider)e.getSource();
|
||||
System.out.println("slider"+s1.getValue());
|
||||
updateEditor();
|
||||
}
|
||||
}
|
||||
}
|
||||
49
src/javaeva/gui/PropertyStringList.java
Normal file
49
src/javaeva/gui/PropertyStringList.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package javaeva.gui;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 23.03.2004
|
||||
* Time: 15:04:05
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class PropertyStringList implements java.io.Serializable {
|
||||
|
||||
public String[] m_Strings;
|
||||
public boolean[] m_Selection;
|
||||
|
||||
public PropertyStringList() {
|
||||
|
||||
}
|
||||
public PropertyStringList(PropertyStringList b) {
|
||||
if (b.m_Strings != null) {
|
||||
this.m_Strings = new String[b.m_Strings.length];
|
||||
System.arraycopy(b.m_Strings, 0, this.m_Strings, 0, this.m_Strings.length);
|
||||
}
|
||||
if (b.m_Selection != null) {
|
||||
this.m_Selection = new boolean[b.m_Selection.length];
|
||||
System.arraycopy(b.m_Selection, 0, this.m_Selection, 0, this.m_Selection.length);
|
||||
}
|
||||
}
|
||||
public Object clone() {
|
||||
return (Object) new PropertyStringList(this);
|
||||
}
|
||||
public void setStrings(String[] strings) {
|
||||
this.m_Strings = strings;
|
||||
this.m_Selection = new boolean[this.m_Strings.length];
|
||||
}
|
||||
public String[] getStrings() {
|
||||
return this.m_Strings;
|
||||
}
|
||||
|
||||
public void setSelection(boolean[] selection) {
|
||||
this.m_Selection = selection;
|
||||
}
|
||||
public boolean[] getSelection() {
|
||||
return this.m_Selection;
|
||||
}
|
||||
|
||||
public void setSelectionForElement(int index, boolean b) {
|
||||
this.m_Selection[index] = b;
|
||||
}
|
||||
}
|
||||
68
src/javaeva/gui/PropertyText.java
Normal file
68
src/javaeva/gui/PropertyText.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 57 $
|
||||
* $Date: 2007-05-04 14:22:16 +0200 (Fri, 04 May 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.*;
|
||||
import javax.swing.*;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PropertyText extends JTextField {
|
||||
private PropertyEditor m_Editor;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PropertyText(PropertyEditor pe) {
|
||||
super(pe.getAsText());
|
||||
m_Editor = pe;
|
||||
// m_Editor.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
// public void propertyChange(PropertyChangeEvent evt) {
|
||||
// updateUs();
|
||||
// }
|
||||
// });
|
||||
addKeyListener(new KeyAdapter() {
|
||||
public void keyReleased(KeyEvent e) {
|
||||
//if (e.getKeyCode() == KeyEvent.VK_ENTER)
|
||||
updateEditor();
|
||||
}
|
||||
});
|
||||
addFocusListener(new FocusAdapter() {
|
||||
public void focusLost(FocusEvent e) {
|
||||
updateEditor();
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void updateUs() {
|
||||
try {
|
||||
String x = m_Editor.getAsText();
|
||||
setText(x);
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void updateEditor() {
|
||||
try {
|
||||
String x = getText();
|
||||
m_Editor.setAsText(x);
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
}
|
||||
}
|
||||
55
src/javaeva/gui/PropertyValueSelector.java
Normal file
55
src/javaeva/gui/PropertyValueSelector.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 57 $
|
||||
* $Date: 2007-05-04 14:22:16 +0200 (Fri, 04 May 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.*;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PropertyValueSelector extends JComboBox {
|
||||
PropertyEditor m_Editor;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PropertyValueSelector(PropertyEditor pe) {
|
||||
m_Editor = pe;
|
||||
Object value = m_Editor.getAsText();
|
||||
String tags[] = m_Editor.getTags();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
ComboBoxModel model = new DefaultComboBoxModel(tags) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Object getSelectedItem() {
|
||||
return m_Editor.getAsText();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setSelectedItem(Object o) {
|
||||
m_Editor.setAsText((String)o);
|
||||
}
|
||||
};
|
||||
setModel(model);
|
||||
setSelectedItem(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
34
src/javaeva/gui/PropertyWeightedLPTchebycheff.java
Normal file
34
src/javaeva/gui/PropertyWeightedLPTchebycheff.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package javaeva.gui;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 15.07.2005
|
||||
* Time: 10:16:10
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class PropertyWeightedLPTchebycheff implements java.io.Serializable {
|
||||
|
||||
public double[] m_IdealValue;
|
||||
public double[] m_Weights;
|
||||
public int m_P = 0;
|
||||
|
||||
public PropertyWeightedLPTchebycheff() {
|
||||
}
|
||||
|
||||
public PropertyWeightedLPTchebycheff(PropertyWeightedLPTchebycheff e) {
|
||||
if (e.m_IdealValue != null) {
|
||||
this.m_IdealValue = new double[e.m_IdealValue.length];
|
||||
System.arraycopy(e.m_IdealValue, 0, this.m_IdealValue, 0, this.m_IdealValue.length);
|
||||
}
|
||||
if (e.m_Weights != null) {
|
||||
this.m_Weights = new double[e.m_Weights.length];
|
||||
System.arraycopy(e.m_Weights, 0, this.m_Weights, 0, this.m_Weights.length);
|
||||
}
|
||||
this.m_P = e.m_P;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return (Object) new PropertyWeightedLPTchebycheff(this);
|
||||
}
|
||||
}
|
||||
136
src/javaeva/gui/SerializedObject.java
Normal file
136
src/javaeva/gui/SerializedObject.java
Normal file
@@ -0,0 +1,136 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.io.*;
|
||||
import java.util.zip.*;
|
||||
/**
|
||||
* This class stores an object serialized in memory. It allows compression,
|
||||
* to be used to conserve memory (for example, when storing large strings
|
||||
* in memory), or can be used as a mechanism for deep copying objects.
|
||||
*
|
||||
*/
|
||||
public class SerializedObject implements Serializable {
|
||||
/** Stores the serialized object */
|
||||
private byte [] m_Serialized;
|
||||
/** True if the object has been compressed during storage */
|
||||
private boolean m_Compressed;
|
||||
/**
|
||||
* Serializes the supplied object into a byte array without compression.
|
||||
*
|
||||
* @param obj the Object to serialize.
|
||||
* @exception Exception if the object is not Serializable.
|
||||
*/
|
||||
public SerializedObject(Object obj) throws Exception {
|
||||
this(obj, false);
|
||||
}
|
||||
/**
|
||||
* Serializes the supplied object into a byte array.
|
||||
*
|
||||
* @param obj the Object to serialize.
|
||||
* @param compress true if the object should be stored compressed.
|
||||
* @exception Exception if the object is not Serializable.
|
||||
*/
|
||||
public SerializedObject(Object obj, boolean compress) throws Exception {
|
||||
//System.err.print("."); System.err.flush();
|
||||
m_Compressed = compress;
|
||||
m_Serialized = toByteArray(obj, m_Compressed);
|
||||
}
|
||||
/**
|
||||
* Serializes the supplied object to a byte array.
|
||||
*
|
||||
* @param obj the Object to serialize
|
||||
* @param compress true if the object should be compressed.
|
||||
* @return the byte array containing the serialized object.
|
||||
* @exception Exception if the object is not Serializable.
|
||||
*/
|
||||
protected static byte [] toByteArray(Object obj, boolean compress) throws Exception {
|
||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||
OutputStream os = bo;
|
||||
if (compress)
|
||||
os = new GZIPOutputStream(os);
|
||||
os = new BufferedOutputStream(os);
|
||||
ObjectOutputStream oo = new ObjectOutputStream(os);
|
||||
oo.writeObject(obj);
|
||||
oo.close();
|
||||
return bo.toByteArray();
|
||||
}
|
||||
/**
|
||||
* Gets the object stored in this SerializedObject. The object returned
|
||||
* will be a deep copy of the original stored object.
|
||||
*
|
||||
* @return the deserialized Object.
|
||||
*/
|
||||
public Object getObject() {
|
||||
try {
|
||||
InputStream is = new ByteArrayInputStream(m_Serialized);
|
||||
if (m_Compressed) {
|
||||
is = new GZIPInputStream(is);
|
||||
}
|
||||
is = new BufferedInputStream(is);
|
||||
ObjectInputStream oi = new ObjectInputStream(is);
|
||||
Object result = oi.readObject();
|
||||
oi.close();
|
||||
return result;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this object with another for equality.
|
||||
*
|
||||
* @param other the other Object.
|
||||
* @return true if the objects are equal.
|
||||
*/
|
||||
public final boolean equals(Object other) {
|
||||
|
||||
// Check class type
|
||||
if ((other == null) || !(other.getClass().equals(this.getClass()))) {
|
||||
return false;
|
||||
}
|
||||
// Check serialized length
|
||||
byte [] os = ((SerializedObject)other).m_Serialized;
|
||||
if (os.length != m_Serialized.length) {
|
||||
return false;
|
||||
}
|
||||
// Check serialized contents
|
||||
for (int i = 0; i < m_Serialized.length; i++) {
|
||||
if (m_Serialized[i] != os[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hashcode for this object.
|
||||
*
|
||||
* @return the hashcode for this object.
|
||||
*/
|
||||
public final int hashCode() {
|
||||
return m_Serialized.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a text representation of the state of this object.
|
||||
*
|
||||
* @return a String representing this object.
|
||||
*/
|
||||
public String toString() {
|
||||
|
||||
return (m_Compressed ? "Compressed object: " : "Uncompressed object: ")
|
||||
+ m_Serialized.length + " bytes";
|
||||
}
|
||||
}
|
||||
137
src/javaeva/gui/StatisticsEditor.java
Normal file
137
src/javaeva/gui/StatisticsEditor.java
Normal file
@@ -0,0 +1,137 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 194 $
|
||||
* $Date: 2007-10-23 13:43:24 +0200 (Tue, 23 Oct 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
|
||||
import java.beans.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javaeva.server.stat.GenericStatistics;
|
||||
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
public class StatisticsEditor implements PropertyEditor {
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
private PropertySheetPanelStat m_StatPanel;
|
||||
private JScrollPane m_ScrollPane;
|
||||
private JPanel m_Panel;
|
||||
private GenericStatistics m_Value;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StatisticsEditor () {
|
||||
super();
|
||||
m_StatPanel = new PropertySheetPanelStat();
|
||||
m_StatPanel.addPropertyChangeListener(
|
||||
new PropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
m_Support.firePropertyChange("", null, null);
|
||||
}
|
||||
});
|
||||
m_ScrollPane = new JScrollPane(m_StatPanel);
|
||||
m_Panel = new JPanel();
|
||||
m_Panel.setLayout(new BorderLayout());
|
||||
|
||||
m_Panel.add(m_ScrollPane, BorderLayout.CENTER);
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setValue (Object value) {
|
||||
if (value instanceof GenericStatistics) {
|
||||
m_Value=(GenericStatistics) value;
|
||||
m_StatPanel.setTarget(m_Value.getPropertyNames(),m_Value.getState());
|
||||
}
|
||||
m_Support.firePropertyChange("", null, null);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Object getValue () {
|
||||
System.out.println("getValue !!!!!!!!!!!!");
|
||||
m_Value.setState(m_StatPanel.getState());
|
||||
return m_Value;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getJavaInitializationString () {
|
||||
return "null";
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean isPaintable () {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void paintValue (Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent())/2;
|
||||
//String rep = EVAHELP.cutClassName(m_ElementClass.getName());
|
||||
gfx.drawString("StatisticeEditor", 2, fm.getHeight() + vpad - 3);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText () {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText (String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags () {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean supportsCustomEditor () {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Component getCustomEditor () {
|
||||
return m_Panel;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addPropertyChangeListener (PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener (PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
146
src/javaeva/gui/TagEditor.java
Normal file
146
src/javaeva/gui/TagEditor.java
Normal file
@@ -0,0 +1,146 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 14 $
|
||||
* $Date: 2006-12-18 16:32:23 +0100 (Mon, 18 Dec 2006) $
|
||||
* $Author: marcekro $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javaeva.tools.SelectedTag;
|
||||
import javaeva.tools.Tag;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.*;
|
||||
import java.awt.Toolkit;
|
||||
import java.beans.*;
|
||||
import javax.swing.*;
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
import javaeva.client.EvAClient;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TagEditor extends PropertyEditorSupport {
|
||||
/**
|
||||
* Returns a description of the property value as java source.
|
||||
*
|
||||
* @return a value of type 'String'
|
||||
*/
|
||||
public String getJavaInitializationString() {
|
||||
|
||||
SelectedTag s = (SelectedTag)getValue();
|
||||
Tag [] tags = s.getTags();
|
||||
String result = "new SelectedTag("
|
||||
+ s.getSelectedTag().getID()
|
||||
+ ", {\n";
|
||||
for (int i = 0; i < tags.length; i++) {
|
||||
result += "new Tag(" + tags[i].getID()
|
||||
+ ",\"" + tags[i].getString()
|
||||
+ "\")";
|
||||
if (i < tags.length - 1) {
|
||||
result += ',';
|
||||
}
|
||||
result += '\n';
|
||||
}
|
||||
return result + "})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current value as text.
|
||||
*
|
||||
* @return a value of type 'String'
|
||||
*/
|
||||
public String getAsText() {
|
||||
SelectedTag s = (SelectedTag)getValue();
|
||||
return s.getSelectedTag().getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current property value as text.
|
||||
*
|
||||
* @param text the text of the selected tag.
|
||||
* @exception java.lang.IllegalArgumentException if an error occurs
|
||||
*/
|
||||
public void setAsText(String text) throws java.lang.IllegalArgumentException {
|
||||
SelectedTag s = (SelectedTag)getValue();
|
||||
Tag [] tags = s.getTags();
|
||||
try {
|
||||
for (int i = 0; i < tags.length; i++) {
|
||||
if (text.equals(tags[i].getString())) {
|
||||
setValue(new SelectedTag(tags[i].getID(), tags));
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new java.lang.IllegalArgumentException(text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of tags that can be selected from.
|
||||
*
|
||||
* @return an array of string tags.
|
||||
*/
|
||||
public String[] getTags() {
|
||||
|
||||
SelectedTag s = (SelectedTag)getValue();
|
||||
Tag [] tags = s.getTags();
|
||||
String [] result = new String [tags.length];
|
||||
for (int i = 0; i < tags.length; i++) {
|
||||
result[i] = tags[i].getString
|
||||
();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests out the selectedtag editor from the command line.
|
||||
*
|
||||
* @param args ignored
|
||||
*/
|
||||
public static void main(String [] args) {
|
||||
try {
|
||||
PropertyEditorManager.registerEditor(SelectedTag.class,TagEditor.class);
|
||||
Tag [] tags = {
|
||||
new Tag(1, "First option"),
|
||||
new Tag(2, "Second option"),
|
||||
new Tag(3, "Third option"),
|
||||
new Tag(4, "Fourth option"),
|
||||
new Tag(5, "Fifth option"),
|
||||
};
|
||||
SelectedTag initial = new SelectedTag(1, tags);
|
||||
TagEditor ce = new TagEditor();
|
||||
ce.setValue(initial);
|
||||
PropertyValueSelector ps = new PropertyValueSelector(ce);
|
||||
JFrame f = new JFrame();
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAClient.iconLocation);
|
||||
try {
|
||||
f.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find JavaEvA icon, please move rescoure folder to working directory!");
|
||||
}
|
||||
f.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
f.getContentPane().setLayout(new BorderLayout());
|
||||
f.getContentPane().add(ps, BorderLayout.CENTER);
|
||||
f.pack();
|
||||
f.setVisible(true);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
105
src/javaeva/gui/TopoPlot.java
Normal file
105
src/javaeva/gui/TopoPlot.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 306 $
|
||||
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import wsi.ra.chart2d.*;
|
||||
import java.awt.*;
|
||||
|
||||
import javaeva.server.go.problems.Interface2DBorderProblem;
|
||||
import wsi.ra.diagram.ColorBarCalculator;
|
||||
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TopoPlot extends Plot {
|
||||
|
||||
public int gridx = 50;
|
||||
public int gridy = 50;
|
||||
int colorScale = ColorBarCalculator.BLUE_TO_RED;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public TopoPlot(String PlotName,String xname,String yname) {
|
||||
super(PlotName, xname, yname);
|
||||
//if (TRACE) System.out.println("Constructor TopoPlot "+PlotName);
|
||||
}
|
||||
public TopoPlot(String PlotName,String xname,String yname,double[] a, double[] b) {
|
||||
super(PlotName, xname, yname, a, b);
|
||||
//if (TRACE) System.out.println("Constructor TopoPlot "+PlotName);
|
||||
}
|
||||
/**
|
||||
* Defines parameters used for drawing the topology.
|
||||
* @param gridX the x-resolution of the topology, higher value means higher resolution
|
||||
* @param gridY the y-resolution of the topology, higher value means higher resolution
|
||||
* @param color_scale the topologies color coding. Values (0-3) are valid. @See ColorBarCalculator.
|
||||
*/
|
||||
public void setParams(int gridX, int gridY, int color_scale) {
|
||||
if (gridX>m_Frame.getWidth())
|
||||
gridX = m_Frame.getWidth();
|
||||
if (gridY>m_Frame.getHeight())
|
||||
gridY = m_Frame.getHeight();
|
||||
gridx = gridX;
|
||||
gridy = gridY;
|
||||
colorScale = color_scale;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines the topology (by setting a specific problem) and draws the topology
|
||||
*/
|
||||
public void setTopology(Interface2DBorderProblem problem) {
|
||||
double sizeX = java.lang.Math.abs( problem.get2DBorder()[0][1]-problem.get2DBorder()[0][0]);
|
||||
double sizeY = java.lang.Math.abs( problem.get2DBorder()[1][1]-problem.get2DBorder()[1][0]);
|
||||
double rx, ry;
|
||||
double rw = sizeX/gridx;
|
||||
double rh = sizeY/gridy;
|
||||
double[] pos = new double[2];
|
||||
//double fitRange = java.lang.Math.abs(problem.getMinFitness()-problem.getMaxFitness() );
|
||||
double fitRange = 0, max = -Double.MAX_VALUE, min = Double.MAX_VALUE, tmp;
|
||||
for (int x=0; x<gridx; x++) {
|
||||
for (int y=0; y<gridy; y++) {
|
||||
rx = problem.get2DBorder()[0][0]+x*rw;
|
||||
ry = problem.get2DBorder()[1][0]+y*rh;
|
||||
pos[0] = rx; pos[1] = ry;
|
||||
tmp = (float)(problem.functionValue(pos));
|
||||
if (tmp < min) min = tmp;
|
||||
if (tmp > max) max = tmp;
|
||||
} // for y
|
||||
} // for x
|
||||
fitRange = java.lang.Math.abs(max - min);
|
||||
ColorBarCalculator colorBar = new ColorBarCalculator(colorScale);
|
||||
|
||||
m_Frame.setVisible(false);
|
||||
for (int x=0; x<gridx; x++) {
|
||||
for (int y=0; y<gridy; y++) {
|
||||
rx = problem.get2DBorder()[0][0]+x*rw;
|
||||
ry = problem.get2DBorder()[1][0]+y*rh;
|
||||
pos[0] = rx; pos[1] = ry;
|
||||
DRectangle rect = new DRectangle(rx,ry,rw,rh);
|
||||
Color color = new Color(colorBar.getRGB((float)(problem.functionValue(pos)/fitRange))); // Color color = new Color(255,(int)(problem.doEvaluation(pos)[0]/fitRange*255),(int)(problem.doEvaluation(pos)[0]/fitRange*255));
|
||||
rect.setColor(color);
|
||||
rect.setFillColor(color);
|
||||
m_PlotArea.addDElement(rect);
|
||||
} // for y
|
||||
} // for x
|
||||
m_Frame.setVisible(true);
|
||||
|
||||
} // setTopology
|
||||
|
||||
|
||||
|
||||
} // class
|
||||
19
src/javaeva/gui/TreeElement.java
Normal file
19
src/javaeva/gui/TreeElement.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package javaeva.gui;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 10 $
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
public interface TreeElement {
|
||||
public int getNumber();
|
||||
public TreeElement getComponent(int index);
|
||||
public TreeElement[] getComponents();
|
||||
}
|
||||
66
src/javaeva/gui/WindowCloseAction.java
Normal file
66
src/javaeva/gui/WindowCloseAction.java
Normal file
@@ -0,0 +1,66 @@
|
||||
//package javaeva.gui;
|
||||
///*==========================================================================*
|
||||
// * IMPORTS
|
||||
// *==========================================================================*/
|
||||
//import javaeva.client.EvAClient;
|
||||
//import javax.swing.event.InternalFrameListener;
|
||||
//import javax.swing.event.InternalFrameEvent;
|
||||
//import javax.swing.JOptionPane;
|
||||
//import java.awt.event.ActionEvent;
|
||||
///*==========================================================================*
|
||||
//* CLASS DECLARATION
|
||||
//*==========================================================================*/
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//public class WindowCloseAction extends ExtAction implements InternalFrameListener{
|
||||
// private EvAClient m_App;
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// public WindowCloseAction(String s,String toolTip,EvAClient App){
|
||||
// super(s, toolTip);
|
||||
// m_App = App;
|
||||
// }
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// private void close(JDocFrame f){
|
||||
// if(f == null) return;
|
||||
// boolean doClose = false;
|
||||
// if(f.isChanged()){
|
||||
// switch(JOptionPane.showConfirmDialog(m_App.getDesktop(), "M<>chten Sie die <20>nderungen an "
|
||||
// + f.getTitle() + " speichern?", "Frage", JOptionPane.YES_NO_CANCEL_OPTION)){
|
||||
// case JOptionPane.YES_OPTION:
|
||||
// System.out.println(f.getTitle() + " geschlossen, <20>nderungen gespeichert.");
|
||||
// doClose = true;
|
||||
// break;
|
||||
// case JOptionPane.NO_OPTION:
|
||||
// doClose = true;
|
||||
// break;
|
||||
// case JOptionPane.CANCEL_OPTION:;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// doClose = true;
|
||||
// if(doClose) f.dispose();
|
||||
// }
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// public void actionPerformed(ActionEvent e){
|
||||
// close((JDocFrame)((ExtDesktopManager)m_App.getDesktop().getDesktopManager()).getActiveFrame());
|
||||
// }
|
||||
// public void internalFrameOpened(InternalFrameEvent e){}
|
||||
// public void internalFrameClosed(InternalFrameEvent e){}
|
||||
// public void internalFrameIconified(InternalFrameEvent e){}
|
||||
// public void internalFrameDeiconified(InternalFrameEvent e){}
|
||||
// public void internalFrameActivated(InternalFrameEvent e){}
|
||||
// public void internalFrameDeactivated(InternalFrameEvent e){}
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// public void internalFrameClosing(InternalFrameEvent e){
|
||||
// close((JDocFrame)e.getSource());
|
||||
// }
|
||||
//}
|
||||
33
src/javaeva/server/EvAMainAdapter.java
Normal file
33
src/javaeva/server/EvAMainAdapter.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package javaeva.server;
|
||||
/**
|
||||
* Title: javaeva
|
||||
* Description: API for distributed and parallel computing.
|
||||
* Copyright: Copyright (c) 2004
|
||||
* Company: University of Tuebingen
|
||||
* @version: $Revision: 259 $
|
||||
* $Date: 2007-11-16 17:25:09 +0100 (Fri, 16 Nov 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
|
||||
import javaeva.server.modules.ModuleAdapter;
|
||||
import wsi.ra.jproxy.MainAdapter;
|
||||
import wsi.ra.jproxy.MainAdapterClient;
|
||||
/*==========================================================================*
|
||||
* INTERFACE DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface EvAMainAdapter extends MainAdapter {
|
||||
|
||||
public String[] getModuleNameList();
|
||||
// returns the corresponding ModuleAdapter
|
||||
public ModuleAdapter getModuleAdapter(String str,
|
||||
boolean withoutRMI,
|
||||
String hostAddress,
|
||||
MainAdapterClient client);
|
||||
|
||||
}
|
||||
50
src/javaeva/server/EvAMainAdapterImpl.java
Normal file
50
src/javaeva/server/EvAMainAdapterImpl.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package javaeva.server;
|
||||
|
||||
/**
|
||||
* Title: The JProxy Framework
|
||||
* Description: API for distributed and parallel computing.
|
||||
* Copyright: Copyright (c) 2004
|
||||
* Company: University of Tuebingen
|
||||
* @version: $Revision: 315 $
|
||||
* $Date: 2007-12-04 15:23:57 +0100 (Tue, 04 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javaeva.client.EvAClient;
|
||||
import javaeva.server.modules.ModuleAdapter;
|
||||
import wsi.ra.jproxy.MainAdapterClient;
|
||||
import wsi.ra.jproxy.MainAdapterImpl;
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class EvAMainAdapterImpl extends MainAdapterImpl implements EvAMainAdapter {
|
||||
private ModuleServer m_ModulServer=null;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public EvAMainAdapterImpl() {
|
||||
super();
|
||||
m_ModulServer = new ModuleServer(EvAClient.getProperties());
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getModuleNameList() {
|
||||
return m_ModulServer.getModuleNameList();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ModuleAdapter getModuleAdapter(String str, boolean withoutRMI, String hostAddress, MainAdapterClient client) {
|
||||
if (TRACE) System.out.println("MainAdapterImpl.GetModuleAdapter() for module " +
|
||||
str +" for Client: "+hostAddress+ " called");
|
||||
return m_ModulServer.createModuleAdapter(str,client,withoutRMI,hostAddress);
|
||||
}
|
||||
}
|
||||
|
||||
148
src/javaeva/server/EvAServer.java
Normal file
148
src/javaeva/server/EvAServer.java
Normal file
@@ -0,0 +1,148 @@
|
||||
package javaeva.server;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 320 $
|
||||
* $Date: 2007-12-06 16:05:11 +0100 (Thu, 06 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.net.InetAddress;
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// -Xrunhprof:cpu=times
|
||||
// -Djava.security.policy=server.policy
|
||||
///////////////////////////////////////////////////////////////
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class EvAServer {
|
||||
/* Version string of the server application. */
|
||||
public static final String Version = new String ("2.00");
|
||||
public static boolean TRACE = false;
|
||||
/* MainAdapterImp object. This is need for the first
|
||||
connection between the server and the client program. */
|
||||
public EvAMainAdapter m_MainRemoteObject;
|
||||
//private EvAComAdapter m_ComAdapter;
|
||||
public static String m_UserName;
|
||||
public static int m_NumberOfVM =0;
|
||||
private RMIServerEvA m_RMIServer;
|
||||
/**
|
||||
* Constructor of EvAServer.
|
||||
* Calls RMIConnection().
|
||||
*/
|
||||
public EvAServer(boolean insideClient, boolean Restart) {
|
||||
System.out.println ("Number of CPUs :" +Runtime.getRuntime().availableProcessors());
|
||||
// m_InsideClient = insideClient;
|
||||
// m_Restart = Restart;
|
||||
System.out.println ("*******************************************************************************");
|
||||
System.out.println ("This is EvA Server Version: "+ Version+ " CommVersion: "+Version);
|
||||
//System.out.println ("Java Version: " + System.getProperty("java.version") );
|
||||
System.out.println ("*******************************************************************************");
|
||||
m_UserName = System.getProperty("user.name");
|
||||
// RMIConnection();
|
||||
// m_ComAdapter = new EvAComAdapter();
|
||||
// RMIProxyRemote.setComAdaper(m_ComAdapter);
|
||||
m_RMIServer = RMIServerEvA.getInstance();
|
||||
}
|
||||
/**
|
||||
* Main method of this class.
|
||||
* Is the starting point of the server application.
|
||||
*/
|
||||
static public void main ( String[] args ){
|
||||
boolean Restart = false;
|
||||
boolean nomulti = false;
|
||||
for (int i=0;i<args.length;i++) {
|
||||
System.out.println("args = "+args[i]);
|
||||
if (args[i].equals("restart"))
|
||||
Restart = true;
|
||||
if (args[i].equals("nomulti"))
|
||||
nomulti = true;
|
||||
|
||||
}
|
||||
//Runtime.getRuntime().addShutdownHook(new ExitThread());
|
||||
if (Restart== true) {
|
||||
String MyHostName = "Host";
|
||||
try {
|
||||
MyHostName = InetAddress.getLocalHost().getHostName();
|
||||
} catch (Exception e) {
|
||||
System.out.println("ERROR getting HostName (EvAServer.main) "+e.getMessage());
|
||||
}
|
||||
try {Thread.sleep(2000);}
|
||||
catch(Exception e) {
|
||||
System.out.println("Error in sleep of ExitThread");
|
||||
}
|
||||
try {
|
||||
System.setOut(new PrintStream(
|
||||
new FileOutputStream(MyHostName+"_server.txt")));
|
||||
} catch (Exception e) {
|
||||
System.out.println("System.setOut"+e.getMessage());
|
||||
}
|
||||
}
|
||||
EvAServer Application = new EvAServer(false,Restart); // false => started not inside the client, solo server
|
||||
// if (nomulti==false)
|
||||
// Application.multiServers(1);
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void multiServers(int size) {
|
||||
for (int i =0;i<size;i++) {
|
||||
try {Thread.sleep(4000);}
|
||||
catch(Exception e) {
|
||||
System.out.println("Error in sleep of ExitThread");
|
||||
}
|
||||
if (TRACE) System.out.println(" start multiServers int i= "+i);
|
||||
try {
|
||||
System.out.println("Calling the command:"+"java -cp \".:../lib/jdom.jar\" javaeva.server.EvAServer nomulti");
|
||||
Process pro = Runtime.getRuntime().exec("java -cp \".:../lib/jdom.jar:../lib/log4j.jar\" javaeva.server.EvAServer nomulti");
|
||||
//Process pro = Runtime.getRuntime().exec("server");
|
||||
BufferedReader in = new BufferedReader ( new InputStreamReader (pro.getInputStream()));
|
||||
//pro
|
||||
String line = null;
|
||||
while (true) {
|
||||
while((line = in.readLine()) != null ) {
|
||||
System.out.println(line);
|
||||
}
|
||||
}
|
||||
//System.out.println("");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error in calling the command:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public RMIServerEvA getRMIServer() {
|
||||
return m_RMIServer;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private int getNumberOfVM(String[] list) {
|
||||
int ret = 0;
|
||||
for (int i=0;i<list.length;i++) {
|
||||
if (list[i].indexOf(EvAMainAdapterImpl.MAIN_ADAPTER_NAME)!= -1)
|
||||
ret++;
|
||||
}
|
||||
if (TRACE) System.out.println(" getNumberOfVM() NumberOfVM ="+ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
206
src/javaeva/server/ModuleServer.java
Normal file
206
src/javaeva/server/ModuleServer.java
Normal file
@@ -0,0 +1,206 @@
|
||||
package javaeva.server;
|
||||
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 320 $
|
||||
* $Date: 2007-12-06 16:05:11 +0100 (Thu, 06 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
|
||||
import javaeva.server.modules.ModuleAdapter;
|
||||
import javaeva.tools.EVAERROR;
|
||||
import javaeva.tools.EVAHELP;
|
||||
import javaeva.tools.ReflectPackage;
|
||||
|
||||
import wsi.ra.jproxy.MainAdapterClient;
|
||||
import wsi.ra.jproxy.RMIProxyLocal;
|
||||
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ModuleServer {
|
||||
public static boolean TRACE = false;
|
||||
private int m_InstanceCounter = 0;
|
||||
private ArrayList<Class> m_ModuleClassList;
|
||||
private ArrayList m_RunnungModules;
|
||||
private ModuleAdapter m_ModuleAdapter;
|
||||
private int m_ModuleAdapterCounter = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ModuleServer(Properties EvAProps) {
|
||||
if (TRACE)
|
||||
System.out.println("Constructor ModuleServer():");
|
||||
if (m_InstanceCounter > 0) {
|
||||
EVAERROR.EXIT("ModuleServer twice created");
|
||||
}
|
||||
m_RunnungModules = new ArrayList();
|
||||
m_ModuleClassList = new ArrayList<Class>();
|
||||
|
||||
String modulePckg = null;
|
||||
Class filterBy = null;
|
||||
try {
|
||||
modulePckg = EvAProps.getProperty("ModulePackage");
|
||||
filterBy = Class.forName(EvAProps.getProperty("ModuleFilterClass"));
|
||||
} catch(Exception e) {
|
||||
System.err.println("Couldnt load modules:" + e.getMessage());
|
||||
System.err.println("module path was " + modulePckg);
|
||||
System.err.println("filter class path was " + ((filterBy==null) ? "null" : filterBy.getName()));
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// this gets a list of all valid modules from the package
|
||||
Class[] classes = ReflectPackage.getAssignableClassesInPackage(modulePckg, filterBy, true, true);
|
||||
for (Object cls : classes) {
|
||||
if (TRACE) System.out.println("- " + ((Class)cls).getName());
|
||||
m_ModuleClassList.add((Class)cls);
|
||||
}
|
||||
|
||||
m_InstanceCounter++;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getModuleNameList() {
|
||||
ArrayList<String> ModuleNameList = new ArrayList<String>();
|
||||
for (int i = 0; i < m_ModuleClassList.size(); i++) {
|
||||
try {
|
||||
Class Modul = (Class) m_ModuleClassList.get(i);
|
||||
Method[] methods = Modul.getDeclaredMethods();
|
||||
for (int ii = 0; ii < methods.length; ii++) {
|
||||
if (methods[ii].getName().equals("getName") == true) {
|
||||
//System.out.println("name is =="+methods[ii].invoke(null,null));
|
||||
String name = (String)methods[ii].invoke((Object[])null, (Object[])null);
|
||||
if (name != null) ModuleNameList.add(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//ModuleNameList.add ( Modul.getName());
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println("ModuleServer.getModuleNameList() " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
// and the running modules
|
||||
// @todo running modules sind abgeschaltet
|
||||
|
||||
for (int i = 0; i < m_RunnungModules.size(); i++) {
|
||||
String AdapterName = null;
|
||||
try {
|
||||
AdapterName = ( (ModuleAdapter) m_RunnungModules.get(i)).getAdapterName();
|
||||
}
|
||||
catch (Exception ee) {
|
||||
System.err.println("Error: GetAdapterName" + ee.getMessage());
|
||||
}
|
||||
ModuleNameList.add(AdapterName);
|
||||
}
|
||||
|
||||
String[] x = new String[ModuleNameList.size()];
|
||||
ModuleNameList.toArray(x);
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ModuleAdapter createModuleAdapter(String selectedModuleName,
|
||||
MainAdapterClient Client, boolean runWithoutRMI,
|
||||
String hostAddress) {
|
||||
m_ModuleAdapterCounter++;
|
||||
String adapterName = new String("ERROR MODULADAPTER !!");
|
||||
if (TRACE) {
|
||||
System.out.println("ModuleServer.CreateModuleAdapter()");
|
||||
System.out.println(" ModuleServer.CreateModuleAdapter for:" +
|
||||
selectedModuleName);
|
||||
System.out.println(" m_ModulAdapterCounter =" + m_ModuleAdapterCounter);
|
||||
System.out.println(" Start of EvA RMI-ModulAdapter for Module: " +
|
||||
selectedModuleName);
|
||||
}
|
||||
String moduleName;
|
||||
Class module;
|
||||
Method[] methods;
|
||||
for (int i = 0; i < m_ModuleClassList.size(); i++) {
|
||||
moduleName = null;
|
||||
module = m_ModuleClassList.get(i);
|
||||
|
||||
try {
|
||||
methods = module.getDeclaredMethods();
|
||||
|
||||
for (int ii = 0; ii < methods.length; ii++) {
|
||||
if (methods[ii].getName().equals("getName") == true)
|
||||
moduleName = (String) methods[ii].invoke((Object[])null, (Object[])null);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println("ModuleServer.createModuleAdapter() " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
if ((moduleName != null) && (selectedModuleName.equals(moduleName))) {
|
||||
if (TRACE) System.out.println("ModuleName: " + moduleName);
|
||||
try {
|
||||
adapterName = new String(m_ModuleAdapterCounter + "_Running_" +
|
||||
selectedModuleName);
|
||||
|
||||
// create a module instance
|
||||
Constructor[] Constructor = module.getConstructors();
|
||||
Object[] Para = new Object[2];
|
||||
Class paramTypes[] = (Constructor[0]).getParameterTypes();
|
||||
Para[0] = paramTypes[0].cast(adapterName);
|
||||
Para[1] = paramTypes[1].cast(Client);
|
||||
m_ModuleAdapter = (ModuleAdapter) Constructor[0].newInstance(Para);
|
||||
if (!runWithoutRMI) { // if we're using RMI, send the object to a remote server
|
||||
// for this to work the class of m_ModuleAdapter itself must implement the ModuleAdapter interface
|
||||
// for a strange reason, it is _not_ enough if a superclass implements the same interface!
|
||||
m_ModuleAdapter = (ModuleAdapter)RMIProxyLocal.newInstance(m_ModuleAdapter, adapterName);
|
||||
(m_ModuleAdapter).setRemoteThis(m_ModuleAdapter);
|
||||
}
|
||||
// m_RunnungModules.add(m_ModuleAdapter);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println("CLASSPATH " +
|
||||
System.getProperty("java.class.path"));
|
||||
e.printStackTrace();
|
||||
EVAERROR.EXIT("Error in RMI-Moduladapter initialization: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
if (TRACE) System.out.println("End of RMI-Moduladapter initialization !");
|
||||
return (ModuleAdapter) m_ModuleAdapter;
|
||||
}
|
||||
}
|
||||
// @todo running modules sind gerade noch abgeschaltet
|
||||
for (int i = 0; i < m_RunnungModules.size(); i++) {
|
||||
try {
|
||||
adapterName = ( (ModuleAdapter) m_RunnungModules.get(i)).getAdapterName();
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("Error : GetAdapterName" + e);
|
||||
}
|
||||
if (adapterName.equals(selectedModuleName)) {
|
||||
if (TRACE)
|
||||
System.out.println(" Choose a running Module!!! " + adapterName);
|
||||
m_ModuleAdapter = ( (ModuleAdapter) m_RunnungModules.get(i));
|
||||
return (ModuleAdapter) m_ModuleAdapter;
|
||||
}
|
||||
}
|
||||
|
||||
System.err.println("NO VALID MODULE DEFINED: " + selectedModuleName);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
56
src/javaeva/server/RMIServerEvA.java
Normal file
56
src/javaeva/server/RMIServerEvA.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package javaeva.server;
|
||||
/**
|
||||
* Title: The JProxy Framework
|
||||
* Description: API for distributed and parallel computing.
|
||||
* Copyright: Copyright (c) 2004
|
||||
* Company: University of Tuebingen
|
||||
* @version: $Revision: 250 $
|
||||
* $Date: 2007-11-13 10:32:19 +0100 (Tue, 13 Nov 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.rmi.Naming;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.Registry;
|
||||
import javaeva.client.EvAComAdapter;
|
||||
|
||||
import wsi.ra.jproxy.RMIProxyLocal;
|
||||
import wsi.ra.jproxy.RMIServer;
|
||||
///////////////////////////////////////////////////////////////
|
||||
//-Xrunhprof:cpu=times
|
||||
//-Djava.security.policy=server.policy
|
||||
///////////////////////////////////////////////////////////////
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RMIServerEvA extends RMIServer {
|
||||
|
||||
public static RMIServerEvA getInstance() {
|
||||
if (m_instance==null) {
|
||||
m_instance = new RMIServerEvA();
|
||||
}
|
||||
return (RMIServerEvA)m_instance;
|
||||
}
|
||||
|
||||
protected void createMainRemoteObject(String mainAdapterName) {
|
||||
try {
|
||||
m_MainRemoteObject = new EvAMainAdapterImpl();
|
||||
m_MainRemoteObject =
|
||||
(EvAMainAdapter) RMIProxyLocal.newInstance(
|
||||
m_MainRemoteObject,
|
||||
mainAdapterName + "_" + m_NumberOfVM);
|
||||
m_MainRemoteObject.setRemoteThis(m_MainRemoteObject);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
24
src/javaeva/server/go/CrossoverInterface.java
Normal file
24
src/javaeva/server/go/CrossoverInterface.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package javaeva.server.go;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 306 $
|
||||
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javaeva.server.stat.Statistics;
|
||||
/*==========================================================================*
|
||||
* INTERFACE DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface CrossoverInterface {
|
||||
public void addListener(Statistics e);
|
||||
}
|
||||
752
src/javaeva/server/go/GOStandaloneVersion.java
Normal file
752
src/javaeva/server/go/GOStandaloneVersion.java
Normal file
@@ -0,0 +1,752 @@
|
||||
package javaeva.server.go;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.List;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import javaeva.client.EvAClient;
|
||||
import javaeva.gui.JParaPanel;
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.ESIndividualDoubleData;
|
||||
import javaeva.server.go.individuals.GAIndividualDoubleData;
|
||||
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
||||
import javaeva.server.go.operators.crossover.CrossoverGANPoint;
|
||||
import javaeva.server.go.operators.mutation.InterfaceMutation;
|
||||
import javaeva.server.go.operators.mutation.MutateESLocal;
|
||||
import javaeva.server.go.operators.mutation.MutateESStandard;
|
||||
import javaeva.server.go.operators.selection.SelectTournament;
|
||||
import javaeva.server.go.operators.terminators.EvaluationTerminator;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.F1Problem;
|
||||
import javaeva.server.go.strategies.EvolutionStrategies;
|
||||
import javaeva.server.go.strategies.GeneticAlgorithm;
|
||||
import javaeva.server.go.strategies.InterfaceOptimizer;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
import javaeva.server.modules.GOParameters;
|
||||
import javaeva.tools.TokenHolder;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import wsi.ra.jproxy.ThreadProxy;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 306 $
|
||||
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopulationChangedEventListener, java.io.Serializable {
|
||||
|
||||
// Interface GUI Stuff
|
||||
transient private JFrame m_Frame;
|
||||
transient private JPanel m_MainPanel;
|
||||
transient private JPanel m_ButtonPanel;
|
||||
transient private JButton m_RunButton, m_StopButton, m_Continue, m_ShowSolution;
|
||||
transient private JComponent m_OptionsPanel, m_O1, m_O2;
|
||||
transient private JComponent m_StatusPanel;
|
||||
transient private JLabel m_StatusField;
|
||||
transient private JProgressBar m_ProgressBar;
|
||||
transient private SwingWorker worker;
|
||||
transient private boolean show = false;
|
||||
// transient private InterfaceTest test = new Test1();
|
||||
|
||||
// Opt. Algorithms and Parameters
|
||||
//transient private InterfaceOptimizer m_Optimizer = new EvolutionaryMultiObjectiveOptimization();
|
||||
//transient private InterfaceOptimizationProblem m_Problem = new TF1Problem();
|
||||
//transient private int m_FunctionCalls = 1000;
|
||||
private GOParameters m_GO;
|
||||
transient private int m_MultiRuns = 1;
|
||||
transient private int m_RecentFC;
|
||||
transient private int currentExperiment = 0;
|
||||
transient private int currentRun;
|
||||
transient private int currentProgress;
|
||||
transient private String m_ExperimentName;
|
||||
transient private String m_OutputPath = "";
|
||||
// transient private String m_OutputFileName = "none";
|
||||
// transient private GOStandaloneVersion m_yself;
|
||||
|
||||
// these parameters are for the continue option
|
||||
transient private Population m_Backup;
|
||||
transient private boolean m_ContinueFlag;
|
||||
|
||||
// Plot Panel stuff
|
||||
transient private javaeva.gui.Plot m_Plot;
|
||||
transient private ArrayList m_PerformedRuns = new ArrayList();
|
||||
transient private ArrayList m_TmpData;
|
||||
transient private BufferedWriter m_OutputFile;
|
||||
|
||||
// Test
|
||||
transient private List m_List;
|
||||
|
||||
|
||||
/** Create a new EALectureGUI.
|
||||
*/
|
||||
public GOStandaloneVersion() {
|
||||
// this.m_List = new List();
|
||||
// this.m_List.add("Test1");
|
||||
// this.m_List.add("Test2");
|
||||
// this.m_List.add("Test3");
|
||||
// this.m_yself = this;
|
||||
this.m_GO = GOParameters.getInstance();
|
||||
this.m_ExperimentName = this.m_GO.getOptimizer().getName()+"-"+this.m_PerformedRuns.size();
|
||||
this.m_GO.addPopulationChangedEventListener(this);
|
||||
RandomNumberGenerator.setseed(m_GO.getSeed());
|
||||
}
|
||||
|
||||
/** This method allows you to get the current GO parameters
|
||||
*
|
||||
*/
|
||||
public GOParameters getGOParameters() {
|
||||
return this.m_GO;
|
||||
}
|
||||
|
||||
/** This method will generate a Plot Frame and a main Editing Frame
|
||||
*/
|
||||
public void initFrame() {
|
||||
this.m_ProgressBar = new JProgressBar();
|
||||
// init the main frame
|
||||
this.m_Frame = new JFrame();
|
||||
this.m_Frame.setTitle("Genetic Optimizing");
|
||||
this.m_Frame.setSize(500, 400);
|
||||
this.m_Frame.setLocation(530, 50);
|
||||
this.m_Frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
// build the main panel
|
||||
this.m_MainPanel = new JPanel();
|
||||
this.m_Frame.getContentPane().add(this.m_MainPanel);
|
||||
this.m_MainPanel.setLayout(new BorderLayout());
|
||||
// build the button panel
|
||||
this.m_ButtonPanel = new JPanel();
|
||||
this.m_RunButton = new JButton("Run");
|
||||
this.m_RunButton.addActionListener(this.runListener);
|
||||
this.m_RunButton.setEnabled(true);
|
||||
this.m_RunButton.setToolTipText("Run the optimization process with the current parameter settings.");
|
||||
this.m_StopButton = new JButton("Stop");
|
||||
this.m_StopButton.addActionListener(this.stopListener);
|
||||
this.m_StopButton.setEnabled(false);
|
||||
this.m_StopButton.setToolTipText("Stop the runnig the optimization process.");
|
||||
this.m_Continue = new JButton("Continue");
|
||||
this.m_Continue.addActionListener(this.continueListener);
|
||||
this.m_Continue.setEnabled(false);
|
||||
this.m_Continue.setToolTipText("Resume the previous optimization (check termination criteria and multiruns = 1!).");
|
||||
this.m_ShowSolution = new JButton("Show Solution");
|
||||
this.m_ShowSolution.addActionListener(this.showSolListener);
|
||||
this.m_ShowSolution.setEnabled(true);
|
||||
this.m_ShowSolution.setToolTipText("Show the current best solution.");
|
||||
this.m_ButtonPanel.add(this.m_RunButton);
|
||||
this.m_ButtonPanel.add(this.m_Continue);
|
||||
this.m_ButtonPanel.add(this.m_StopButton);
|
||||
this.m_ButtonPanel.add(this.m_ShowSolution);
|
||||
this.m_MainPanel.add(this.m_ButtonPanel, BorderLayout.NORTH);
|
||||
|
||||
// build the Options Panel
|
||||
JParaPanel paraPanel = new JParaPanel(this, "MyGUI");
|
||||
Class object = null, editor = null;
|
||||
String tmp = "javaeva.server.oa.go.Tools.InterfaceTest";
|
||||
try {
|
||||
object = Class.forName(tmp);
|
||||
} catch(java.lang.ClassNotFoundException e) {
|
||||
System.out.println("No Class found for " + tmp);
|
||||
}
|
||||
tmp = "javaeva.gui.GenericObjectEditor";
|
||||
try {
|
||||
editor = Class.forName(tmp);
|
||||
} catch(java.lang.ClassNotFoundException e) {
|
||||
System.out.println("No Class found for " + tmp);
|
||||
}
|
||||
if ((object != null) && (editor != null)) paraPanel.registerEditor(object, editor);
|
||||
this.m_O1 = (paraPanel.installActions());
|
||||
EvAClient.setProperty("javaeva.server.oa.go.Tools.InterfaceTest", "javaeva.server.oa.go.Tools.Test1,javaeva.server.oa.go.Tools.Test2");
|
||||
this.m_OptionsPanel = new JTabbedPane();
|
||||
JParaPanel paraPanel2 = new JParaPanel(this.m_GO, "MyGUI");
|
||||
this.m_O2 = (paraPanel2.installActions());
|
||||
((JTabbedPane)this.m_OptionsPanel).addTab("GO Parameters", this.m_O2);
|
||||
((JTabbedPane)this.m_OptionsPanel).addTab("GO Statistics", this.m_O1);
|
||||
this.m_MainPanel.add(this.m_OptionsPanel, BorderLayout.CENTER);
|
||||
|
||||
// build the Status Panel
|
||||
this.m_StatusPanel = new JPanel();
|
||||
this.m_StatusPanel.setLayout(new BorderLayout());
|
||||
this.m_StatusField = new JLabel("Click Run to begin...");
|
||||
this.m_ProgressBar = new JProgressBar();
|
||||
this.m_StatusPanel.add(this.m_StatusField, BorderLayout.NORTH);
|
||||
this.m_StatusPanel.add(this.m_ProgressBar, BorderLayout.SOUTH);
|
||||
this.m_MainPanel.add(this.m_StatusPanel, BorderLayout.SOUTH);
|
||||
// The plot frame
|
||||
double[] tmpD = new double[2];
|
||||
tmpD[0] = 1;
|
||||
tmpD[1] = 1;
|
||||
this.m_Plot = new javaeva.gui.Plot("EA Lecture Plot", "Function calls", "Fitness", true);
|
||||
// validate and show
|
||||
this.m_Frame.validate();
|
||||
this.m_Frame.setVisible(true);
|
||||
}
|
||||
|
||||
/** This action listener, called by the "Run/Restart" button, will init the problem and start the computation.
|
||||
*/
|
||||
ActionListener runListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
worker = new SwingWorker() {
|
||||
public Object construct() {
|
||||
return doWork();
|
||||
}
|
||||
public void finished() {
|
||||
m_RunButton.setEnabled(true);
|
||||
m_Continue.setEnabled(true);
|
||||
m_StopButton.setEnabled(false);
|
||||
m_Backup = (Population) m_GO.getOptimizer().getPopulation().clone();
|
||||
}
|
||||
};
|
||||
worker.start();
|
||||
m_RunButton.setEnabled(false);
|
||||
m_Continue.setEnabled(false);
|
||||
m_StopButton.setEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener, called by the "Cancel" button, interrupts
|
||||
* the worker thread which is running this.doWork(). Note that
|
||||
* the doWork() method handles InterruptedExceptions cleanly.
|
||||
*/
|
||||
ActionListener stopListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
m_RunButton.setEnabled(true);
|
||||
m_Continue.setEnabled(true);
|
||||
m_StopButton.setEnabled(false);
|
||||
worker.interrupt();
|
||||
for (int i = 0; i < m_MultiRuns; i++) m_Plot.clearGraph(1000 +i);
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener, called by the "Cancel" button, interrupts
|
||||
* the worker thread which is running this.doWork(). Note that
|
||||
* the doWork() method handles InterruptedExceptions cleanly.
|
||||
*/
|
||||
ActionListener continueListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
// todo something need to be done here...
|
||||
worker = new SwingWorker() {
|
||||
public Object construct() {
|
||||
return doWork();
|
||||
}
|
||||
public void finished() {
|
||||
m_RunButton.setEnabled(true);
|
||||
m_Continue.setEnabled(true);
|
||||
m_StopButton.setEnabled(false);
|
||||
m_Backup = (Population) m_GO.getOptimizer().getPopulation().clone();
|
||||
m_ContinueFlag = false;
|
||||
}
|
||||
};
|
||||
// also mal ganz anders ich gehe davon aus, dass der Benutzer das Ding parametrisiert hat
|
||||
// setze einfach die Backup population ein...
|
||||
m_ContinueFlag = true;
|
||||
m_MultiRuns = 1; // multiruns machen bei continue einfach keinen Sinn...
|
||||
worker.start();
|
||||
m_RunButton.setEnabled(false);
|
||||
m_Continue.setEnabled(false);
|
||||
m_StopButton.setEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener, called by the "show" button will show the
|
||||
* currently best solution in a frame.
|
||||
*/
|
||||
ActionListener showSolListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setTitle("The current best solution for "+m_GO.getProblem().getName());
|
||||
frame.setSize(400, 300);
|
||||
frame.setLocation(450, 250);
|
||||
frame.getContentPane().add(m_GO.getProblem().drawIndividual(m_GO.getOptimizer().getPopulation().getBestEAIndividual()));
|
||||
frame.validate();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
};
|
||||
|
||||
/** This method gives the experimental settings and starts the work.
|
||||
*/
|
||||
public void startExperiment() {
|
||||
// This is for the CBN-TEST RUNS
|
||||
this.m_GO.setOptimizer(new EvolutionStrategies());
|
||||
this.m_GO.setProblem(new F1Problem());
|
||||
EvaluationTerminator terminator = new EvaluationTerminator();
|
||||
terminator.setFitnessCalls(50000);
|
||||
this.m_GO.setTerminator(terminator);
|
||||
this.m_MultiRuns = 10;
|
||||
int experimentType = 0;
|
||||
this.m_ExperimentName = "InferringGRN";
|
||||
this.m_GO.setOutputFileName("Result");
|
||||
this.m_OutputPath = "results/";
|
||||
// These are some tmp Variables
|
||||
InterfaceDataTypeDouble tmpIndy = new ESIndividualDoubleData();
|
||||
InterfaceMutation tmpMut = new MutateESStandard();
|
||||
|
||||
switch (experimentType) {
|
||||
case 0 : {
|
||||
// use the Struture Skeletalizing with GA
|
||||
this.m_GO.setOutputFileName("Prim4_StructSkelGATESTIT");
|
||||
GeneticAlgorithm ga = new GeneticAlgorithm();
|
||||
SelectTournament tour = new SelectTournament();
|
||||
tour.setTournamentSize(10);
|
||||
ga.setParentSelection(tour);
|
||||
ga.setPartnerSelection(tour);
|
||||
this.m_GO.setOptimizer(ga);
|
||||
this.m_GO.getOptimizer().getPopulation().setPopulationSize(100);
|
||||
F1Problem problem = new F1Problem();
|
||||
tmpIndy = new GAIndividualDoubleData();
|
||||
((GAIndividualDoubleData)tmpIndy).setCrossoverOperator(new CrossoverGANPoint());
|
||||
((GAIndividualDoubleData)tmpIndy).setCrossoverProbability(1.0);
|
||||
((GAIndividualDoubleData)tmpIndy).setMutationProbability(1.0);
|
||||
((F1Problem)problem).setEAIndividual(tmpIndy);
|
||||
//((FGRNInferringProblem)this.m_Problem).setStructreSkelInterval(1);
|
||||
this.m_GO.getOptimizer().SetProblem(problem);
|
||||
this.m_GO.getOptimizer().addPopulationChangedEventListener(this);
|
||||
this.doWork();
|
||||
break;
|
||||
}
|
||||
case 1 : {
|
||||
// use the simple ES Local
|
||||
this.m_GO.setOutputFileName("X360_StandardES");
|
||||
EvolutionStrategies es = new EvolutionStrategies();
|
||||
this.m_GO.setOptimizer(es);
|
||||
this.m_GO.getOptimizer().getPopulation().setPopulationSize(50);
|
||||
F1Problem problem = new F1Problem();
|
||||
tmpIndy = new ESIndividualDoubleData();
|
||||
((ESIndividualDoubleData)tmpIndy).setMutationOperator(new MutateESLocal());
|
||||
((F1Problem)problem).setEAIndividual(tmpIndy);
|
||||
//((FGRNInferringProblem)this.m_Problem).setUseHEigenMatrix(true);
|
||||
//((FGRNInferringProblem)this.m_Problem).setUseOnlyPositiveNumbers(true);
|
||||
this.m_GO.getOptimizer().SetProblem(problem);
|
||||
this.m_GO.getOptimizer().addPopulationChangedEventListener(this);
|
||||
this.doWork();
|
||||
break;
|
||||
}
|
||||
}
|
||||
String m_MyHostName = "_";
|
||||
try {
|
||||
m_MyHostName = InetAddress.getLocalHost().getHostName();
|
||||
} catch (Exception e) {
|
||||
System.out.println("ERROR getting HostName (GOStandalone.startExperiment) " + e.getMessage());
|
||||
}
|
||||
// EVAMail.SendMail("GOTask on "+m_MyHostName+ " finished", "Have a look at the results at the result file", "streiche@informatik.uni-tuebingen.de");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method represents the application code that we'd like to
|
||||
* run on a separate thread. It simulates slowly computing
|
||||
* a value, in this case just a string 'All Done'. It updates the
|
||||
* progress bar every half second to remind the user that
|
||||
* we're still busy.
|
||||
*/
|
||||
public Object doWork() {
|
||||
try {
|
||||
this.m_GO.saveInstance();
|
||||
if (this.show) this.m_StatusField.setText("Optimizing...");
|
||||
|
||||
RandomNumberGenerator.setseed(m_GO.getSeed());
|
||||
// opening output file...
|
||||
if (!this.m_GO.getOutputFileName().equalsIgnoreCase("none")) {
|
||||
String name = "";
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("E'_'yyyy.MM.dd'_'HH.mm.ss");
|
||||
String m_StartDate = formatter.format(new Date());
|
||||
name = this.m_OutputPath + this.m_GO.getOutputFileName() +"_"+this.m_ExperimentName+"_"+m_StartDate+".dat";
|
||||
try {
|
||||
this.m_OutputFile = new BufferedWriter(new OutputStreamWriter (new FileOutputStream (name)));
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("Could not open output file! Filename: " + name);
|
||||
}
|
||||
} else {
|
||||
this.m_OutputFile = null;
|
||||
}
|
||||
|
||||
// init problem
|
||||
this.m_GO.getProblem().initProblem();
|
||||
this.m_GO.getOptimizer().SetProblem(this.m_GO.getProblem());
|
||||
// int optimizer and population
|
||||
//this.m_GO.getOptimizer().init();
|
||||
|
||||
// init the log data
|
||||
ArrayList tmpMultiRun = new ArrayList();
|
||||
this.m_PerformedRuns.add(tmpMultiRun);
|
||||
|
||||
// something to log file
|
||||
//if (m_OutputFile != null) this.writeToFile(this.m_GO.getOptimizer().getStringRepresentation());
|
||||
//this.writeToFile("Here i'll write something characterizing the algorithm.");
|
||||
|
||||
for (int j = 0; j < this.m_MultiRuns; j++) {
|
||||
this.m_GO.getProblem().initProblem(); // in the loop as well, dynamic probs may need that (MK)
|
||||
this.m_TmpData = new ArrayList();
|
||||
this.currentRun = j;
|
||||
if (this.show)
|
||||
this.m_StatusField.setText("Optimizing Run " + (j+1) + " of " + this.m_MultiRuns + " Multi Runs...");
|
||||
if (Thread.interrupted())
|
||||
throw new InterruptedException();
|
||||
// write header to file
|
||||
this.writeToFile(" FitnessCalls\t Best\t Mean\t Worst \t" + this.m_GO.getProblem().getAdditionalFileStringHeader(this.m_GO.getOptimizer().getPopulation()));
|
||||
if ((this.m_ContinueFlag) && (this.m_Backup != null)) {
|
||||
this.m_RecentFC += this.m_Backup.getFunctionCalls();
|
||||
this.m_GO.getOptimizer().getProblem().initProblem();
|
||||
this.m_GO.getOptimizer().addPopulationChangedEventListener(null);
|
||||
this.m_GO.getOptimizer().setPopulation(this.m_Backup);
|
||||
this.m_GO.getOptimizer().getProblem().evaluate(this.m_GO.getOptimizer().getPopulation());
|
||||
this.m_GO.getOptimizer().getProblem().evaluate(this.m_GO.getOptimizer().getPopulation().getArchive());
|
||||
this.m_GO.getOptimizer().initByPopulation(this.m_Backup, false);
|
||||
this.m_GO.getOptimizer().getPopulation().SetFunctionCalls(0);
|
||||
this.m_GO.addPopulationChangedEventListener(this);
|
||||
} else {
|
||||
this.m_RecentFC = 0;
|
||||
this.m_GO.getOptimizer().init();
|
||||
}
|
||||
//while (this.m_GO.getOptimizer().getPopulation().getFunctionCalls() < this.m_FunctionCalls) {
|
||||
while (!this.m_GO.getTerminator().isTerminated(this.m_GO.getOptimizer().getPopulation())) {
|
||||
//System.out.println("Simulated Function calls "+ this.m_Optimizer.getPopulation().getFunctionCalls());
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
m_GO.getOptimizer().optimize();
|
||||
}
|
||||
System.gc();
|
||||
// @TODO if you want the final report include this
|
||||
//this.writeToFile(this.m_GO.getProblem().getStringRepresentationForProblem(this.m_GO.getOptimizer()));
|
||||
tmpMultiRun.add(this.m_TmpData);
|
||||
}
|
||||
if (this.show) this.m_Plot.setInfoString(this.currentExperiment, this.m_ExperimentName, 0.5f);
|
||||
if (this.show) this.draw();
|
||||
this.m_ExperimentName = this.m_GO.getOptimizer().getName()+"-"+this.m_PerformedRuns.size();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
updateStatus(0);
|
||||
if (this.show) this.m_StatusField.setText("Interrupted...");
|
||||
return "Interrupted";
|
||||
}
|
||||
if (this.m_OutputFile != null) {
|
||||
try {
|
||||
this.m_OutputFile.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Failed to close output file!");
|
||||
}
|
||||
}
|
||||
if (this.show) for (int i = 0; i < this.m_MultiRuns; i++) this.m_Plot.clearGraph(1000 +i);
|
||||
updateStatus(0);
|
||||
if (this.show) this.m_StatusField.setText("Finished...");
|
||||
return "All Done";
|
||||
}
|
||||
|
||||
/** This method refreshes the plot
|
||||
*/
|
||||
private void draw() {
|
||||
ArrayList multiRuns, singleRun;
|
||||
Double[] tmpD;
|
||||
double[][] data;
|
||||
// Color tmpColor;
|
||||
|
||||
for (int i = this.m_PerformedRuns.size()-1; i < this.m_PerformedRuns.size(); i++) {
|
||||
multiRuns = (ArrayList)this.m_PerformedRuns.get(i);
|
||||
// determine minimum run length
|
||||
int minRunLen = Integer.MAX_VALUE;
|
||||
for (int j = 0; j < multiRuns.size(); j++) {
|
||||
singleRun = (ArrayList)multiRuns.get(j);
|
||||
// tmpD = (Double[])singleRun.get(singleRun.size()-1);
|
||||
minRunLen = Math.min(minRunLen, singleRun.size());
|
||||
}
|
||||
|
||||
data = new double[minRunLen][3];
|
||||
// First run to determine mean
|
||||
for (int j = 0; j < multiRuns.size(); j++) {
|
||||
singleRun = (ArrayList)multiRuns.get(j);
|
||||
for (int p = 0; p < data.length; p++) {
|
||||
tmpD = (Double[])singleRun.get(p);
|
||||
data[p][0] = tmpD[0].doubleValue();
|
||||
data[p][1] += tmpD[1].doubleValue()/multiRuns.size();
|
||||
}
|
||||
}
|
||||
// Second run to determine variance
|
||||
for (int j = 0; j < multiRuns.size(); j++) {
|
||||
singleRun = (ArrayList)multiRuns.get(j);
|
||||
for (int p = 0; p < data.length; p++) {
|
||||
tmpD = (Double[])singleRun.get(p);
|
||||
data[p][2] += Math.pow(data[p][1] - tmpD[1].doubleValue(),2)/multiRuns.size();
|
||||
}
|
||||
}
|
||||
// Now enter this stuff into the graph
|
||||
this.m_Plot.clearGraph(this.currentExperiment);
|
||||
// tmpColor = Color.darkGray;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("MCS")) tmpColor = Color.magenta;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("MS-HC")) tmpColor = Color.green;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("GA")) tmpColor = Color.blue;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("PBIL")) tmpColor = Color.CYAN;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("CHC")) tmpColor = Color.ORANGE;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("ES")) tmpColor = Color.red;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("CBN-EA")) tmpColor = Color.black;
|
||||
|
||||
for (int j = 0; j < data.length; j++) {
|
||||
if (this.m_ContinueFlag) this.m_Plot.setConnectedPoint(data[j][0]+this.m_RecentFC, data[j][1], this.currentExperiment);
|
||||
else this.m_Plot.setConnectedPoint(data[j][0], data[j][1], this.currentExperiment);
|
||||
}
|
||||
this.currentExperiment++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When the worker needs to update the GUI we do so by queuing
|
||||
* a Runnable for the event dispatching thread with
|
||||
* SwingUtilities.invokeLater(). In this case we're just
|
||||
* changing the progress bars value.
|
||||
*/
|
||||
void updateStatus(final int i) {
|
||||
if (this.m_ProgressBar != null) {
|
||||
Runnable doSetProgressBarValue = new Runnable() {
|
||||
public void run() {
|
||||
m_ProgressBar.setValue(i);
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(doSetProgressBarValue);
|
||||
}
|
||||
}
|
||||
|
||||
/** This method will create a new instance of LectureGUI and will call show() to create
|
||||
* the necessary frames. This method will ignore all arguments.
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
if (false) {
|
||||
InterfaceGOStandalone app = (InterfaceGOStandalone)ThreadProxy.newInstance(new GOStandaloneVersion());
|
||||
new TokenHolder("streiche", "");
|
||||
app.startExperiment();
|
||||
app.setShow(false);
|
||||
} else {
|
||||
GOStandaloneVersion program = new GOStandaloneVersion();
|
||||
RandomNumberGenerator.setseed(1);
|
||||
program.initFrame();
|
||||
program.setShow(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void setShow(boolean t) {
|
||||
this.show = t;
|
||||
}
|
||||
|
||||
/** This method allows an optimizer to register a change in the optimizer.
|
||||
* @param source The source of the event.
|
||||
* @param name Could be used to indicate the nature of the event.
|
||||
*/
|
||||
public void registerPopulationStateChanged(Object source, String name) {
|
||||
Population population = ((InterfaceOptimizer)source).getPopulation();
|
||||
double x = 100/this.m_MultiRuns;
|
||||
if (this.m_GO.getTerminator() instanceof EvaluationTerminator) {
|
||||
double y = x/(double)((EvaluationTerminator)this.m_GO.getTerminator()).getFitnessCalls();
|
||||
currentProgress = (int)(this.currentRun * x + population.getFunctionCalls()*y);
|
||||
} else {
|
||||
currentProgress = (int)(this.currentRun * x);
|
||||
}
|
||||
updateStatus(currentProgress);
|
||||
|
||||
// data to be stored in file
|
||||
double tmpd = 0;
|
||||
StringBuffer tmpLine = new StringBuffer("");
|
||||
tmpLine.append(population.getFunctionCalls());
|
||||
tmpLine.append("\t");
|
||||
tmpLine.append(population.getBestEAIndividual().getFitness(0));
|
||||
tmpLine.append("\t");
|
||||
for (int i = 0; i < population.size(); i++) tmpd += ((AbstractEAIndividual)population.get(i)).getFitness(0)/(double)population.size();
|
||||
tmpLine.append("\t");
|
||||
tmpLine.append(tmpd);
|
||||
tmpLine.append("\t");
|
||||
tmpLine.append(population.getWorstEAIndividual().getFitness(0));
|
||||
//tmpLine.append("\t");
|
||||
//tmpLine.append(this.m_GO.getProblem().getAdditionalFileStringValue(population));
|
||||
this.writeToFile(tmpLine.toString());
|
||||
|
||||
Double[] tmpData = new Double[2];
|
||||
tmpData[0] = new Double(population.getFunctionCalls());
|
||||
// instead of adding simply the best fitness value i'll ask the problem what to show
|
||||
tmpData[1] = this.m_GO.getProblem().getDoublePlotValue(population);
|
||||
if (this.m_Plot != null) {
|
||||
if (this.m_ContinueFlag) this.m_Plot.setConnectedPoint(tmpData[0].doubleValue()+this.m_RecentFC, tmpData[1].doubleValue(), 1000+this.currentRun);
|
||||
else this.m_Plot.setConnectedPoint(tmpData[0].doubleValue(), tmpData[1].doubleValue(), 1000+this.currentRun);
|
||||
}
|
||||
this.m_TmpData.add(tmpData);
|
||||
}
|
||||
|
||||
/** This method writes Data to file.
|
||||
* @param line The line that is to be added to the file
|
||||
*/
|
||||
private void writeToFile(String line) {
|
||||
String write = line + "\n";
|
||||
if (this.m_OutputFile == null) return;
|
||||
try {
|
||||
this.m_OutputFile.write(write, 0, write.length());
|
||||
this.m_OutputFile.flush();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Problems writing to output file!");
|
||||
}
|
||||
}
|
||||
|
||||
/** This method allows the CommonJavaObjectEditorPanel to read the
|
||||
* name to the current object.
|
||||
* @return The name.
|
||||
*/
|
||||
public String getName() {
|
||||
return "EA Lecture GUI";
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************
|
||||
* These are for GUI
|
||||
*/
|
||||
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This is a simple example framework for Evolutionary Algorithms.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the number of mulitruns that are to be performed,
|
||||
* necessary for stochastic optimizers to ensure reliable results.
|
||||
* @param multiruns The number of multiruns that are to be performed
|
||||
*/
|
||||
public void setMultiRuns(int multiruns) {
|
||||
this.m_MultiRuns = multiruns;
|
||||
}
|
||||
public int getMultiRuns() {
|
||||
return this.m_MultiRuns;
|
||||
}
|
||||
public String multiRunsTipText() {
|
||||
return "Multiple runs may be necessary to produce reliable results for stochastic optimizing algorithms.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the seed for the random number
|
||||
* generator.
|
||||
* @param seed The seed for the random number generator
|
||||
*/
|
||||
// MK: These methods have nothing to do with the seed parameter from the m_GO object which is actually used, so I comment them out
|
||||
// public void setSeed(long seed) {
|
||||
// RandomNumberGenerator.setseed(seed);
|
||||
// }
|
||||
// public long getSeed() {
|
||||
// return RandomNumberGenerator.getRandomSeed();
|
||||
// }
|
||||
// public String seedTipText() {
|
||||
// return "Choose the seed for the random number generator.";
|
||||
// }
|
||||
|
||||
/** This method sets the name of the current experiment as it will occur in the
|
||||
* plot legend.
|
||||
* @param experimentName The experiment name
|
||||
*/
|
||||
public void setExpName(String experimentName) {
|
||||
this.m_ExperimentName = experimentName;
|
||||
}
|
||||
public String getExpName() {
|
||||
return this.m_ExperimentName;
|
||||
}
|
||||
public String expNameTipText() {
|
||||
return "Set the name of the experiment as it will occur in the legend.";
|
||||
}
|
||||
|
||||
// /** This method will set the output filename
|
||||
// * @param name
|
||||
// */
|
||||
// public void setOutputFileName (String name) {
|
||||
// this.m_GO.setOutputFileName(name);
|
||||
// }
|
||||
// public String getOutputFileName () {
|
||||
// return this.m_GO.getOutputFileName();
|
||||
// }
|
||||
// public String outputFileNameTipText() {
|
||||
// return "Set the name for the output file, if 'none' no output file will be created.";
|
||||
// }
|
||||
|
||||
/** This method will set the output filename
|
||||
* @param name
|
||||
*/
|
||||
public void setList (List name) {
|
||||
this.m_List = name;
|
||||
}
|
||||
public List getListe () {
|
||||
return this.m_List;
|
||||
}
|
||||
public String listTipText() {
|
||||
return "Set the name for the output file, if 'none' no output file will be created.";
|
||||
}
|
||||
|
||||
// /** This method allows you to set the number of functions calls that are to
|
||||
// * be evaluated. Note generational optimizers may exceed this number since
|
||||
// * they allways evaluate the complete population
|
||||
// * @param functionCalls The maximal number of Function calls
|
||||
// */
|
||||
// public void setFunctionCalls(int functionCalls) {
|
||||
// this.m_FunctionCalls = functionCalls;
|
||||
// }
|
||||
// public int getFunctionCalls() {
|
||||
// return this.m_FunctionCalls;
|
||||
// }
|
||||
// public String functionCallsTipText() {
|
||||
// return "The maxiaml number of function(fitness) evaluations that are performed. Mote: Generational algorihtms may be delayed!";
|
||||
// }
|
||||
//
|
||||
// /** This method allows you to set the current optimizing algorithm
|
||||
// * @param optimizer The new optimizing algorithm
|
||||
// */
|
||||
// public void setOptimizer(InterfaceOptimizer optimizer) {
|
||||
// this.m_Optimizer = optimizer;
|
||||
// this.m_Optimizer.addPopulationChangedEventListener(this);
|
||||
// this.m_ExperimentName = this.m_Optimizer.getName()+"-"+this.m_PerformedRuns.size();
|
||||
// this.m_Optimizer.SetProblem(this.m_Problem);
|
||||
// }
|
||||
// public InterfaceOptimizer getOptimizer() {
|
||||
// return this.m_Optimizer;
|
||||
// }
|
||||
// public String optimizerTipText() {
|
||||
// return "Choose a optimizing strategies.";
|
||||
// }
|
||||
|
||||
// /** This method will set the problem that is to be optimized
|
||||
// * @param problem
|
||||
// */
|
||||
// public void SetProblem (InterfaceOptimizationProblem problem) {
|
||||
// this.m_Problem = problem;
|
||||
// this.m_Optimizer.SetProblem(this.m_Problem);
|
||||
// }
|
||||
// public InterfaceOptimizationProblem getProblem () {
|
||||
// return this.m_Problem;
|
||||
// }
|
||||
// public String problemTipText() {
|
||||
// return "Choose the problem that is to optimize and the EA individual parameters.";
|
||||
// }
|
||||
|
||||
|
||||
// public void setTest(InterfaceTest v) {
|
||||
// this.test = v;
|
||||
// }
|
||||
// public InterfaceTest getTest() {
|
||||
// return this.test;
|
||||
// }
|
||||
// public String testTipText() {
|
||||
// return "Test";
|
||||
// }
|
||||
}
|
||||
26
src/javaeva/server/go/IndividualInterface.java
Normal file
26
src/javaeva/server/go/IndividualInterface.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package javaeva.server.go;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 306 $
|
||||
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
/*==========================================================================*
|
||||
* INTERFACE DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface IndividualInterface {
|
||||
public IndividualInterface getClone();
|
||||
public double[] getFitness();
|
||||
public void SetFitness (double[] fit);
|
||||
public double[] getDoubleArray();
|
||||
}
|
||||
64
src/javaeva/server/go/InterfaceGOParameters.java
Normal file
64
src/javaeva/server/go/InterfaceGOParameters.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package javaeva.server.go;
|
||||
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.strategies.InterfaceOptimizer;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 11.05.2003
|
||||
* Time: 13:14:06
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public interface InterfaceGOParameters {
|
||||
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo();
|
||||
|
||||
/** This method allows you to serialize the current parameters into a *.ser file
|
||||
*/
|
||||
public void saveInstance();
|
||||
|
||||
/** This method returns the name
|
||||
* @return string
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/** This methods allow you to set and get the Seed for the Random Number Generator.
|
||||
* @param x Long seed.
|
||||
*/
|
||||
public void setSeed(long x);
|
||||
public long getSeed();
|
||||
public String seedTipText();
|
||||
|
||||
/** This method allows you to choose a termination criteria for the
|
||||
* evolutionary algorithm.
|
||||
* @param term The new terminator
|
||||
*/
|
||||
public void setTerminator(TerminatorInterface term);
|
||||
public TerminatorInterface getTerminator();
|
||||
public String terminatorTipText();
|
||||
|
||||
/** This method allows you to set the current optimizing algorithm
|
||||
* @param optimizer The new optimizing algorithm
|
||||
*/
|
||||
public void setOptimizer(InterfaceOptimizer optimizer);
|
||||
public InterfaceOptimizer getOptimizer();
|
||||
// public String optimizerTipText();
|
||||
|
||||
/** This method will set the problem that is to be optimized
|
||||
* @param problem
|
||||
*/
|
||||
public void setProblem (InterfaceOptimizationProblem problem);
|
||||
public InterfaceOptimizationProblem getProblem ();
|
||||
public String problemTipText();
|
||||
|
||||
/** This method will set the output filename
|
||||
* @param name
|
||||
*/
|
||||
public void setOutputFileName (String name);
|
||||
public String getOutputFileName ();
|
||||
public String outputFileNameTipText();
|
||||
}
|
||||
13
src/javaeva/server/go/InterfaceGOStandalone.java
Normal file
13
src/javaeva/server/go/InterfaceGOStandalone.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package javaeva.server.go;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 27.05.2003
|
||||
* Time: 16:24:32
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public interface InterfaceGOStandalone {
|
||||
public void startExperiment();
|
||||
public void setShow(boolean t);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package javaeva.server.go;
|
||||
|
||||
import javaeva.server.go.populations.Population;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 24.04.2003
|
||||
* Time: 18:09:47
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public interface InterfacePopulationChangedEventListener {
|
||||
|
||||
/** This method allows an optimizer to register a change in the optimizer.
|
||||
* @param source The source of the event.
|
||||
* @param name Could be used to indicate the nature of the event.
|
||||
*/
|
||||
public void registerPopulationStateChanged(Object source, String name);
|
||||
}
|
||||
30
src/javaeva/server/go/InterfaceProcessor.java
Normal file
30
src/javaeva/server/go/InterfaceProcessor.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package javaeva.server.go;
|
||||
|
||||
import wsi.ra.jproxy.RemoteStateListener;
|
||||
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 306 $
|
||||
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
/*==========================================================================*
|
||||
* INTERFACE DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface InterfaceProcessor {
|
||||
public void startOpt();
|
||||
public void restartOpt();
|
||||
public void stopOpt();
|
||||
public void addListener(RemoteStateListener module);
|
||||
public String getInfoString();
|
||||
}
|
||||
514
src/javaeva/server/go/MOCCOStandalone.java
Normal file
514
src/javaeva/server/go/MOCCOStandalone.java
Normal file
@@ -0,0 +1,514 @@
|
||||
package javaeva.server.go;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.mocco.InterfaceProcessElement;
|
||||
import javaeva.server.go.mocco.MOCCOChooseMOStrategy;
|
||||
import javaeva.server.go.mocco.MOCCOChooseReferencePoint;
|
||||
import javaeva.server.go.mocco.MOCCOChooseReferenceSolution;
|
||||
import javaeva.server.go.mocco.MOCCOInitialPopulationSize;
|
||||
import javaeva.server.go.mocco.MOCCOParameterizeGDF;
|
||||
import javaeva.server.go.mocco.MOCCOParameterizeMO;
|
||||
import javaeva.server.go.mocco.MOCCOParameterizeRefPoint;
|
||||
import javaeva.server.go.mocco.MOCCOParameterizeSO;
|
||||
import javaeva.server.go.mocco.MOCCOParameterizeSTEP;
|
||||
import javaeva.server.go.mocco.MOCCOParameterizeTchebycheff;
|
||||
import javaeva.server.go.mocco.MOCCOProblemInitialization;
|
||||
import javaeva.server.go.mocco.MOCCOProblemRedefinition;
|
||||
import javaeva.server.go.mocco.MOCCOState;
|
||||
import javaeva.server.go.mocco.paretofrontviewer.MOCCOViewer;
|
||||
import javaeva.server.go.operators.moso.InterfaceMOSOConverter;
|
||||
import javaeva.server.go.operators.moso.MOSOWeightedFitness;
|
||||
import javaeva.server.go.operators.terminators.EvaluationTerminator;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.AbstractMultiObjectiveOptimizationProblem;
|
||||
import javaeva.server.go.problems.InterfaceMultiObjectiveDeNovoProblem;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationObjective;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.problems.TF1Problem;
|
||||
import javaeva.server.go.strategies.InterfaceOptimizer;
|
||||
import javaeva.server.go.strategies.IslandModelEA;
|
||||
import javaeva.server.go.tools.GeneralGOEProperty;
|
||||
import javaeva.gui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wsi.ra.jproxy.ThreadProxy;
|
||||
|
||||
/*import wsi.ra.jproxy.test.Something;
|
||||
import wsi.ra.jproxy.test.SomethingInterface;*/
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 21.10.2005
|
||||
* Time: 14:31:56
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MOCCOStandalone implements InterfaceGOStandalone, InterfacePopulationChangedEventListener, java.io.Serializable {
|
||||
|
||||
public volatile MOCCOState m_State;
|
||||
private SwingWorker worker;
|
||||
private volatile boolean m_StillWorking = false;
|
||||
public int m_Iteration = -1;
|
||||
public JFrame m_JFrame;
|
||||
//public ParetoFrontView n_ParetoFrontView;
|
||||
public boolean m_Debug = false;
|
||||
public MOCCOViewer m_View;
|
||||
public JPanel m_JPanelMain, m_JPanelParameters, m_JPanelControl, m_JPanelButtom;
|
||||
private JLabel m_CurrentState;
|
||||
private JProgressBar m_ProgressBar;
|
||||
|
||||
public MOCCOStandalone() {
|
||||
this.m_State = new MOCCOState();
|
||||
}
|
||||
|
||||
/** This method will init the main MOCCO GUI
|
||||
* frame
|
||||
*/
|
||||
public void initMOCCOFrame() {
|
||||
JParaPanel paraPanel = new JParaPanel(this, "MyGUI");
|
||||
|
||||
this.m_State.isVisible = true;
|
||||
this.m_JFrame = new JFrame();
|
||||
this.m_JFrame.setTitle("MOCCO - Interactive Multi-Objective Optimization");
|
||||
this.m_JFrame.setSize(1200, 750);
|
||||
this.m_JFrame.setLocation(50, 50);
|
||||
this.m_JFrame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
// init basic panel structure
|
||||
this.m_JPanelMain = new JPanel();
|
||||
this.m_JPanelParameters = new JPanel();
|
||||
this.m_JPanelParameters.setPreferredSize(new Dimension(500, 300));
|
||||
this.m_JPanelParameters.setMinimumSize(new Dimension(500, 300));
|
||||
this.m_JPanelControl = new JPanel();
|
||||
this.m_View = new MOCCOViewer(this);
|
||||
this.m_JFrame.getContentPane().add(this.m_JPanelMain);
|
||||
this.m_JPanelMain.setLayout(new BorderLayout());
|
||||
this.m_JPanelMain.add(this.m_JPanelParameters, BorderLayout.WEST);
|
||||
this.m_JPanelMain.add(this.m_View, BorderLayout.CENTER);
|
||||
this.m_JPanelButtom = new JPanel();
|
||||
this.m_JPanelButtom.setLayout(new BorderLayout());
|
||||
JPanel tmpP = new JPanel();
|
||||
tmpP.setLayout(new GridLayout(2,1));
|
||||
this.m_CurrentState = new JLabel("Problem Initialization");
|
||||
tmpP.add(this.m_CurrentState);
|
||||
this.m_ProgressBar = new JProgressBar();
|
||||
tmpP.add(this.m_ProgressBar);
|
||||
this.m_JPanelButtom.add(tmpP, BorderLayout.CENTER);
|
||||
this.m_JPanelControl.setMinimumSize(new Dimension(400,0));
|
||||
this.m_JPanelControl.setPreferredSize(new Dimension(400,0));
|
||||
this.m_JPanelButtom.add(this.m_JPanelControl, BorderLayout.EAST);
|
||||
this.m_JPanelMain.add(this.m_JPanelButtom, BorderLayout.SOUTH);
|
||||
this.m_JFrame.validate();
|
||||
// everything is prepared let's start the main loop
|
||||
this.MOCCOOptimization();
|
||||
}
|
||||
|
||||
public void MOCCOOptimization() {
|
||||
boolean cont = true;
|
||||
InterfaceProcessElement tmpP;
|
||||
while (cont) {
|
||||
this.m_Iteration++;
|
||||
while (m_StillWorking) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
if (this.m_State.m_OriginalProblem == null) {
|
||||
this.m_State.m_OriginalProblem = new TF1Problem();
|
||||
tmpP = new MOCCOProblemInitialization(this);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { }}
|
||||
this.m_State.m_CurrentProblem = (InterfaceOptimizationProblem)this.m_State.m_OriginalProblem.clone();
|
||||
this.m_View.problemChanged(true);
|
||||
this.m_JPanelParameters.removeAll();
|
||||
tmpP = new MOCCOInitialPopulationSize(this);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { }}
|
||||
this.m_State.m_InitialPopulationSize = Math.max(1, this.m_State.m_InitialPopulationSize);
|
||||
Population pop = new Population();
|
||||
pop.setPopulationSize(this.m_State.m_InitialPopulationSize);
|
||||
this.m_State.m_CurrentProblem = (InterfaceOptimizationProblem) this.m_State.m_OriginalProblem.clone();
|
||||
this.m_State.m_CurrentProblem.initPopulation(pop);
|
||||
this.m_State.m_CurrentProblem.evaluate(pop);
|
||||
this.m_State.addPopulation2History(pop);
|
||||
this.m_View.problemChanged(true);
|
||||
}
|
||||
((InterfaceMultiObjectiveDeNovoProblem)this.m_State.m_CurrentProblem).deactivateRepresentationEdit();
|
||||
this.updateStatus("Analysis/Redefinition", 33);
|
||||
tmpP = new MOCCOProblemRedefinition(this);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
this.m_State.makeFitnessCache(true);
|
||||
this.m_State.m_CurrentProblem.initProblem();
|
||||
this.m_State.makeBackup();
|
||||
this.m_View.problemChanged(true);
|
||||
if (this.m_State.m_CurrentProblem.isMultiObjective()) {
|
||||
this.updateStatus("MO Strategy Selection", 50);
|
||||
tmpP = new MOCCOChooseMOStrategy(this);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
switch (((MOCCOChooseMOStrategy)tmpP).getMOStrategy()) {
|
||||
case MOCCOChooseMOStrategy.STRATEGY_MOEA : {
|
||||
this.updateStatus("MOEA Parameterization", 75);
|
||||
tmpP = new MOCCOParameterizeMO(this);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
break;
|
||||
}
|
||||
case MOCCOChooseMOStrategy.STRATEGY_STEP : {
|
||||
this.updateStatus("Reference Solution...", 75);
|
||||
tmpP = new MOCCOChooseReferenceSolution(this);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
AbstractEAIndividual reference = ((MOCCOChooseReferenceSolution)tmpP).getReferenceSolution();
|
||||
this.updateStatus("STEP Parameterization...", 90);
|
||||
tmpP = new MOCCOParameterizeSTEP(this);
|
||||
((MOCCOParameterizeSTEP)tmpP).setReferenceSolution(reference);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
break;
|
||||
}
|
||||
case MOCCOChooseMOStrategy.STRATEGY_REFP : {
|
||||
this.updateStatus("Reference Point...", 75);
|
||||
tmpP = new MOCCOChooseReferencePoint(this);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
double[] reference = ((MOCCOChooseReferencePoint)tmpP).getReferencePoint();
|
||||
this.updateStatus("Reference Point Parameterization...", 90);
|
||||
tmpP = new MOCCOParameterizeRefPoint(this);
|
||||
((MOCCOParameterizeRefPoint)tmpP).setReferencePoint(reference);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
break;
|
||||
}
|
||||
case MOCCOChooseMOStrategy.STRATEGY_TBCH : {
|
||||
this.updateStatus("Reference Point...", 75);
|
||||
tmpP = new MOCCOChooseReferencePoint(this);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
double[] reference = ((MOCCOChooseReferencePoint)tmpP).getReferencePoint();
|
||||
this.updateStatus("Tchebycheff Method Parameterization...", 90);
|
||||
tmpP = new MOCCOParameterizeTchebycheff(this);
|
||||
((MOCCOParameterizeTchebycheff)tmpP).setReferencePoint(reference);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
break;
|
||||
}
|
||||
case MOCCOChooseMOStrategy.STRATEGY_GDF : {
|
||||
this.updateStatus("Reference Solution...", 75);
|
||||
tmpP = new MOCCOChooseReferenceSolution(this);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
AbstractEAIndividual reference = ((MOCCOChooseReferenceSolution)tmpP).getReferenceSolution();
|
||||
this.updateStatus("Geoffrion-Dyer-Feinberg Method Parameterization...", 90);
|
||||
tmpP = new MOCCOParameterizeGDF(this);
|
||||
((MOCCOParameterizeGDF)tmpP).setReferenceSolution(reference);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
tmpP = new MOCCOParameterizeMO(this);
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.updateStatus("SO-Optimizer Parameterization", 66);
|
||||
tmpP = new MOCCOParameterizeSO(this);
|
||||
tmpP.initProcessElementParametrization();
|
||||
while (!tmpP.isFinished()) { try { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } }
|
||||
}
|
||||
// now optimize
|
||||
this.updateStatus("Optimizing...", 0);
|
||||
this.startExperiment();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkForObjectives(String w) {
|
||||
System.out.println("I'm currently "+w);
|
||||
System.out.print("Original Problem is ");
|
||||
if (this.m_State.m_OriginalProblem.isMultiObjective()) System.out.println("multi-objective.");
|
||||
else System.out.println("single-objective.");
|
||||
System.out.print("Current Problem is ");
|
||||
if (this.m_State.m_CurrentProblem.isMultiObjective()) System.out.println("multi-objective.");
|
||||
else System.out.println("single-objective.");
|
||||
if (this.m_State.m_BackupProblem != null) {
|
||||
System.out.print("Backup Problem is ");
|
||||
if (this.m_State.m_BackupProblem.isMultiObjective()) System.out.println("multi-objective.");
|
||||
else System.out.println("single-objective.");
|
||||
} else {
|
||||
System.out.println("No Backup Problem");
|
||||
}
|
||||
}
|
||||
|
||||
private void checktForMOSO(String w) {
|
||||
String s;
|
||||
System.out.println("I'm currently at "+w);
|
||||
InterfaceMOSOConverter moso = ((AbstractMultiObjectiveOptimizationProblem)this.m_State.m_CurrentProblem).getMOSOConverter();
|
||||
System.out.println("MOSO selected: "+moso.getName());
|
||||
InterfaceOptimizationObjective[] obj = ((InterfaceMultiObjectiveDeNovoProblem)this.m_State.m_CurrentProblem).getProblemObjectives();
|
||||
s = "Objectives: {";
|
||||
for (int i = 0; i < obj.length; i++) {
|
||||
s += obj[i].getIdentName();
|
||||
if (i < (obj.length-1)) s += "; ";
|
||||
}
|
||||
s += "}";
|
||||
System.out.println(""+s);
|
||||
if (moso instanceof MOSOWeightedFitness) {
|
||||
PropertyDoubleArray prop = ((MOSOWeightedFitness)moso).getWeights();
|
||||
double[] d = prop.getDoubleArray();
|
||||
s = "Weights : {";
|
||||
for (int i = 0; i < d.length; i++) {
|
||||
s += d[i];
|
||||
if (i < (d.length-1)) s += "; ";
|
||||
}
|
||||
s += "}";
|
||||
System.out.println(""+s);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
public void test() {
|
||||
for (int a = 1; a < 10; a++) {
|
||||
ArrayList ProxyList = new ArrayList();
|
||||
ArrayList NormalList = new ArrayList();
|
||||
// Create a list of ThreadProxies of Something objects --> ProxyList
|
||||
// Create a list of Something objects --> NormalList
|
||||
for (int i = 0; i < a; i++) {
|
||||
ProxyList.add(ThreadProxy.newInstance(new Something(1000)));
|
||||
NormalList.add(new Something(1000));
|
||||
}
|
||||
long ProxyTime = System.currentTimeMillis();
|
||||
// calling a method of Something, everytime a call is performed a
|
||||
// new Thread is started processing this call.
|
||||
for (int i = 0; i < a; i++)
|
||||
((SomethingInterface)(ProxyList.get(i))).doit();
|
||||
long CallingProxyTime = ProxyTime-System.currentTimeMillis();
|
||||
// calling a second method of Something but the first call (doit)
|
||||
// is not finished until now. So the opeartion sequence waits
|
||||
// here until the first call is finished.
|
||||
for (int i = 0; i < a; i++)
|
||||
((SomethingInterface)(ProxyList.get(i))).nothing();
|
||||
ProxyTime = System.currentTimeMillis() - ProxyTime;
|
||||
System.out.print ("ProxyTime :" + ProxyTime + " CallingProxyTime :" +CallingProxyTime);
|
||||
long NormalTime = System.currentTimeMillis();
|
||||
for (int i = 0; i < a; i++)
|
||||
((SomethingInterface)(NormalList.get(i))).doit();
|
||||
NormalTime = System.currentTimeMillis() - NormalTime;
|
||||
System.out.print (" NormalTime :" + NormalTime);
|
||||
double frac = ((double)NormalTime)/((double)ProxyTime);
|
||||
System.out.println(" Number of Threads=" + a+ " frac = "+frac);
|
||||
}
|
||||
}*/
|
||||
|
||||
/** This is the main method
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
MOCCOStandalone go = new MOCCOStandalone();
|
||||
if (args.length == 0) {
|
||||
// start GUI
|
||||
go.initMOCCOFrame();
|
||||
} else {
|
||||
String file = args[0];
|
||||
go.openObject(file);
|
||||
if (go.m_State == null) {
|
||||
System.out.println("No valid input state!");
|
||||
System.exit(0);
|
||||
} else {
|
||||
if (go.m_State.m_Optimizer.getPopulation().getFunctionCalls() == 0) {
|
||||
// start to optimize
|
||||
go.startExperiment();
|
||||
file = file.replaceAll(".ser","");
|
||||
go.saveObject(file+"_Finished.ser");
|
||||
} else {
|
||||
// start GUI
|
||||
go.initMOCCOFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This methods loads the current state of MOCO from a serialized file
|
||||
* @param loadFrom The name of the serialized file
|
||||
* @return The new state of MOCO
|
||||
*/
|
||||
public Object openObject(String loadFrom) {
|
||||
File selected = new File(loadFrom);
|
||||
try {
|
||||
ObjectInputStream oi = new ObjectInputStream(new BufferedInputStream(new FileInputStream(selected)));
|
||||
Object obj = oi.readObject();
|
||||
oi.close();
|
||||
if (!(obj instanceof MOCCOState)) {
|
||||
throw new Exception("Object not of type MOCCOState");
|
||||
} return obj;
|
||||
} catch (Exception ex) {
|
||||
if (this.m_JFrame != null)
|
||||
JOptionPane.showMessageDialog(this.m_JFrame, "Couldn't read object: " + selected.getName() + "\n" + ex.getMessage(), "Open object file", JOptionPane.ERROR_MESSAGE);
|
||||
else
|
||||
System.out.println("Couldn't read object: " + selected.getName() + "\n" + ex.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** This method saves the current MOCOData into a serialized file
|
||||
* @param saveAs The name of the outputfile
|
||||
*/
|
||||
public void saveObject(String saveAs) {
|
||||
File sFile = new File(saveAs);
|
||||
try {
|
||||
ObjectOutputStream oo = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(sFile)));
|
||||
oo.writeObject(this.m_State);
|
||||
oo.close();
|
||||
} catch (Exception ex) {
|
||||
if (this.m_JFrame != null)
|
||||
JOptionPane.showMessageDialog(this.m_JFrame, "Couldn't write to file: " + sFile.getName() + "\n" + ex.getMessage(), "Save object", JOptionPane.ERROR_MESSAGE);
|
||||
else
|
||||
System.out.println("Couldn't write to file: " + sFile.getName() + "\n" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void findViewFor(GeneralGOEProperty editor) {
|
||||
if (editor.m_Editor instanceof sun.beans.editors.BoolEditor) {
|
||||
editor.m_View = new PropertyBoolSelector(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor instanceof sun.beans.editors.DoubleEditor) {
|
||||
editor.m_View = new PropertyText(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.isPaintable() && editor.m_Editor.supportsCustomEditor()) {
|
||||
editor.m_View = new PropertyPanel(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.getTags() != null ) {
|
||||
editor.m_View = new PropertyValueSelector(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.getAsText() != null) {
|
||||
editor.m_View = new PropertyText(editor.m_Editor);
|
||||
} else {
|
||||
System.out.println("Warning: Property \"" + editor.m_Name
|
||||
+ "\" has non-displayabale editor. Skipping.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************************************
|
||||
* InterfaceGOStandalone
|
||||
*/
|
||||
|
||||
/** This method starts the actual optimization procedure
|
||||
*/
|
||||
public void startExperiment() {
|
||||
if (this.m_JFrame != null) {
|
||||
}
|
||||
this.m_StillWorking = true;
|
||||
this.m_State.m_Optimizer.SetProblem(this.m_State.m_CurrentProblem);
|
||||
if (this.m_Debug) System.out.println(""+this.m_State.m_Optimizer.getStringRepresentation());
|
||||
this.m_State.m_CurrentProblem.evaluate(this.m_State.m_Optimizer.getPopulation());
|
||||
this.m_State.m_Optimizer.getPopulation().SetFunctionCalls(0);
|
||||
if (this.m_State.m_Optimizer.getPopulation().size() == 0) this.m_State.m_Optimizer.init();
|
||||
this.m_State.m_Optimizer.addPopulationChangedEventListener(this);
|
||||
worker = new SwingWorker() {
|
||||
public Object construct() {
|
||||
return doWork();
|
||||
}
|
||||
public void finished() {
|
||||
Population[] pop = null;
|
||||
if (m_State.m_Optimizer instanceof IslandModelEA) {
|
||||
InterfaceOptimizer[] opt = ((IslandModelEA)m_State.m_Optimizer).getOptimizers();
|
||||
pop = new Population[opt.length];
|
||||
for (int i = 0; i < opt.length; i++) {
|
||||
pop[i] = opt[i].getPopulation();
|
||||
}
|
||||
}
|
||||
m_State.restore();
|
||||
if (pop == null) {
|
||||
m_State.addPopulation2History(m_State.m_Optimizer.getPopulation());
|
||||
} else {
|
||||
for (int i = 0; i < pop.length; i++) {
|
||||
m_State.m_CurrentProblem.evaluate(pop[i]);
|
||||
m_State.addPopulation2History(pop[i]);
|
||||
}
|
||||
}
|
||||
if (m_View != null) m_View.problemChanged(true);
|
||||
m_StillWorking = false;
|
||||
}
|
||||
};
|
||||
worker.start();
|
||||
}
|
||||
|
||||
/** When the worker needs to update the GUI we do so by queuing
|
||||
* a Runnable for the event dispatching thread with
|
||||
* SwingUtilities.invokeLater(). In this case we're just
|
||||
* changing the progress bars value.
|
||||
*/
|
||||
void updateStatus(final String t, final int i) {
|
||||
if (this.m_ProgressBar != null) {
|
||||
Runnable doSetProgressBarValue = new Runnable() {
|
||||
public void run() {
|
||||
m_ProgressBar.setValue(i);
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(doSetProgressBarValue);
|
||||
}
|
||||
this.m_CurrentState.setText(t);
|
||||
}
|
||||
|
||||
/** This method represents the application code that we'd like to
|
||||
* run on a separate thread. It simulates slowly computing
|
||||
* a value, in this case just a string 'All Done'. It updates the
|
||||
* progress bar every half second to remind the user that
|
||||
* we're still busy.
|
||||
*/
|
||||
Object doWork() {
|
||||
try {
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
while (!this.m_State.m_Terminator.isTerminated(this.m_State.m_Optimizer.getPopulation())) {
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
this.m_State.m_Optimizer.optimize();
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
updateStatus("Interrupted", 0);
|
||||
return "Interrupted";
|
||||
}
|
||||
updateStatus("All Done", 0);
|
||||
return "All Done";
|
||||
}
|
||||
|
||||
public void setShow(boolean t) {
|
||||
// i guess this is not necessary in this environment
|
||||
}
|
||||
|
||||
/***********************************************************************************************
|
||||
* InterfacePopulationChangedEventListener
|
||||
*/
|
||||
/** This method allows an optimizer to register a change in the optimizer.
|
||||
* @param source The source of the event.
|
||||
* @param name Could be used to indicate the nature of the event.
|
||||
*/
|
||||
public void registerPopulationStateChanged(Object source, String name) {
|
||||
int currentProgress;
|
||||
if (this.m_State.isVisible) {
|
||||
Population population = ((InterfaceOptimizer)source).getPopulation();
|
||||
double x = 100;
|
||||
if (this.m_State.m_Terminator instanceof EvaluationTerminator) {
|
||||
double y = x/(double)((EvaluationTerminator)this.m_State.m_Terminator).getFitnessCalls();
|
||||
currentProgress = (int)(population.getFunctionCalls()*y);
|
||||
} else {
|
||||
currentProgress = (int)(0);
|
||||
}
|
||||
updateStatus("Optimizing...",currentProgress);
|
||||
} else {
|
||||
// perhaps i could write it to file!?
|
||||
}
|
||||
}
|
||||
}
|
||||
24
src/javaeva/server/go/MutationInterface.java
Normal file
24
src/javaeva/server/go/MutationInterface.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package javaeva.server.go;
|
||||
/*
|
||||
* Title: JavaEvA
|
||||
* Description:
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
* @version: $Revision: 306 $
|
||||
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import javaeva.server.stat.Statistics;
|
||||
/*==========================================================================*
|
||||
* INTERFACE DECLARATION
|
||||
*==========================================================================*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface MutationInterface {
|
||||
public void addStatisticsListner(Statistics e);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user