Skip to content

Commit 0835804

Browse files
author
Daniil-Osokin
committedNov 30, 2015
Merge pull request #132 from A-Kostrov/lab2-mvvm-tree
Костров - Лабораторная работа #2
2 parents 936f86b + d1d8300 commit 0835804

File tree

13 files changed

+513
-2
lines changed

13 files changed

+513
-2
lines changed
 
File renamed without changes.
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dependencies {
2+
compile project(':kostrov-aleksey-ViewModel')
3+
}
4+
5+
sourceSets {
6+
main.java.srcDir 'src/main/java'
7+
test.java.srcDir 'src/test/java'
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ru.unn.agile.TreeStructure.view.TreeView">
3+
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="0" left="0" bottom="0" right="0"/>
5+
<constraints>
6+
<xy x="12" y="19" width="939" height="526"/>
7+
</constraints>
8+
<properties>
9+
<minimumSize width="398" height="250"/>
10+
<preferredSize width="398" height="250"/>
11+
</properties>
12+
<border type="none"/>
13+
<children>
14+
<grid id="d0210" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
15+
<margin top="0" left="0" bottom="0" right="0"/>
16+
<constraints>
17+
<grid row="0" column="1" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
18+
</constraints>
19+
<properties/>
20+
<border type="none"/>
21+
<children>
22+
<component id="449f3" class="javax.swing.JRadioButton" binding="searchRadioButton">
23+
<constraints>
24+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
25+
</constraints>
26+
<properties>
27+
<opaque value="true"/>
28+
<rolloverEnabled value="false"/>
29+
<text value="Search_by_key"/>
30+
</properties>
31+
</component>
32+
<component id="aa21a" class="javax.swing.JRadioButton" binding="truncateRadioButton" default-binding="true">
33+
<constraints>
34+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
35+
</constraints>
36+
<properties>
37+
<text value="Truncate"/>
38+
</properties>
39+
</component>
40+
<component id="e9e44" class="javax.swing.JRadioButton" binding="insertRadioButton" default-binding="true">
41+
<constraints>
42+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
43+
</constraints>
44+
<properties>
45+
<enabled value="true"/>
46+
<hideActionText value="false"/>
47+
<selected value="false"/>
48+
<text value="Insert"/>
49+
<verifyInputWhenFocusTarget value="true"/>
50+
<visible value="true"/>
51+
</properties>
52+
</component>
53+
<component id="24b31" class="javax.swing.JButton" binding="buttonDo">
54+
<constraints>
55+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
56+
</constraints>
57+
<properties>
58+
<text value="DO!"/>
59+
</properties>
60+
</component>
61+
</children>
62+
</grid>
63+
<grid id="33295" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
64+
<margin top="0" left="0" bottom="0" right="0"/>
65+
<constraints>
66+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
67+
</constraints>
68+
<properties/>
69+
<border type="none"/>
70+
<children>
71+
<component id="39339" class="javax.swing.JTextField" binding="textKey">
72+
<constraints>
73+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
74+
<preferred-size width="150" height="-1"/>
75+
</grid>
76+
</constraints>
77+
<properties>
78+
<horizontalAlignment value="0"/>
79+
<text value=""/>
80+
</properties>
81+
</component>
82+
<component id="f811d" class="javax.swing.JTextField" binding="textDataFromNode">
83+
<constraints>
84+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
85+
<preferred-size width="150" height="-1"/>
86+
</grid>
87+
</constraints>
88+
<properties>
89+
<horizontalAlignment value="0"/>
90+
<text value=""/>
91+
</properties>
92+
</component>
93+
</children>
94+
</grid>
95+
<grid id="5dd64" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
96+
<margin top="0" left="0" bottom="0" right="0"/>
97+
<constraints>
98+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
99+
</constraints>
100+
<properties/>
101+
<border type="none"/>
102+
<children>
103+
<component id="4bec" class="javax.swing.JTextArea" binding="textError">
104+
<constraints>
105+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
106+
<preferred-size width="150" height="50"/>
107+
</grid>
108+
</constraints>
109+
<properties>
110+
<enabled value="false"/>
111+
<font size="18"/>
112+
<text value=""/>
113+
</properties>
114+
</component>
115+
</children>
116+
</grid>
117+
</children>
118+
</grid>
119+
<buttonGroups>
120+
<group name="buttonsOperationGroup">
121+
<member id="449f3"/>
122+
<member id="aa21a"/>
123+
<member id="e9e44"/>
124+
</group>
125+
</buttonGroups>
126+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package ru.unn.agile.TreeStructure.view;
2+
import ru.unn.agile.TreeStructure.viewmodel.TreeViewModel;
3+
import javax.swing.*;
4+
import javax.swing.event.DocumentEvent;
5+
import javax.swing.event.DocumentListener;
6+
import java.awt.event.*;
7+
8+
public final class TreeView {
9+
private JPanel mainPanel;
10+
private ButtonGroup operationButtonGroup;
11+
private JRadioButton insertRadioButton;
12+
private JRadioButton searchRadioButton;
13+
private JRadioButton truncateRadioButton;
14+
private JButton buttonDo;
15+
private JTextArea textError;
16+
private JTextField textKey;
17+
private JTextField textDataFromNode;
18+
private TreeViewModel viewModel;
19+
private String operation;
20+
21+
private TreeView() { }
22+
private TreeView(final TreeViewModel viewModel) {
23+
this.viewModel = viewModel;
24+
operation = "Insert";
25+
operationButtonGroup = new ButtonGroup();
26+
operationButtonGroup.add(insertRadioButton);
27+
operationButtonGroup.add(searchRadioButton);
28+
operationButtonGroup.add(truncateRadioButton);
29+
operationButtonGroup.setSelected(insertRadioButton.getModel(), true);
30+
insertRadioButton.setActionCommand("Insert");
31+
searchRadioButton.setActionCommand("Search");
32+
truncateRadioButton.setActionCommand("Truncate");
33+
34+
buttonDo.addActionListener(new ActionListener() {
35+
@Override
36+
public void actionPerformed(final ActionEvent e) {
37+
treeViewBackBind();
38+
TreeView.this.viewModel.doOperation();
39+
treeViewBind();
40+
}
41+
});
42+
43+
ActionListener listenerRadioButton = new ActionListener() {
44+
@Override
45+
public void actionPerformed(final ActionEvent e) {
46+
treeViewBackBind();
47+
treeViewBind();
48+
}
49+
};
50+
searchRadioButton.addActionListener(listenerRadioButton);
51+
truncateRadioButton.addActionListener(listenerRadioButton);
52+
insertRadioButton.addActionListener(listenerRadioButton);
53+
54+
textKey.getDocument().addDocumentListener(new DocumentListener() {
55+
@Override
56+
public void insertUpdate(final DocumentEvent e) {
57+
treeViewBackBind();
58+
treeViewBind();
59+
}
60+
61+
@Override
62+
public void removeUpdate(final DocumentEvent e) {
63+
treeViewBackBind();
64+
treeViewBind();
65+
}
66+
67+
@Override
68+
public void changedUpdate(final DocumentEvent e) {
69+
treeViewBackBind();
70+
treeViewBind();
71+
}
72+
});
73+
treeViewBackBind();
74+
treeViewBind();
75+
}
76+
77+
private void treeViewBind() {
78+
buttonDo.setEnabled(viewModel.isDoButtonEnabled());
79+
textDataFromNode.setEnabled(viewModel.isDataTextFieldEnabled());
80+
textDataFromNode.setText(viewModel.getSearchedData());
81+
textError.setText(viewModel.getErrorMessage());
82+
}
83+
84+
private void treeViewBackBind() {
85+
operation = operationButtonGroup.getSelection().getActionCommand();
86+
viewModel.setOperation(operation);
87+
viewModel.setKey(textKey.getText());
88+
viewModel.setDataFromNode(textDataFromNode.getText());
89+
}
90+
91+
public static void main(final String[] args) {
92+
JFrame frame = new JFrame("TreeView");
93+
frame.setContentPane(new TreeView(new TreeViewModel()).mainPanel);
94+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
95+
frame.pack();
96+
frame.setVisible(true);
97+
}
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ru.unn.agile.TreeStructure.view;
2+
3+
import org.junit.Ignore;
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.fail;
7+
8+
public class FakeTreeViewTests {
9+
@Ignore @Test
10+
public void fakeTreeTest() {
11+
fail("There is no tests for view");
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dependencies {
2+
compile project(':kostrov-aleksey-Model')
3+
}
4+
5+
sourceSets {
6+
main.java.srcDir 'src/main/java'
7+
test.java.srcDir 'src/test/java'
8+
}

0 commit comments

Comments
 (0)