Skip to content

Commit

Permalink
Removing lua dependency from java code
Browse files Browse the repository at this point in the history
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@243 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
theraysmith committed Jun 2, 2009
1 parent 254b936 commit c82051a
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 127 deletions.
6 changes: 4 additions & 2 deletions java/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
SUBDIRS =

EXTRA_DIST = \
test.lua makefile SVEvent.java SVEventHandler.java \
test.lua makefile SVAbstractMenuItem.java \
SVCheckboxMenuItem.java SVEmptyMenuItem.java \
SVEvent.java SVEventHandler.java \
SVEventType.java SVImageHandler.java SVMenuBar.java \
SVMenuItem.java SVPopupMenu.java SVWindow.java \
SVMenuItem.java SVPopupMenu.java SVSubMenuItem.java SVWindow.java \
ScrollView.java
58 changes: 58 additions & 0 deletions java/SVAbstractMenuItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2007 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); You may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
// applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

package com.google.scrollview.ui;

/**
* A MenuListItem is any sort of menu entry. This can either be within a popup
* menu or within a menubar. It can either be a submenu (only name and
* command-id) or a name with an associated value and possibly description. They
* can also have new entries added (if they are submenus).
*
* @author wanke@google.com
*/

import com.google.scrollview.events.SVEventType;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

abstract class SVAbstractMenuItem {
JMenuItem mi;
public String name;
public int id;

/**
* Sets the basic attributes for name, id and the corresponding swing item
*/
SVAbstractMenuItem(int id, String name, JMenuItem jmi) {
this.mi = jmi;
this.name = name;
this.id = id;
}

/** Returns the actual value of the MenuListItem. */
public String getValue() { return null; }

/** Adds a child entry to the submenu. */
public void add(SVAbstractMenuItem mli) { }

/** Adds a child menu to the submenu (or root node). */
public void add(JMenu jli) { }

/**
* What to do when user clicks on this item.
* @param window The window the event happened.
* @param eventType What kind of event will be associated
* (usually SVET_POPUP or SVET_MENU).
*/
public void performAction(SVWindow window, SVEventType eventType) {}
}

60 changes: 60 additions & 0 deletions java/SVCheckboxMenuItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2007 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); You may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
// applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

package com.google.scrollview.ui;

/**
* A MenuListItem is any sort of menu entry. This can either be within a popup
* menu or within a menubar. It can either be a submenu (only name and
* command-id) or a name with an associated value and possibly description. They
* can also have new entries added (if they are submenus).
*
* @author wanke@google.com
*/

import com.google.scrollview.ScrollView;
import com.google.scrollview.events.SVEvent;
import com.google.scrollview.events.SVEventType;

import javax.swing.JCheckBoxMenuItem;

/**
* Constructs a new menulistitem which possesses a flag that can be toggled.
*/
class SVCheckboxMenuItem extends SVAbstractMenuItem {
public String value = null;
public String desc = null;
public boolean bvalue;

SVCheckboxMenuItem(int id, String name, boolean val) {
super(id, name, new JCheckBoxMenuItem(name, val));
bvalue = val;
}

/** What to do when user clicks on this item. */
@Override
public void performAction(SVWindow window, SVEventType eventType) {
// Checkbox entry - trigger and send event.
if (bvalue) {
bvalue = false;
} else {
bvalue = true;
}
SVEvent svme = new SVEvent(eventType, window, id, getValue());
ScrollView.addMessage(svme);
}

/** Returns the actual value of the MenuListItem. */
@Override
public String getValue() {
return Boolean.toString(bvalue);
}
}

48 changes: 48 additions & 0 deletions java/SVEmptyMenuItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2007 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); You may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
// applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

package com.google.scrollview.ui;

/**
* A MenuListItem is any sort of menu entry. This can either be within a popup
* menu or within a menubar. It can either be a submenu (only name and
* command-id) or a name with an associated value and possibly description. They
* can also have new entries added (if they are submenus).
*
* @author wanke@google.com
*/

import com.google.scrollview.ScrollView;
import com.google.scrollview.events.SVEvent;
import com.google.scrollview.events.SVEventType;

import javax.swing.JMenuItem;

/**
* Constructs a new menulistitem which just has an ID and a name attached to
* it. In this case, we will have to ask for the value of the item and its
* description if it gets called.
*/
class SVEmptyMenuItem extends SVAbstractMenuItem {
SVEmptyMenuItem(int id, String name) {
super(id, name, new JMenuItem(name));
}
/** What to do when user clicks on this item. */
@Override
public void performAction(SVWindow window, SVEventType eventType) {
// Send an event indicating that someone clicked on an entry.
// Value will be null here.
SVEvent svme =
new SVEvent(eventType, window, id, getValue());
ScrollView.addMessage(svme);
}
}


