Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  UIEventAdapter Usage  (Read 2066 times)
0 Members and 1 Guest are viewing this topic.
Offline shochu

Junior Member




Java games rock!


« Posted 2003-12-14 21:18:30 »

I notice that the UIEVentAdapter receives all Mouse and Keyboard events.  It then dispatches the event to the proper overlay (i.e. the one with focus) However, the main canvas is not in the overlay list.  How do we set up the mouse and keyboard listeners for the main Canvas3D so that it is also considered an overlay.  

IN other words, right now, when I input text into a textfield overlay my keyboard inputs are also effecting the main cavas3D.

Am I supposed to add the Cavnas3D as an overlay??  Any example code would be greatly appreciated.  Thank you for the help. ~shochu
Offline DavidYazel

Junior Member




Java games rock!


« Reply #1 - Posted 2003-12-14 21:37:25 »

There is no solution for this currently.  Let me propose the following:

Allow for default listeners to be registered with the UIWindowManager.  We can call this listener for mouse events which happen outside an overlay window and for keyboard events when there is not an overlay window in focus.

Question is:  Would you rather receive all the events with a flag set if they were also sent to a window?  This way you could still have function keys, etc which couldbe active even if you had a chat box highlighted.  If we didn't do that then the user would have to click on a non-window in order to get keyboard events to the new listeners?

Or do you want the new listeners to have first crack at the event with the option to consume it?  Maybe we combine them and pass in the window which we are planning to send the event to (if there is one) and if the event comes back consumed then we don't send it to the window?

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline shochu

Junior Member




Java games rock!


« Reply #2 - Posted 2003-12-15 00:32:02 »

Both ideas sound good to me.  Both of them sound easy enough to use.  The flag seems very easy to implement.  Having xith pass the event first to to the overlay with focus and then if the event is not consumed passing the event to the main window is probably the best.  I'm not sure if this is technically possible though.  Until a fix is made I'll just hack the source and add a flag myself.   Thanks for the info David!

~shochu
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline shochu

Junior Member




Java games rock!


« Reply #3 - Posted 2003-12-15 01:03:11 »

I just added a flag to UIWindow which tells me if the window is in focus.  For now I just check that before doing anything in my main window with key inputs.

However, I'm having another problem.  I think this one is similar to Jyang81's questions about scrollPanes.  I have a scrollpane and it works only if you are scolling up and down in the textarea with your keyboard arrow keys.  If you try to click on the scollpane buttons (the up and down arrow) using your mouse nothing happens.  Also, if you try to scoll the scoll pane bar nothing happens.

Any idea how to fix this or is this a problem with the UI system in xith??
Offline DavidYazel

Junior Member




Java games rock!


« Reply #4 - Posted 2003-12-15 10:10:49 »

On the scroll pane issue: The problem there is the method that Swing uses to scroll is bizzare.  I have traced the code back and found it uses a timer to scroll and that it absolutely requires that the component be active and attached to a "real window" which of course UIWindow is not.  So the solution is to setup a listener in your code on the scrollbar and force a redraw of the pane when the scrollbar changes.  Thats what I do in my code and it works great.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline shochu

Junior Member




Java games rock!


« Reply #5 - Posted 2003-12-15 11:46:12 »

Are you talking about adding this listener?

1  
2  
3  
4  
5  
6  
            scrollPaneScreen.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener(){
                  public void adjustmentValueChanged(AdjustmentEvent e){
                        scrollPaneScreen.repaint();
                  }
            }
            );


I added that and you can scroll with the keyboard but not by using the VerticalScrollBar.  I tried adding listeners for mouse events and repaint on those but that didn't do anything.  Any ideas?
Offline shochu

Junior Member




Java games rock!


« Reply #6 - Posted 2003-12-15 13:17:56 »

Also, I don't think the layoutManagers are working.  At least not in the way you can use them in normal SWing.
Offline DavidYazel

Junior Member




Java games rock!


« Reply #7 - Posted 2003-12-15 13:56:49 »

Hmmm, can you be more specific? UIWindow.pack() does a layout on all components.  I have some screens with many layers of nested panes and controls using flow layout and border layout without issues.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline shochu

Junior Member




Java games rock!


« Reply #8 - Posted 2003-12-15 17:08:54 »

Here's my test program.  I want to have three panels.  One panel is the main panel and it has two subpanels.  The chat panel and the button Panel.  I use BorderLayout.  At first I didn't set any sizes because I thought the componenets would all expand to the right size, but that didn't work.  I explicitly set the sizes of everything below and that still doesn't work.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
import java.awt.*; 
import java.awt.event.*;
import com.xith3d.scenegraph.*;
import com.xith3d.render.*;
import com.xith3d.render.jogl.*;
import javax.vecmath.*;
import javax.swing.*;
import com.xith3d.userinterface.*;

 
public class TryUI{
 UIWindowManager windowMgr;
 View view;
 String inputText = "";
 
 public void start(){
       while(true){
             view.renderOnce();
       }
 }
 
 
 public void init() throws Exception
  {
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 
   VirtualUniverse universe = new VirtualUniverse();
   view = new View();
   view.setBackClipDistance(100f);
   view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
   view.getTransform().lookAt(new Vector3f(0, 0, 3), new Vector3f(0, 0, 0), new Vector3f(0, 1, 3));
   Locale locale = new Locale();
   universe.addLocale(locale);
   universe.addView(view);
   RenderPeer renderPeer = new RenderPeerImpl();
   CanvasPeer canvasPeer = renderPeer.makeCanvas(null,
                                                                            screenSize.width - 200,
                                                                            screenSize.height - 200,
                                                                            16, false);
   canvasPeer.getWindow().setLocation(100, 100);
   Canvas3D canvas = new Canvas3D();
   canvas.set3DPeer(canvasPeer);
   view.addCanvas3D(canvas);
 
   // construct a window manager for this canvas
  windowMgr = new UIWindowManager(canvas);
   TestWindow w = new TestWindow(800,200);
   windowMgr.addOverlay(w);
   windowMgr.setPosition(w,25,600);
   windowMgr.setVisible(w,true);
   
   UIEventAdapter eventAdapter = new UIEventAdapter(windowMgr);
   canvas.get3DPeer().getComponent().addKeyListener(eventAdapter);
   canvas.get3DPeer().getComponent().addMouseListener(eventAdapter);
   canvas.get3DPeer().getComponent().addMouseMotionListener(eventAdapter);
   canvas.get3DPeer().getComponent().setFocusable(true);
 
   start();
 }
 
 class TestWindow extends UIWindow{
 
  public TestWindow(int width, int height) {
     super(width, height, false, false );
     setRoot(buildGUI(width,height));
     this.pack();
     
  }
 
  private JComponent buildGUI (int width, int height) {
   JPanel mainPanel = new JPanel();
   JPanel chatPanel = new JPanel();
   JPanel buttonPanel = new JPanel();
   
   
   
   
   mainPanel.setDoubleBuffered(true);
   mainPanel.setLocation(0,0);
   mainPanel.setBackground(new Color(1.0f,1.0f,1.0f,0.5f)); //the 4th parameter changes the transparency setting
     
   //TextArea  
  final JTextArea textAreaScreen = new JTextArea();
   textAreaScreen.setEditable(false);
   textAreaScreen.setBackground(new Color(1f,1f,1f,.5f));
   textAreaScreen.setLineWrap(true);
   
   //ScrollPane
  final JScrollPane scrollPaneScreen = new JScrollPane(textAreaScreen);
   scrollPaneScreen.setBackground(new Color(1f,1f,1f, 0.5f));
   scrollPaneScreen.setSize(width, 100);
     
   scrollPaneScreen.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
              scrollPaneScreen.repaint();
        }
   });

   //TextField
  final JTextField textFieldInput = new JTextField();
   textFieldInput.setSize(width, 100);
   textFieldInput.setBackground(new Color(1f,1f,1f,0.5f)); //the 4th parameter changes the transparency settings
  textFieldInput.addKeyListener(new KeyListener(){
       public void keyPressed(KeyEvent e) {}
         
       public void keyReleased(KeyEvent e) {}
 
       public void keyTyped(KeyEvent e) {
            if(e.getKeyChar() == 10){
                  textAreaScreen.append("\n" + textFieldInput.getText());
                  textFieldInput.setText("");
            }  
       }
    });
   
   //Button
  JButton logoutButton = new JButton();
   logoutButton.setText("Logout");
   logoutButton.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
        System.exit(0);
      }
   });  
   //Set Panel and Component SIze
  mainPanel.setSize(new Dimension(width,height));
   chatPanel.setSize(new Dimension(width, height/2));
   buttonPanel.setSize(new Dimension(width, height/2));
   scrollPaneScreen.setSize(new Dimension(width, height/4));
   textAreaScreen.setSize(new Dimension(width, height/4));
   textFieldInput.setSize(new Dimension(width, height/4));
   logoutButton.setSize(new Dimension(100,25));
   
   chatPanel.add(scrollPaneScreen, BorderLayout.CENTER);
   chatPanel.add(textFieldInput, BorderLayout.SOUTH);
   buttonPanel.add(logoutButton, BorderLayout.SOUTH);
   mainPanel.add(chatPanel, BorderLayout.CENTER);
   mainPanel.add(buttonPanel, BorderLayout.SOUTH);
 
   return mainPanel;
   
  }
   
 
 }
 
 public static void main(String[] args)
  {
   try
   {
      TryUI test = new TryUI();
      test.init();
   }
   catch (Exception e)
   {
      e.printStackTrace();
   }
 }
}



WHat could be causing the problem?  
Offline DavidYazel

Junior Member




Java games rock!


« Reply #9 - Posted 2003-12-15 17:25:50 »

When using layout managers you have to setPreferredSize() instead of setSize().  You can only use setSize() and setLocation() if you use the null layout manager.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline shochu

Junior Member




Java games rock!


« Reply #10 - Posted 2003-12-15 20:35:45 »

Hi David ....
  Do you have any examples of a complex GUI which uses things like text fields and text areas?  I'm stil having problems and I think if I had a more complex example to look at I'd be able to figure it out.  The UI example's already available are all too simple to help me.  Thanks you. ~shochu  
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #11 - Posted 2003-12-15 22:45:26 »

I doubt anyone has the time to make one, but I would really love to see a simple demo with a few odd shaped transparent GUI components in action (the screenshots of Magicosm are awesome).

The GUI library of Xith3D is very powerful as the Magicosm screen shots show and it's a shame there's no public example which shows off the best of it's capabilities.

Will.

Offline shochu

Junior Member




Java games rock!


« Reply #12 - Posted 2003-12-15 23:05:47 »

Yes I agree hehe.  It's frustrating to know that it can be done but I can't figure out how  :-/

The magicosm UI makes me so jealous
hahah
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #13 - Posted 2003-12-16 04:10:14 »

looks like we got our wish  Grin Grin

Will.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!