Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Alan Greenspan
Jun 17, 2001

rotor posted:

You won't be able to write to it, IIRC.

http://forum.java.sun.com/thread.jspa?threadID=300557&start=45&tstart=-1

Someone developed a cute hack I use to modify the classpath at runtime for plugin reasons.

Adbot
ADBOT LOVES YOU

Alan Greenspan
Jun 17, 2001

Sweet and simple question about writing your own GUI controls.

I have a custom control that prints "Help me COC :(" by extending JPanel and overwriting

code:
public void paintComponent(Graphics g2)
Now I have a library that zooms stuff on the screen.

When I directly write to g2 the zoomed text looks great.



I used this code:

code:
public void paintComponent(Graphics g)
{
   g.setColor(Color.RED);
   g.fillRect(0, 0, getWidth(), getHeight());
   g.setColor(Color.BLACK);
   g.drawString("Help me COC :(", 20, 20);
}
Now the problem is that I don't have just 1 COC control but maybe like 50000 so drawing right to the screen graphics context is way too slow. I need to paint elsewhere and copy the "elsewhere" to the screen in one go.

code:
public void paintComponent(Graphics g)
{
   BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D g2 = (Graphics2D) img.getGraphics();
   
   g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
   g2.setColor(Color.RED);
   g2.fillRect(0, 0, getWidth(), getHeight());
   g2.setColor(Color.BLACK);
   g2.drawString("Help me COC :(", 20, 20);
   
   img.flush();
   
   g.drawImage(img, 0, 0, null);
}


Now zooming does not work anymore. I suspect it's because I write to an image in the second case and it's pixels are fixed once written.

Any suggestions? Why are there differences between the Graphics context I get passed as the argument to the function and the one I create myself. What are these differences? Where should I draw to offscreen? How do I get a Graphics context that's equal to the one from the argument but doesn't directly write to the screen? Why is the zoomed text fine if directly written to the screen? Just what the hell is going on here, I appreciate any speculation. :(

Alan Greenspan
Jun 17, 2001

OK, I'm pretty sure this is what happens.

1. I write my stuff in my BufferedImage
2. I drawImage my BufferedImage to the Graphics context from the argument
3. The zoom kicks in and uses a method like Graphics2D::scale on the context
4. My drawn image pixelates because the scale method only sees the image and not the operations that created the image

:smithicide:

Alan Greenspan
Jun 17, 2001

Is there an easy way to put breakpoints on Java library functions? Let's say I want to put a breakpoint on one of the constructors of java.io.File.

IDE is Eclipse but I'm willing to switch to any IDE for this.

Alan Greenspan
Jun 17, 2001

TRex EaterofCars posted:

Yeah, in Eclipse your java source should already be linked to the rt.jar file. Just ctrl+click on a new File() statement and it'll take you right to the constructor. If that doesn't work, you probably have to link the source. I can tell you how to do that if you need.

Thanks for the reply but apparently this is tricky because when I set a breakpoint into the rt.jar source ...



:saddowns:

Alan Greenspan
Jun 17, 2001

TRex EaterofCars posted:

What versions of Eclipse and Java are you running?

I figured it out. I was using the rt.jar from the real JRE, using the rt.jar from the JRE shipped with the JDK worked. Thank you. :woop:

Alan Greenspan
Jun 17, 2001

Eclipse configuration question: I have this

code:
public interface IInterface
{
  /**
  * Some incredibly useful comment.
  **/
  void foo();
}

public class MyClass implements IInterface
{
  @Override
  public void foo()
  {
    // Code goes here.
  }
}
What I want now is that Eclipse mirrors the incredibly useful comment so that I can see it right above the implementation of the foo function in MyClass. Basically I want comments from interfaces visible above implementing methods in classes. Is this possible?

Also: I want these comments to be visible directly in the source, not the Javadoc tab.

Alan Greenspan
Jun 17, 2001

csammis posted:

Also why are you using @Override on an interface method?

Pretty much what the others said. My Eclipse adds it automatically and it's cool because unintended interface changes often turn into compilation errors.

Also: Too bad that what I want does apparently not exist in Eclipse. :saddowns:

Alan Greenspan
Jun 17, 2001

I have like 50-75 classes that need to have the same 9 lines:

code:
private ListenerProvider<T> listeners = new ListenerProvider<T>();

public void addListener(T listener)
{
  listeners.addListener(listener);
}

public void removeListener(T listener)
{
  listeners.removeListener(listener);
}
where T needs to be a concrete but variable type.

Is there any way that I can auto-generate these lines of code. I'd really like to do:

code:
@AddListener(MyListenerType)
public class Whatever
{
}
Also: the listeners variable must be accessible from regular code.

I'm using Eclipse. apt looks like it might work. Anybody ever done anything like that?

Alan Greenspan
Jun 17, 2001

poopiehead posted:

This probably isn't the case, but if the classes can reasonably have a common base class or maybe can be grouped into a few common base classes, it's pretty easy. But unless they genuinely have something else in common, this would probably be a bad idea.

code:

abstract class AbstractListener<T>
{
  private ListenerProvider<T> listeners = new ListenerProvider<T>(); 
  public void addListener(T listener) 
  { 
    listeners.addListener(listener); 
  } 
  public void removeListener(T listener) 
  { 
    listeners.removeListener(listener); 
  }
}

class A extends AbstractListener<ConcreteListenerClass>
{
 ...
}

class B extends AbstractListener<SomeOtherConcreteListenerClass>
{
}

Thank you for your reply, but you're obviously right. That's a really bad idea because it's not really a problem to be solved with inheritance (especially in a language with only single-inheritance support).

Java. :argh:

Alan Greenspan
Jun 17, 2001

a_passerby posted:

What's the easiest way to register a Windows file association from a Java program? For example, if I want my program to open all files with a .crap extension automatically, how do I register that with Windows?
What I do is to create a .reg file with the necessary information and execute "regedit /S filename.reg" from Java.

Adbot
ADBOT LOVES YOU

Alan Greenspan
Jun 17, 2001

Boz0r posted:

is there any way around making for loops to insert them?

There is System.arraycopy.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply