Skip to content

Commit abcd7ad

Browse files
committed
Merge pull request #2 from LittleRolf/feature/gui
Feature/gui
2 parents d404b67 + f08bb5a commit abcd7ad

File tree

5 files changed

+89
-15
lines changed

5 files changed

+89
-15
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
*target*
2-
*.jar
32
*.war
43
*.ear
54
*.class
@@ -26,3 +25,4 @@ local.properties
2625
# Locally stored "Eclipse launch configurations"
2726
*.launch
2827

28+
Thumbs.db

libs/jsyntaxpane-0.9.5-b29.jar

388 KB
Binary file not shown.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package de.littlerolf.sav.gui;
2+
3+
import java.awt.BorderLayout;
4+
5+
import javax.swing.JEditorPane;
6+
import javax.swing.JFrame;
7+
import javax.swing.JMenu;
8+
import javax.swing.JMenuBar;
9+
import javax.swing.JMenuItem;
10+
import javax.swing.JScrollPane;
11+
12+
public class CodeEditorFrame extends JFrame {
13+
14+
/**
15+
*
16+
*/
17+
private static final long serialVersionUID = 738669143009851723L;
18+
private JEditorPane codeEditor = new JEditorPane();
19+
20+
public CodeEditorFrame() {
21+
setTitle("Code Editor");
22+
getContentPane().setLayout(new BorderLayout());
23+
24+
JScrollPane scrPane = new JScrollPane(codeEditor);
25+
getContentPane().add(scrPane, BorderLayout.CENTER);
26+
getContentPane().doLayout();
27+
codeEditor.setContentType("text/java");
28+
codeEditor.setText("public static void main(String[] args) {\n}");
29+
30+
setSize(800, 600);
31+
32+
JMenuBar menuBar = new JMenuBar();
33+
setJMenuBar(menuBar);
34+
35+
JMenu mnDatei = new JMenu("Datei");
36+
menuBar.add(mnDatei);
37+
38+
JMenuItem mntmSpeichern = new JMenuItem("Speichern");
39+
mnDatei.add(mntmSpeichern);
40+
41+
}
42+
}

src/de/littlerolf/sav/gui/SAVFrame.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package de.littlerolf.sav.gui;
22

3+
import java.awt.Dimension;
4+
import java.awt.Toolkit;
5+
36
import javax.swing.JButton;
47
import javax.swing.JComboBox;
58
import javax.swing.JFrame;
@@ -9,12 +12,17 @@
912
import javax.swing.UIManager;
1013
import javax.swing.UnsupportedLookAndFeelException;
1114

