Created
December 23, 2010 20:18
-
-
Save kattrali/753489 to your computer and use it in GitHub Desktop.
Non-modal pop-up dialog in JRuby/SWT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.eclipse.swt.custom.StyledText | |
import org.eclipse.swt.custom.StyleRange | |
class KeyListener | |
def initialize(shell) | |
@shell = shell | |
end | |
def key_pressed(e) | |
@shell.dispose | |
end | |
def key_released(e) | |
end | |
end | |
def modeless_message(title,message,width=250,height=100) | |
parent = Redcar::ApplicationSWT.display | |
shell = Swt::Widgets::Shell.new(parent, Swt::SWT::MODELESS) | |
layout = Swt::Layout::GridLayout.new | |
layout.marginHeight = 0 | |
layout.marginWidth = 0 | |
layout.verticalSpacing = 0 | |
shell.setLayout(layout) | |
shell.set_size(width,height) | |
text = StyledText.new(shell, Swt::SWT::WRAP) | |
text.setLayoutData(Swt::Layout::GridData.new(Swt::Layout::GridData::FILL_BOTH)) | |
text.set_editable false | |
new_line = "\n\n" | |
new_line = "\r\n\r\n" if Redcar.platform == :windows | |
text.set_text(title + new_line + message) | |
style1 = StyleRange.new | |
style1.start = 0 | |
style1.length = title.split(//).length | |
style1.fontStyle = Swt::SWT::BOLD | |
style1.foreground = parent.getSystemColor(Swt::SWT::COLOR_WHITE) | |
text.setStyleRange(style1) | |
text.set_margins(2,2,2,2) | |
text.setBackground(Swt::Graphics::Color.new(parent, 230, 240, 255)) | |
text.setLineBackground(0, 1, Swt::Graphics::Color.new(parent, 135, 178, 247)) | |
text.set_caret(nil) | |
text.add_key_listener(KeyListener.new(shell)) | |
x, y = Redcar.gui.dialog_adapter.send(:get_coordinates, :cursor) | |
shell.set_location(x,y) | |
shell.open | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment