Author Topic: JAPI 2.0  (Read 30344 times)

Mopz

  • Guest
Re: JAPI 2.0
« Reply #45 on: May 28, 2013, 07:20:42 am »
Quote
a bufferedreader should be used instead of a datainputstream for reading lines, etc.

JAPI_Thread.java (starting at line 73)
Code: [Select]
            in = new JAPI_SocketInputStream(commandsock.getInputStream());
            out = new JAPI_SocketOutputStream(commandsock.getOutputStream());
            action = new JAPI_SocketOutputStream(actionsock.getOutputStream());

  /* magic number for swap test */
out.sendInt(1234);

/* Debuglevel und window */
o[0]=null;
debug=in.recvInt();
            o[1] = new JAPI_Debugwindow(debug);
            debugwindow = (JAPI_Debugwindow)o[1];
            o[2] = new JAPI_Errordialog(debugwindow);
            errordialog = (JAPI_Errordialog)o[2];
            objectcounter=3;
            if(debug>0) debugwindow.println("Debug Level : "+debug);
            if(debug>0) debugwindow.println("Commandstream connected");
            if(debug>0) debugwindow.println("Actionstream  connected");


/* Clienthost and HTTP Port */
clienthost = in.readLine();
httpport   = in.recvInt();
  if(debug>0) debugwindow.println("Display   : "+clienthost);
if(debug>0) debugwindow.println("HTTP Port : "+httpport);

Marcus,

The readLine() deprecated method is everywhere and I want to make sure I understand what I need to change so I don't waste a bunch of time having to redo it. Is the deprecated method only a read issue and the old way of writing to the output device is fine?

John

I think the output streams are safe. There was a bug in readLine for the DataInputStream, and that's why it was deprecated. I guess old programs took the bug into account, and therefor they deprecated the function rather than fixing it.

Mopz

  • Guest
Re: JAPI 2.0
« Reply #46 on: May 28, 2013, 07:22:35 am »
Marcus,

I notice this reference to show that didn't appear in the deprecation list. Is this a different type of method?

Code: [Select]
/* Show Popuop */
                if (command == JAPI_Calls.JAPI_SHOWPOPUP)
              {
              int x     = in.recvInt();
              int y     = in.recvInt();

if(debug>2) debugwindow.println("Show Popup "+o[obj].toString()+" at "+x+":"+y);
if(o[obj] instanceof PopupMenu)
((PopupMenu)o[obj]).show((Component)(((Menu)o[obj]).getParent()),x,y);
            else
            nextaction=errordialog.getResult("No Popup ID in j_showpopup( ID , ... )\nID = "+o[obj].toString());
                    continue;
}

Yep, the show method for PopupMenu is not  deprecated.

ScriptBasic

  • Guest
Re: JAPI 2.0
« Reply #47 on: May 28, 2013, 07:27:07 am »
Quote
I think the output streams are safe. There was a bug in readLine for the DataInputStream, and that's why it was deprecated. I guess old programs took the bug into account, and therefor they deprecated the function rather than fixing it.

Can you post the fix for this? The socket thing is confusing me when trying to search for help with Google. I'm thinking nothing needs to be done for the readLine() methods and only the DataInputStream syntax needs fixing.


Mopz

  • Guest
Re: JAPI 2.0
« Reply #48 on: May 28, 2013, 08:12:45 am »
I can't do much right now (I'm at work). But what confuses me is the recvInt method. I've checked the javadocs and DataInputStream does not have such a method, nor does BufferedReader. What type of object are we dealing with?

Code: [Select]
in = new JAPI_SocketInputStream(commandsock.getInputStream());
This suggests it's a SocketInputStream. But I can't find anything about that class on oracle. On other places I've found the class but no information about the recvInt method. Perhaps the class is the JAPI authors own construct? Is there a SocketInputStream.java file that I can look at?
« Last Edit: May 28, 2013, 08:35:21 am by Mopz »

ScriptBasic

  • Guest
Re: JAPI 2.0
« Reply #49 on: May 28, 2013, 08:47:05 am »
Quote
This suggests it's a SocketInputStream. But I can't find anything about that class on oracle. On other places I've found the class but no information about the recvInt method. Perhaps the class is the JAPI authors own construct? Is there a SocketInputStream.java file that I can look at?

Not that I could find. Attached is my current state of the JAPI 2.0 swing source. JAPI_Thread.java only needs the SocketInputStream issue addressed.

Note: I'm working under Linux so the source files are not in DOS format.
« Last Edit: May 28, 2013, 08:50:32 am by ScriptBasic »

