Skip to content

Instantly share code, notes, and snippets.

View eugener's full-sized avatar

Eugene Ryzhikov eugener

View GitHub Profile
@eugener
eugener / gist:623213
Created October 13, 2010 01:00
Equivalent of C# using keyword. Automatically closes any resource which has a close method. Capable of returning a value
object Controls {
type CloseableResource = { def close() }
/**
* Equivalent of C# using keyword. Automatically closes any resource which has a close method.
* Capable of returning a value
* @param T resource which has a close() method
* @param M result
*/
@eugener
eugener / TableColumnDefinitionSupport
Last active September 23, 2015 22:57
Minimizing Table Model Maintenance
public final class TableColumnDefinitionSupport {
public interface ITableColumDefinition {
String getTitle();
}
private TableColumnDefinitionSupport() {}
public final static > getDefinition( Class cls, int index ) {
return cls.getEnumConstants()[index];
public class ComponentClassScanner extends ClassPathScanningCandidateComponentProvider {
public ComponentClassScanner() {
super(false);
}
@SuppressWarnings("unchecked")
public final Collection getComponentClasses(String basePackage) {
basePackage = basePackage == null ? "" : basePackage;
List<Class<? extends T>> classes = new ArrayList<Class<? extends T>>();
class PreferencePageClassScanner extends ComponentClassScanner {
public PreferencePageClassScanner() {
super();
addIncludeFilter( new AssignableTypeFilter(JComponent.class));
addIncludeFilter( new AnnotationTypeFilter(PreferencePage.class));
}
}
public final class TableEnumColumnSupport {
public interface ITableColumDefinition {
String getTitle();
}
private TableEnumColumnSupport() {}
/**
* Finds column definition by index
boolean validationResult = ...// your business logic here
TaskDialog dlg = TaskDialog.getInstance(this); //find the task dialog panel belongs to
dlg.fireValidationFinished( validationResult );
TaskDialogs.warn( "Are you sure you want to quit?@@10", "Please do not quit yet!");
int choice = TaskDialogs.choice(
"What do you want to do with your game in\nprogress?",
"",
1,
new CommandLink("Exit and save my game", "Save your game in progress, then exit. " +
"This will\noverwrite any previosely saved games."),
new CommandLink("Exit and don't save", "Exit without saving your game. " +
"This is counted\nas a loss in your statistics." ),
new CommandLink("Don't exit", "Return to your game progress" ));
TaskDialog dlg = new TaskDialog("Security Warning");
dlg.setInstruction( "The publisher cannot be verified.\nDo you want to run this software?" );
dlg.setText( "Name: C:\\Program Files\\eclipse\\eclipse.exe\n" +
"Publisher: <b>Unknown Publisher</b>\n" +
"Type: Application\n");
dlg.setIcon( TaskDialog.StandardIcon.WARNING );
dlg.getFooter().setCheckBoxText("Always ask before opening this file");
dlg.setCommands( StandardCommand.OK.derive("Run"), StandardCommand.CANCEL );
if ( dlg.show().equals(StandardCommand.OK)) {
//do something
TaskDialog dlg = new TaskDialog("Copying...");
dlg.setInstruction("Copying file");
dlg.setText( "Location: From 'Others' to 'Others'\n" +
"File Name: <b>Photo.jpg</b>" );
dlg.setIcon( TaskDialog.StandardIcon.INFO );
JProgressBar pb = new JProgressBar();
pb.setValue(30);
dlg.setFixedComponent( pb );
dlg.show();