117 changes: 6 additions & 111 deletions java/SVMenuItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2007 Google Inc. All Rights Reserved.
//
//
// Licensed under the Apache License, Version 2.0 (the "License"); You may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
Expand All @@ -15,86 +15,14 @@
* menu or within a menubar. It can either be a submenu (only name and
* command-id) or a name with an associated value and possibly description. They
* can also have new entries added (if they are submenus).
*
*
* @author wanke@google.com
*/

import com.google.scrollview.ScrollView;
import com.google.scrollview.events.SVEvent;
import com.google.scrollview.events.SVEventType;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

abstract class SVAbstractMenuItem {
JMenuItem mi;
public String name;
public int id;

/**
* Sets the basic attributes for name, id and the corresponding swing item
*/
SVAbstractMenuItem(int id, String name, JMenuItem jmi) {
this.mi = jmi;
this.name = name;
this.id = id;
}

/** Returns the actual value of the MenuListItem. */
public String getValue() { return null; }

/** Adds a child entry to the submenu. */
public void add(SVAbstractMenuItem mli) { }

/** Adds a child menu to the submenu (or root node). */
public void add(JMenu jli) { }

/**
* What to do when user clicks on this item.
* @param window The window the event happened.
* @param eventType What kind of event will be associated (usually SVET_POPUP or SVET_MENU).
*/
public void performAction(SVWindow window, SVEventType eventType) {}
}

/** Constructs a new submenu which can hold other entries. */
class SVSubMenuItem extends SVAbstractMenuItem {
public SVSubMenuItem(String name, JMenu jli) {
super(-1, name, jli);
}
/** Adds a child entry to the submenu. */
@Override
public void add(SVAbstractMenuItem mli) {
mi.add(mli.mi);
}
/** Adds a child menu to the submenu (or root node). */
@Override
public void add(JMenu jli) {
mi.add(jli);
}
}

/**
* Constructs a new menulistitem which just has an ID and a name attached to
* it. In this case, we will have to ask for the value of the item and its
* description if it gets called.
*/
class SVEmptyMenuItem extends SVAbstractMenuItem {
SVEmptyMenuItem(int id, String name) {
super(id, name, new JMenuItem(name));
}
/** What to do when user clicks on this item. */
@Override
public void performAction(SVWindow window, SVEventType eventType) {
// Send an event indicating that someone clicked on an entry.
// Value will be null here.
SVEvent svme =
new SVEvent(eventType, window, id, getValue());
ScrollView.addMessage(svme);
}
}

/**
* Constructs a new menulistitem which also has a value and a description. For
* these, we will not have to ask the server what the value is when the user
Expand All @@ -103,14 +31,14 @@ public void performAction(SVWindow window, SVEventType eventType) {
class SVMenuItem extends SVAbstractMenuItem {
public String value = null;
public String desc = null;

SVMenuItem(int id, String name, String v, String d) {
super(id, name, new JMenuItem(name));
value = v;
desc = d;
}
/**

/**
* Ask the user for new input for a variable and send it.
* Depending on whether there is a description given for the entry, show
* the description in the dialog or just show the name.
Expand All @@ -123,44 +51,11 @@ public void performAction(SVWindow window, SVEventType eventType) {
window.showInputDialog(name, value, id, eventType);
}
}

/** Returns the actual value of the MenuListItem. */
@Override
public String getValue() {
return value;
}
}

/**
* Constructs a new menulistitem which possesses a flag that can be toggled.
*/
class SVCheckboxMenuItem extends SVAbstractMenuItem {
public String value = null;
public String desc = null;
public boolean bvalue;

SVCheckboxMenuItem(int id, String name, boolean val) {
super(id, name, new JCheckBoxMenuItem(name, val));
bvalue = val;
}

/** What to do when user clicks on this item. */
@Override
public void performAction(SVWindow window, SVEventType eventType) {
// Checkbox entry - trigger and send event.
if (bvalue) {
bvalue = false;
} else {
bvalue = true;
}
SVEvent svme = new SVEvent(eventType, window, id, getValue());
ScrollView.addMessage(svme);
}

/** Returns the actual value of the MenuListItem. */
@Override
public String getValue() {
return Boolean.toString(bvalue);
return value;
}
}

41 changes: 41 additions & 0 deletions java/SVSubMenuItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2007 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); You may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
// applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

package com.google.scrollview.ui;

/**
* A MenuListItem is any sort of menu entry. This can either be within a popup
* menu or within a menubar. It can either be a submenu (only name and
* command-id) or a name with an associated value and possibly description. They
* can also have new entries added (if they are submenus).
*
* @author wanke@google.com
*/

import javax.swing.JMenu;

/** Constructs a new submenu which can hold other entries. */
class SVSubMenuItem extends SVAbstractMenuItem {
public SVSubMenuItem(String name, JMenu jli) {
super(-1, name, jli);
}
/** Adds a child entry to the submenu. */
@Override
public void add(SVAbstractMenuItem mli) {
mi.add(mli.mi);
}
/** Adds a child menu to the submenu (or root node). */
@Override
public void add(JMenu jli) {
mi.add(jli);
}
}


Loading

0 comments on commit c82051a

Please sign in to comment.