ScriptBasic

  • Guest
Re: JAPI 2.0
« Reply #50 on: May 28, 2013, 09:45:38 am »
Code: [Select]
public Dimension getpreferredSize() // JAPI2
{
Dimension dim = super.getpreferredSize(); // JAPI2
dim.width  = w>0 ? w : dim.width;
dim.height = h>0 ? h : dim.height;
return(dim);
}

public Dimension getminimumSize() // JAPI2
{
Dimension dim = super.getminimumSize(); // JAPI2
dim.width  = w>0 ? w : dim.width;
dim.height = h>0 ? h : dim.height;
return(dim);
}

Marcus,

The dep list only indicates that the public Dimension preferredSize() needs to be changes but I think the Dimension dim = super.preferredSize(); needs to be changed as well. Your thoughts ...

ScriptBasic

  • Guest
Re: JAPI 2.0
« Reply #51 on: May 28, 2013, 10:02:38 am »
I'm thinking that this deprecation detector is flawed.

Here is what it says are the problems.

Code: [Select]
./JAPI_Frame.java:29: warning: [deprecation] disable() in java.awt.Component has been deprecated
public void disable()
            ^
./JAPI_Frame.java:33: warning: [deprecation] disable() in java.awt.Component has been deprecated
getComponent(i).disable();
               ^
./JAPI_Frame.java:38: warning: [deprecation] enable() in java.awt.Component has been deprecated
public void enable()
            ^
./JAPI_Frame.java:42: warning: [deprecation] enable() in java.awt.Component has been deprecated
getComponent(i).enable();
               ^

Here are the changes I made. (code starts at line 29)

Code: [Select]

// public void paint(Graphics g)
// {
//     if(isResizable()!=resizable)
//     super.setResizable(resizable);
// }

public void disable()
{
int i;
for(i=0;i<getComponentCount();i++)
getComponent(i).setEnabled(false); // JAPI2
if(getJMenuBar() != null)
((JAPI_Menubar)getJMenuBar()).setEnabled(false); // JAPI2
}

public void enable()
{
int i;
  for(i=0;i<getComponentCount();i++)
getComponent(i).setEnabled(true); // JAPI2
if(getJMenuBar() != null)
((JAPI_Menubar)getJMenuBar()).setEnabled(true); // JAPI2
}

I'm wondering if the enable() / disable() user functions are overloading the Java defaults. If so, we are using a single function now and have two routines. I'm wondering if the enable() / disable() are high level methods that controls/users access and not the Java standard methods directly. Sorry for being such a dumb ass about Java.
« Last Edit: May 28, 2013, 04:08:15 pm by ScriptBasic »

ScriptBasic

  • Guest
Re: JAPI 2.0
« Reply #52 on: May 28, 2013, 06:15:41 pm »
I have finished with the JAPI 2.0 deprecation updates based on fix list. I still need to address the above issues when you have time.


ScriptBasic

  • Guest
Re: JAPI 2.0
« Reply #53 on: May 28, 2013, 07:42:58 pm »
I thought I would give what I have done so far a test compile and see what warnings/errors would still be present. I think we may have missed the boat on a few of the translations. I'm still new at Java to make any guesses or determinations at this point.

I attached the compete error/warning output as it exceeded the max post size.

I have noticed new deprecation errors that didn't show up in the last list. I'm getting the sickening feeling that the -Xlint:deprecation only spits out 100 at a time.  :-[

Code: [Select]
javac -Xlint:deprecation -O JAPI.java && jar cf JAPI.jar *.class *.gif
./JAPI_Alert.java:160: error: no suitable method found for setVisible()
this.setVisible(); // JAPI2
    ^
    method Dialog.setVisible(boolean) is not applicable
      (actual and formal argument lists differ in length)
./JAPI_MultiLineLabel.java:124: error: cannot find symbol
        Dimension d = this.getsize(); // JAPI2
                          ^
  symbol: method getsize()
./JAPI_VFlowlayout.java:110: error: cannot find symbol
Dimension d = m.getpreferredSize(); // JAPI2
               ^
  symbol:   method getpreferredSize()
  location: variable m of type Component
./JAPI_VFlowlayout.java:133: error: cannot find symbol
Dimension d = m.getminimumSize(); // JAPI2
               ^
  symbol:   method getminimumSize()
  location: variable m of type Component
./JAPI_VFlowlayout.java:150: error: cannot find symbol
int maxheight = target.getsize().height - (insets.top  + insets.bottom); // JAPI2
                      ^
  symbol:   method getsize()
  location: variable target of type Container
./JAPI_VFlowlayout.java:151: error: cannot find symbol
int maxwidth  = target.getsize().width  - (insets.left + insets.right); // JAPI2
                      ^
  symbol:   method getsize()
  location: variable target of type Container
./JAPI_VFlowlayout.java:166: error: cannot find symbol
Dimension d = m.getpreferredSize(); // JAPI2
               ^
  symbol:   method getpreferredSize()
  location: variable m of type Component
./JAPI_VFlowlayout.java:185: error: cannot find symbol
Dimension d = m.getpreferredSize(); // JAPI2
               ^
  symbol:   method getpreferredSize()
  location: variable m of type Component
./JAPI_VFlowlayout.java:210: error: cannot find symbol
Dimension d = m.getpreferredSize(); // JAPI2
               ^
  symbol:   method getpreferredSize()
  location: variable m of type Component
./JAPI_VFlowlayout.java:249: error: cannot find symbol
Dimension d = m.getpreferredSize(); // JAPI2
               ^
  symbol:   method getpreferredSize()
  location: variable m of type Component
./JAPI_Ruler.java:43: error: cannot find symbol
Dimension dim = super.getminimumSize(); // JAPI2
                     ^
  symbol: method getminimumSize()
./JAPI_Canvas.java:59: error: cannot find symbol
Dimension d = super.getsize(); // JAPI2
                   ^
  symbol: method getsize()
./JAPI_Canvas.java:126: error: cannot find symbol
Dimension d = super.getsize(); // JAPI2
                   ^
  symbol: method getsize()
./JAPI_Canvas.java:213: error: cannot find symbol
Dimension dim = super.getpreferredSize(); // JAPI2
                     ^
  symbol: method getpreferredSize()
./JAPI_Canvas.java:221: error: cannot find symbol
Dimension dim = super.getminimumSize(); // JAPI2
                     ^
  symbol: method getminimumSize()
./JAPI_Panel.java:55: error: cannot find symbol
        Dimension d = getsize(); // JAPI2
                      ^
  symbol:   method getsize()
  location: class JAPI_Panel
./JAPI_List.java:40: error: cannot find symbol
Dimension dim = super.getpreferredSize(); // JAPI2
                     ^
  symbol: method getpreferredSize()
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
17 errors
make: *** [JAPI.jar] Error 1
jrs@laptop:~/japi/japilib/swing$
« Last Edit: May 28, 2013, 07:57:43 pm by ScriptBasic »

ScriptBasic

  • Guest
Re: JAPI 2.0
« Reply #54 on: May 28, 2013, 08:31:51 pm »
I found what looks like a usable deprecated method conversion list.

I have also noticed that Java is CaSe sensitive and the reason my change from size() to getsize() should have been getSize().

Back to the list and hope I have better luck this time.

@Marcus - If you can figure out the readline() issue, that would be really helpful.



« Last Edit: May 28, 2013, 08:33:22 pm by ScriptBasic »

ScriptBasic

  • Guest
Re: JAPI 2.0
« Reply #55 on: May 29, 2013, 03:01:22 am »
I have upgraded the Java code to fix most of the deprecated methods. I still have the same component issues using a theme as I did before the upgrade. The following warnings are beyond my skills to fix. I have attached the JAPI2 Java source if someone wishes to try and take this to the next step.

Code: [Select]
javac -Xlint:deprecation -O JAPI.java && jar cf JAPI.jar *.class *.gif
./JAPI_Thread.java:94: warning: [deprecation] readLine() in DataInputStream has been deprecated
clienthost = in.readLine();
               ^
./JAPI_Thread.java:534: warning: [deprecation] readLine() in DataInputStream has been deprecated
                  String s = in.readLine();
                               ^
./JAPI_Thread.java:632: warning: [deprecation] readLine() in DataInputStream has been deprecated
                      String title  = in.readLine();
                                        ^
./JAPI_Thread.java:1097: warning: [deprecation] readLine() in DataInputStream has been deprecated
              String file = in.readLine();
                              ^
./JAPI_Thread.java:1110: warning: [deprecation] readLine() in DataInputStream has been deprecated
              String file = in.readLine();
                              ^
./JAPI_Thread.java:1247: warning: [deprecation] readLine() in DataInputStream has been deprecated
                  String title = in.readLine();
                                   ^
./JAPI_Thread.java:1308: warning: [deprecation] readLine() in DataInputStream has been deprecated
              String item = in.readLine();
                              ^
./JAPI_Thread.java:1338: warning: [deprecation] readLine() in DataInputStream has been deprecated
            String item   = in.readLine();
                              ^
./JAPI_Thread.java:1620: warning: [deprecation] setLabel(String) in AbstractButton has been deprecated
                ((JAPI_Button)o[obj]).setLabel(newtext);
                                     ^
./JAPI_Thread.java:1624: warning: [deprecation] setLabel(String) in AbstractButton has been deprecated
                ((JAPI_Menu)o[obj]).setLabel(newtext);
                                   ^
./JAPI_Thread.java:2254: warning: [deprecation] getLabel() in AbstractButton has been deprecated
  inhalt=((JAPI_Button)o[obj]).getLabel();
                              ^
./JAPI_Thread.java:2256: warning: [deprecation] getLabel() in AbstractButton has been deprecated
                inhalt=((JAPI_Menu)o[obj]).getLabel();
                                          ^
./JAPI_Thread.java:2360: warning: [deprecation] getLabel() in AbstractButton has been deprecated
  out.sendInt(((JAPI_Button)o[obj]).getLabel().length());
                                   ^
./JAPI_Thread.java:2362: warning: [deprecation] getLabel() in AbstractButton has been deprecated
                out.sendInt(((JAPI_Menu)o[obj]).getLabel().length());
                                               ^
./JAPI_Thread.java:2603: warning: [deprecation] readLine() in DataInputStream has been deprecated
                String str = in.readLine();
                               ^
./JAPI_Thread.java:3031: warning: [deprecation] readLine() in DataInputStream has been deprecated
               title = in.readLine();
                         ^
./JAPI_Thread.java:3065: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     title = in.readLine();
                               ^
./JAPI_Thread.java:3208: warning: [deprecation] readLine() in DataInputStream has been deprecated
                      title = in.readLine();
                                ^
./JAPI_Thread.java:3229: warning: [deprecation] readLine() in DataInputStream has been deprecated
                    String icon = in.readLine();
                                    ^
./JAPI_Thread.java:3251: warning: [deprecation] readLine() in DataInputStream has been deprecated
                    title = in.readLine();
                              ^
./JAPI_Thread.java:3274: warning: [deprecation] readLine() in DataInputStream has been deprecated
                    String icon = in.readLine();
                                    ^
./JAPI_Thread.java:3295: warning: [deprecation] readLine() in DataInputStream has been deprecated
                    title = in.readLine();
                              ^
./JAPI_Thread.java:3338: warning: [deprecation] readLine() in DataInputStream has been deprecated
                    title = in.readLine();
                              ^
./JAPI_Thread.java:3468: warning: [deprecation] readLine() in DataInputStream has been deprecated
                      title = in.readLine();
                                ^
./JAPI_Thread.java:3495: warning: [deprecation] readLine() in DataInputStream has been deprecated
                      title = in.readLine();
                                ^
./JAPI_Thread.java:3516: warning: [deprecation] readLine() in DataInputStream has been deprecated
                      title = in.readLine();
                                ^
./JAPI_Thread.java:3536: warning: [deprecation] readLine() in DataInputStream has been deprecated
                      title = in.readLine();
                                ^
./JAPI_Thread.java:3558: warning: [deprecation] readLine() in DataInputStream has been deprecated
                      title = in.readLine();
                                ^
./JAPI_Thread.java:3594: warning: [deprecation] readLine() in DataInputStream has been deprecated
                       String Appath = in.readLine();
                                         ^
./JAPI_Thread.java:3595: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     title = in.readLine();
                               ^
./JAPI_Thread.java:3596: warning: [deprecation] readLine() in DataInputStream has been deprecated
                    String dir = in.readLine();
                                   ^
./JAPI_Thread.java:3651: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     title = in.readLine();
                               ^
./JAPI_Thread.java:3679: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     title = in.readLine();
                               ^
./JAPI_Thread.java:3680: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     String but1 = in.readLine();
                                     ^
./JAPI_Thread.java:3705: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     title = in.readLine();
                               ^
./JAPI_Thread.java:3706: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     String but1 = in.readLine();
                                     ^
./JAPI_Thread.java:3707: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     String but2 = in.readLine();
                                     ^
./JAPI_Thread.java:3732: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     title = in.readLine();
                               ^
./JAPI_Thread.java:3733: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     String but1 = in.readLine();
                                     ^
./JAPI_Thread.java:3734: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     String but2 = in.readLine();
                                     ^
./JAPI_Thread.java:3735: warning: [deprecation] readLine() in DataInputStream has been deprecated
                     String but3 = in.readLine();
                                     ^
./JAPI_Thread.java:3864: warning: [deprecation] readLine() in DataInputStream has been deprecated
                    title = in.readLine();
                              ^
./JAPI_Frame.java:34: warning: [deprecation] disable() in Component has been deprecated
public void disable()
            ^
./JAPI_Frame.java:43: warning: [deprecation] enable() in Component has been deprecated
public void enable()
            ^
./JAPI_Dialog.java:27: warning: [deprecation] disable() in Component has been deprecated
public void disable()
            ^
./JAPI_Dialog.java:33: warning: [deprecation] enable() in Component has been deprecated
public void enable()
            ^
./JAPI_Window.java:14: warning: [deprecation] disable() in Component has been deprecated
public void disable()
            ^
./JAPI_Window.java:21: warning: [deprecation] enable() in Component has been deprecated
public void enable()
            ^
./JAPI_Panel.java:17: warning: [deprecation] disable() in Component has been deprecated
public void disable()
            ^
./JAPI_Panel.java:24: warning: [deprecation] enable() in Component has been deprecated
public void enable()
            ^
./JAPI_Graphicbutton.java:64: warning: [deprecation] disable() in Component has been deprecated
public void disable()
            ^
./JAPI_Graphicbutton.java:71: warning: [deprecation] enable() in Component has been deprecated
public void enable()
            ^
./JAPI_Graphicbutton.java:97: warning: [deprecation] mouseUp(Event,int,int) in Component has been deprecated
  public boolean mouseUp(Event evt, int x, int y)
                 ^
./JAPI_Graphicbutton.java:112: warning: [deprecation] mouseDown(Event,int,int) in Component has been deprecated
  public boolean mouseDown(Event evt, int x, int y)
                 ^
./JAPI_Graphicbutton.java:119: warning: [deprecation] mouseExit(Event,int,int) in Component has been deprecated
  public boolean mouseExit(Event evt, int x, int y)
                 ^
./JAPI_Graphicbutton.java:127: warning: [deprecation] mouseEnter(Event,int,int) in Component has been deprecated
  public boolean mouseEnter(Event evt, int x, int y)
                 ^
./JAPI_Menubar.java:11: warning: [deprecation] disable() in JComponent has been deprecated
    public void disable()
                ^
./JAPI_Menubar.java:18: warning: [deprecation] enable() in JComponent has been deprecated
    public void enable()
                ^
58 warnings
jrs@laptop:~/japi/japilib/swing$
« Last Edit: May 29, 2013, 03:08:38 am by ScriptBasic »

DJLinux

  • Guest
Re: JAPI 2.0
« Reply #56 on: May 29, 2013, 03:28:30 am »
In the case you use class DataInputStream you have to change to the BufferedReader class ?

DJ
Quote from: JAVA Deprecated API
java.io.DataInputStream.readLine()
This method does not properly convert bytes to characters.
As of JDK 1.1, the preferred way to read lines of text is via the BufferedReader.readLine() method.
Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form:

         DataInputStream d = new DataInputStream(in);
with:
         BufferedReader d = new BufferedReader(new InputStreamReader(in));
     

Mopz

  • Guest
Re: JAPI 2.0
« Reply #57 on: May 29, 2013, 05:13:12 pm »
I'm sorry, I think I need to spend some time on understanding how JAPI works before I try to answer any questions. So far, I've just had a first VERY short glance at JAPI.

JAPI uses AWT and SWING. And we're using the latest version of these api:s, right? Unless JAPI uses a big set of new classes and inheritence, there should only be "one level of deprecation" to deal with. That is, we should only need to replace deprecated function calls at one level, not through a "whole family tree" of inheritance. 

I think I need to make my woman pregnant again so that I'll can be parental for six months or so (love the Swedish system) and have serious time for personal programming :) Right now I deal with naalaa and forum activity between work, cooking and diaper changes.

ScriptBasic

  • Guest
Re: JAPI 2.0
« Reply #58 on: May 29, 2013, 05:27:17 pm »
I updated most of the common sense based deprecated methods to bring it to where it is now. This is what I'm in the dark about.

What does LaF do to JAPI that breaks the code and works if no LaF is defined? The button.bas works perfect with themes. The LED and Meter examples just hang. The gridlayout stops working thinking it's parent is lying.

Is there a special include that is needed at the top of the .java programs that brings the theme functionality into play?

I seem to be screwed at the moment. Ever since I added the swing.properties file to enable theming, I can't return back to no LaF support. :(



Mopz

  • Guest
Re: JAPI 2.0
« Reply #59 on: May 29, 2013, 06:21:33 pm »
Sorry John, I've got to spend some real time on this project before I can be of assistance. Hopefully I'll have the time this weekend.