Keilly

Wednesday, November 27, 2013

Fuzzy Remote Desktop / VNC with Retina Display

When viewing remote content on a retina display, it may appear fuzzier than when viewed on a non-retina display.
This is counter intuitive, after all the retina display is the ultimate in resolution no?
However it makes sense when you think about it as the machine doing the rendering of the text knows nothing about the retina display, so renders as usual for a regular one - doing antialiasing to smooth out the edges of text. The remote desktop/vnc app running on the local machine then takes that remote image and it must scale it up to fill the same physical area on the screen. So it doubles it and anti-aliases it again to smooth edges of shapes. It's this double anti-aliasing that makes text blurrier rather than smoother....

VNC viewed on a regular display:


VNC viewed on a retina display:

There is a general solution...

In Finder go to Applications, find the Remote/VNC program, right click and "Get Info".

Check on the "Open in Low Resolution", and things should be nice and crisp the next time it is launched.


Monday, June 17, 2013

Preferred Height of JTextComponents

Given some text and a text component (e.g. JTextArea), it is not obvious how to set the preferred size of the component to only show the current content.
Skip to Answer

This:
     JTextArea ta = new JTextArea();  
     ta.setLineWrap(true);  
     ta.setText("112 312 3 12 31 2432135r34534t 3 t3 4t34y4hthefbasdgagaergergwreg"  
         + "rwergerg ergergergefdav asdvsadg sadgsad gsdgsdgsadgsgd sdgsdg"  
         + "sdg sdgsdgsdg sdgsdgsdgsgh4hgaregwaegasdg sdgsdg sagae4gsaegs "  
         + " sdgsdg sdg s gs dg sd gs dg sdg sdg sadgsdg sad gsa dg s"  
         + "se gs eg se g saeg sa eg s eg sa eg e g eg aweg");  
     JScrollPane sp = new JScrollPane(ta);  
     System.out.println("TextArea Pref Size: " + ta.getPreferredSize());  
     System.out.println("ScrollPane Pref Size: " + sp.getPreferredSize());  

Gives:
TextArea Pref Size: java.awt.Dimension[width=100,height=16]
ScrollPane Pref Size: java.awt.Dimension[width=104,height=20]

The layout manager follows the preferred sizes and it looks like this:


Lets say we want a preferred width of 300, what do we put for the preferred height?
We can't put in an arbitrary preferred height and hope Swing will trim it down, instead it just obeys what we tell it:

     ta.setPreferredSize(new Dimension(300, 100000));

TextArea Pref Size: java.awt.Dimension[width=300,height=10000]
ScrollPane Pref Size: java.awt.Dimension[width=304,height=10004]




So the trick is to get Swing to calculate the height for a given width and text...

We're told never to user setSize() methods on components, we should let the layout manager set the size, we should always use setPreferredSize().
This is an exception, if we set our actual width and also pass an arbitrary and very large height: Swing will automatically set the preferred size to suit only the text at our given width. All the extra height will be ignored.

     JTextArea ta = new JTextArea();  
     ta.setLineWrap(true);  
     ta.setText("112 312 3 12 31 2432135r34534t 3 t3 4t34y4hthefbasdgagaergergwreg"  
         + "rwergerg ergergergefdav asdvsadg sadgsad gsdgsdgsadgsgd sdgsdg"  
         + "sdg sdgsdgsdg sdgsdgsdgsgh4hgaregwaegasdg sdgsdg sagae4gsaegs "  
         + " sdgsdg sdg s gs dg sd gs dg sdg sdg sadgsdg sad gsa dg s"  
         + "se gs eg se g saeg sa eg s eg sa eg e g eg aweg");  
     JScrollPane sp = new JScrollPane(ta);  
     ta.setSize(300, 100000); // desired width, but deliberately large height.  
     System.out.println("TextArea Pref Size: " + ta.getPreferredSize());  
     System.out.println("ScrollPane Pref Size: " + sp.getPreferredSize());  


TextArea Pref Size: java.awt.Dimension[width=300,height=112]
ScrollPane Pref Size: java.awt.Dimension[width=304,height=116]


Look, the component has been sized to exactly match our text at our preferred width!

