Class: Clevic::TagEditor

Inherits:
Object show all
Defined in:
lib/clevic/swing/tag_editor.rb

Overview

all this just to format a display item… .… and work around various other Swing stupidities

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field) ⇒ TagEditor

Returns a new instance of TagEditor.



8
9
10
11
12
13
14
# File 'lib/clevic/swing/tag_editor.rb', line 8

def initialize( field )
  super()
  @field = field

  create_fields
  init_layout
end

Instance Attribute Details

#add_buttonObject (readonly)

Returns the value of attribute add_button.



26
27
28
# File 'lib/clevic/swing/tag_editor.rb', line 26

def add_button
  @add_button
end

#cancel_buttonObject (readonly)

Returns the value of attribute cancel_button.



26
27
28
# File 'lib/clevic/swing/tag_editor.rb', line 26

def cancel_button
  @cancel_button
end

#entityObject (readonly)

Returns the value of attribute entity.



17
18
19
# File 'lib/clevic/swing/tag_editor.rb', line 17

def entity
  @entity
end

#fieldObject (readonly)

Returns the value of attribute field.



16
17
18
# File 'lib/clevic/swing/tag_editor.rb', line 16

def field
  @field
end

#item_listObject (readonly)

Returns the value of attribute item_list.



26
27
28
# File 'lib/clevic/swing/tag_editor.rb', line 26

def item_list
  @item_list
end

#ok_buttonObject (readonly)

Returns the value of attribute ok_button.



26
27
28
# File 'lib/clevic/swing/tag_editor.rb', line 26

def ok_button
  @ok_button
end

#remove_buttonObject (readonly)

Returns the value of attribute remove_button.



26
27
28
# File 'lib/clevic/swing/tag_editor.rb', line 26

def remove_button
  @remove_button
end

#text_fieldObject (readonly)

Returns the value of attribute text_field.



26
27
28
# File 'lib/clevic/swing/tag_editor.rb', line 26

def text_field
  @text_field
end

Instance Method Details

#configureEditor(editor, entity) ⇒ Object

Hopefully called by the editor framework might be init_component



21
22
23
24
# File 'lib/clevic/swing/tag_editor.rb', line 21

def configureEditor( editor, entity )
  @entity = entity
  item_list.model.one = entity
end

#create_fieldsObject



28
29
30
31
32
33
34
35
36
# File 'lib/clevic/swing/tag_editor.rb', line 28

def create_fields
  @item_list = TableView.new( field.many_view )

  @text_field = javax.swing.JTextField.new
  @ok_button = javax.swing.JButton.new
  @cancel_button = javax.swing.JButton.new
  @add_button = javax.swing.JButton.new
  @remove_button = javax.swing.JButton.new
end

#init_layoutObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/clevic/swing/tag_editor.rb', line 38

def init_layout
  # This is mostly cut-n-pasted from the Netbeans Java sources. So don't tweak it.
  text_field.setName("text_field");

  item_list.setName("item_list");

  ok_button.setText("OK");
  ok_button.setToolTipText("Accept edits");
  ok_button.setName("ok_button");

  cancel_button.setText("Cancel");
  cancel_button.setToolTipText("Cancel edits");
  cancel_button.setName("cancel_button");

  add_button.setText("+");
  add_button.setToolTipText("Add a new item");
  add_button.setBorder(nil);
  add_button.setName("add_button");

  remove_button.setText("-");
  remove_button.setToolTipText("Remove selected item");
  remove_button.setBorder(nil);
  remove_button.setName("remove_button");

  layout = org.jdesktop.layout.GroupLayout.new( self );
  setLayout(layout);
  layout.setHorizontalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout::LEADING) \
      .add(layout.createSequentialGroup() \
          .addContainerGap() \
          .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout::LEADING) \
              .add(item_list, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, 210, java.lang.Short::MAX_VALUE) \
              .add(text_field, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, 210, java.lang.Short::MAX_VALUE) \
              .add(layout.createSequentialGroup() \
                  .add(ok_button) \
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle::RELATED, 82, java.lang.Short::MAX_VALUE) \
                  .add(cancel_button)) \
              .add(layout.createSequentialGroup() \
                  .add(add_button, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE, 27, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE) \
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle::RELATED) \
                  .add(remove_button, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE, 27, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE))) \
          .addContainerGap()) \
  );
  layout.setVerticalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout::LEADING) \
      .add(layout.createSequentialGroup() \
          .addContainerGap() \
          .add(text_field, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE) \
          .add(18, 18, 18) \
          .add(item_list, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE, 202, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE) \
          .addPreferredGap(org.jdesktop.layout.LayoutStyle::RELATED) \
          .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout::BASELINE) \
              .add(add_button, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE) \
              .add(remove_button, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE)) \
          .addPreferredGap(org.jdesktop.layout.LayoutStyle::RELATED, 30, java.lang.Short::MAX_VALUE) \
          .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout::BASELINE) \
              .add(ok_button) \
              .add(cancel_button)) \
          .addContainerGap()) \
  );
end