comparison src/Main.java @ 0:4e9f2e87eb7b

Repository start, basic interface mockups
author Fox
date Fri, 01 Apr 2022 00:32:11 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4e9f2e87eb7b
1
2 import java.awt.Dimension;
3 import java.awt.Font;
4
5 import javax.swing.JFrame;
6 import javax.swing.JPanel;
7
8 import java.awt.CardLayout;
9 import java.awt.BorderLayout;
10 import javax.swing.BoxLayout;
11
12 import javax.swing.Box;
13 import javax.swing.JButton;
14 import javax.swing.JTextField;
15 import javax.swing.JTextArea;
16 import javax.swing.JScrollPane;
17
18
19 public class Main {
20
21 public enum Tab {
22 SEARCH,
23 EDIT,
24 };
25
26 public static final String PROGRAM_NAME = "Junotu";
27
28 private static final String[] TAB_NAMES = {
29 "Search",
30 "Edit",
31 };
32
33 private static JFrame window;
34
35 private static JPanel tabs;
36 private static CardLayout tabsLayout;
37 private static JPanel search;
38 private static JPanel edit;
39
40 private static int activeTab = 0;
41
42 public static void main(String[] args)
43 {
44
45 window = new JFrame();
46 panelsCreate();
47 tabSwitch(Tab.EDIT.ordinal());
48
49 window.setSize(384, 384);
50 //window.setLayout(null);
51 window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
52 window.setVisible(true);
53 }
54
55 public static void tabSwitch( int tab )
56 {
57 tabsLayout.show(tabs, TAB_NAMES[tab]);
58 activeTab = tab;
59 window.setTitle(preferredTitle());
60 }
61
62 private static void panelsCreate()
63 {
64
65 tabsLayout = new CardLayout();
66 tabs = new JPanel( tabsLayout );
67
68 panelsCreateSearch();
69 panelsCreateEdit();
70
71 window.add(tabs);
72 tabs.add(search);
73 tabs.add(edit);
74 tabsLayout.addLayoutComponent( search, TAB_NAMES[Tab.SEARCH.ordinal()] );
75 tabsLayout.addLayoutComponent( edit, TAB_NAMES[Tab.EDIT.ordinal()] );
76
77 }
78
79 private static void panelsCreateSearch()
80 {
81 search = new JPanel( new BorderLayout() );
82
83 JPanel top = new JPanel( new BorderLayout() );
84 JTextField field = new JTextField("Type here..");
85 JButton submit = new JButton("Search");
86
87 field.setPreferredSize( new Dimension(32, 32) );
88
89 search.add( top, BorderLayout.NORTH );
90 top.add( field, BorderLayout.CENTER );
91 top.add( submit, BorderLayout.EAST );
92
93 }
94
95 private static void panelsCreateEdit()
96 {
97 edit = new JPanel( new BorderLayout() );
98
99 Box scrollContent = Box.createVerticalBox();
100 JScrollPane scroll = new JScrollPane( scrollContent );
101 JTextField title = new JTextField( "Title" );
102 JTextArea content = new JTextArea( "Here you go. Some text." );
103
104 Box bottom = Box.createHorizontalBox();
105 JButton back = new JButton("Cancel");
106 JButton save = new JButton("Save");
107
108 title.setFont( new Font( "Monospaced", Font.PLAIN, 32 ) );
109 content.setFont( new Font( "Monospaced", Font.PLAIN, 16 ) );
110
111 scroll.getVerticalScrollBar().setUnitIncrement(16);
112
113 title.setMaximumSize( new Dimension( 1000000, 64 ) );
114
115 edit.add( scroll, BorderLayout.CENTER );
116 scrollContent.add( title );
117 scrollContent.add( Box.createVerticalStrut(10) );
118 scrollContent.add( content );
119
120 edit.add( bottom, BorderLayout.SOUTH );
121 bottom.add( back );
122 bottom.add( Box.createHorizontalGlue() );
123 bottom.add( save );
124
125 //scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
126
127 }
128
129 private static String preferredTitle()
130 {
131 return PROGRAM_NAME+" - "+TAB_NAMES[activeTab];
132 }
133
134 }