Use textComponent.setSize(preferredWidth, 1000000)to set a preferred size for text components.

Saturday, October 24, 2009

Listen Again - Last Broadcast

Looks like the ListenAgain widget has played it's last tune.

The widget works by gathering the radio programme information from the iPlayer website. Sometimes the BBC changes the layout of the iPlayer site slightly forcing me to tweak the widget to adapt to the new layout. Unfortunately this time it looks like the changes were much larger, at least internally, and I can't seem to find the URL for the Real Audio stream of each programme. In fact it doesn't look like they use Real Audio at all anymore - only Flash.

This spells the end for the widget I think, from now on you'll have to listen directly with iPlayer.

Thursday, October 15, 2009

MyCaltrain back on sale!

I've reposted the MyCaltrain iPhone app to the app store and updated the schedule due to popular request - depending on your definition of popular - it's currently undergoing Apple review and if it passes it should be available in a few days.

If you like it, please take the time to give it a nice review.

Thanks,
Neil.

Wednesday, September 9, 2009

MyCaltrain Source Code

If you'd like to have a go at updating the Caltrain widget to the new schedule, then here's the source code.
The schedules are stored in the app as text files which were created by cut and pasting the timetable from a page on Caltrain's website.
As long as the text file format is the same, you should be able to do the update, rebuild and test.

The source code is licensed under the GPL.

Let me know if you get something working.

Sunday, August 30, 2009

MyCaltrain removed from sale


The Caltrain schedule undergoes a revision this week, as the app isn't up to date I am withdrawing it from sale to prevent confusion for riders.
As I currently don't ride Caltrain, and because the app is given away for free, I can't justify spending time on this project anymore - so I currently have no plans to update it and bring it back.
Thanks to everyone who used the app and liked it, especially the guy who gave it the stella review.

If you like the app and fancy a bit of iPhone development I am more than willing to send or post the code so you can update it and put it back up for (free) distribution. Please email me or post a comment if interested.

Sunday, April 26, 2009

Listen Again v3.5



Listen to the large archive of recent BBC Radio programmes directly from Dashboard.

Currently supports: Radio 1, 1xtra, Radio 2, Radio 3, Radio 4, 5 live, 5 extra, 6 Music, 7, Asian Network, Radio Scotland, Radio Ulster, Radio Wales, and all local radio. 55 stations in total.

Requires RealPlayer 10.1
Update, RealPlayer 11 doesn't play when Dashboard is hidden. Use RealPlayer 10.1

Download BBCListenAgain Widget

Shortcut Keys:
Space - Play/Pause
Up/Down - Volume
Left/Right - Skip
s - Stop
v - Voiceover feedback
p - Focus on station popup

What's new:
3.5
- Fixed to work with another iPlayer change
- Added local radio (55 stations in total)

3.4
- Fixed to work with another iPlayer change
- Fixed 'Listen Live'

3.33
- Fixed to work with another iPlayer change
- Added auto update mechanism
- Pressing the 'v' key will enable additional spoken feedback.

3.31
- Descriptions of programmes fixed (broken due to BBC slightly rearranging their iPlayer content)

3.3
- Works with new BBC iPlayer website
- Accessibility: Voiceover use is detected and certain actions are spoken if turned on.
- Better font resizing
- Busy feedback

This has been developed and tested on Mac 10.5

VoiceOver users: when selecting stations use VoiceOver keys with the arrows to select the station from the menu.

Troubleshooting:
Try and play directly from the BBC website. If it works there then it will almost certainly work in Dashboard. If not the problem has historically been issues with RealPlayer - try uninstalling and reinstalling RealPlayer using the version from the BBC website. Reboot after the reinstall to restart Dashboard.

Let me know any other problems.

Mac OS X 10.4 Tiger is required. If you're using Safari, click the download link. When the widget download is complete, Show Dashboard, click the Plus sign to display the Widget Bar and click the widget's icon in the Widget Bar to open it. If you're using a browser other than Safari, click the download link. When the widget download is complete, unarchive it and place it in /Library/Widgets/ in your home folder. Show Dashboard, click the Plus sign to display the Widget Bar and click the widget's icon in the Widget Bar to open it.