15+
import jsyntaxpane.DefaultSyntaxKit;
16+
1217
public class SAVFrame extends JFrame {
1318
public SAVFrame() {
1419
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
1520
setResizable(false);
1621
setTitle("SortAlgorithmVisualizer");
17-
setSize(800, 420);
22+
setSize(906, 400);
23+
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
24+
this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height
25+
/ 2 - this.getSize().height / 2);
1826
getContentPane().setLayout(null);
1927

2028
JButton btnSimulieren = new JButton("Simulieren");
@@ -26,23 +34,25 @@ public SAVFrame() {
2634
getContentPane().add(btnAbspielen);
2735

2836
JComboBox comboBox = new JComboBox();
29-
comboBox.setBounds(596, 333, 178, 20);
37+
comboBox.setBounds(596, 333, 294, 20);
3038
getContentPane().add(comboBox);
3139

3240
JSlider slider = new JSlider();
41+
slider.setToolTipText("gemessen in Fischbr\u00F6tchen pro Sekunde");
3342
slider.setBounds(430, 332, 156, 23);
3443
getContentPane().add(slider);
3544

3645
JLabel lblGeschwindigkeit = new JLabel("Geschwindigkeit:");
37-
lblGeschwindigkeit.setBounds(430, 294, 89, 14);
46+
lblGeschwindigkeit.setBounds(430, 307, 89, 14);
3847
getContentPane().add(lblGeschwindigkeit);
3948

4049
JLabel lblImplementation = new JLabel("Implementation:");
41-
lblImplementation.setBounds(596, 294, 89, 14);
50+
lblImplementation.setBounds(596, 307, 89, 14);
4251
getContentPane().add(lblImplementation);
4352

4453
JLabel lblKontrolle = new JLabel("Kontrolle:");
45-
lblKontrolle.setBounds(10, 294, 89, 14);
54+
lblKontrolle.setToolTipText("oder auch \"Cockpit\"... h\u00F6h\u00F6, \"Cock\"...");
55+
lblKontrolle.setBounds(10, 307, 89, 14);
4656
getContentPane().add(lblKontrolle);
4757

4858
JLabel lblSchritte = new JLabel("Schritte:");
@@ -74,14 +84,24 @@ public SAVFrame() {
7484
getContentPane().add(lblSpeed);
7585

7686
JScrollPane scrollPane = new JScrollPane();
77-
scrollPane.setBounds(10, 11, 774, 272);
87+
scrollPane.setBounds(10, 11, 880, 272);
7888
getContentPane().add(scrollPane);
7989

8090
SAVHistoryComponent historyComponent = new SAVHistoryComponent();
8191
scrollPane.setViewportView(historyComponent);
92+
93+
JButton btnNew = new JButton("Neu...");
94+
btnNew.setBounds(710, 303, 75, 23);
95+
getContentPane().add(btnNew);
96+
97+
JButton btnEdit = new JButton("Bearbeiten...");
98+
btnEdit.setBounds(787, 303, 103, 23);
99+
getContentPane().add(btnEdit);
82100
}
83101

84102
public static void main(String[] args) {
103+
DefaultSyntaxKit.initKit();
104+
85105
try {
86106
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
87107
} catch (UnsupportedLookAndFeelException e) {
@@ -90,6 +110,7 @@ public static void main(String[] args) {
90110
} catch (IllegalAccessException e) {
91111
}
92112
new SAVFrame().setVisible(true);
113+
new CodeEditorFrame().setVisible(true);
93114
}
94115

95116
/**

src/de/littlerolf/sav/gui/SAVHistoryComponent.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package de.littlerolf.sav.gui;
22

33
import java.awt.Graphics;
4+
import java.awt.Graphics2D;
5+
import java.awt.RenderingHints;
46
import java.awt.image.BufferedImage;
57
import java.io.IOException;
68
import java.util.ArrayList;
@@ -15,9 +17,10 @@ public class SAVHistoryComponent extends JComponent {
1517

1618
private static final long serialVersionUID = 1099284147258735099L;
1719

18-
private static final int PLAYING_CARD_AMOUNT = 52;
20+
public static final int PLAYING_CARD_AMOUNT = 52;
1921

2022
private BufferedImage[] cardImages;
23+
2124
{
2225
cardImages = new BufferedImage[PLAYING_CARD_AMOUNT];
2326
String[] names = new String[] { "2", "3", "4", "5", "6", "7", "8", "9",
@@ -51,7 +54,7 @@ public class SAVHistoryComponent extends JComponent {
5154

5255
public SAVHistoryComponent() {
5356
HistoryItem i = new HistoryItem();
54-
i.values = new int[] { 4, 50, 42, 3 };
57+
i.values = new int[] { 4, 10, 5, 20, 50, 10, 3, 48 };
5558
getHistoryItems().add(i);
5659
}
5760

@@ -68,8 +71,13 @@ public void reset() {
6871
}
6972

7073
@Override
71-
protected void paintComponent(Graphics g) {
72-
super.paintComponent(g);
74+
protected void paintComponent(Graphics g1) {
75+
super.paintComponent(g1);
76+
Graphics2D g = (Graphics2D) g1;
77+
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
78+
RenderingHints.VALUE_ANTIALIAS_ON);
79+
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
80+
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
7381

7482
HistoryItem currentItem = getHistoryItems().get(currentIndex);
7583
if (currentItem == null)
@@ -78,15 +86,18 @@ protected void paintComponent(Graphics g) {
7886
int valueAmount = currentItem.values.length;
7987
int width = getWidth();
8088
int height = getHeight();
81-
int x = 0;
89+
int i = 0;
90+
int diff = width / 2 / valueAmount;
8291
for (int value : currentItem.values) {
8392
if (value > cardImages.length || value < 0)
8493
continue;
94+
8595
BufferedImage cardImage = cardImages[value];
8696
g.drawImage(cardImage,
87-
x + width / 2 - (valueAmount * cardImage.getWidth()) / 2,
88-
height / 2 - cardImage.getHeight() / 2, null);
89-
x += cardImage.getWidth();
97+
(width / 4) + (i * diff) - cardImage.getWidth() / 8, height
98+
/ 2 - cardImage.getHeight() / 2 / 2,
99+
cardImage.getWidth() / 2, cardImage.getHeight() / 2, null);
100+
i++;
90101
}
91102
}
92103

0 commit comments

Comments
 (0)