Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gbfactory committed Jan 30, 2021
0 parents commit 78f368a
Show file tree
Hide file tree
Showing 20 changed files with 252 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/Teleprompter_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Teleprompter.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
15 changes: 15 additions & 0 deletions src/Frame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import javax.swing.*;
import java.awt.*;

public class Frame extends JFrame {
Frame() {
super("Teleprompter");
setLayout(new BorderLayout());
add(new Teleprompter(), BorderLayout.CENTER);
setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("teleprompter.png")));
setSize(1080, 720);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Main

5 changes: 5 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
new Frame();
}
}
187 changes: 187 additions & 0 deletions src/Teleprompter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;

public class Teleprompter extends JPanel implements KeyListener {

private static boolean isEditing = true;
private static boolean isRunning = false;

private static int spostamento = 1;

private static JTextArea taText;
private static JScrollPane spTele;
private static JPanel pnlControlli;
private static JButton btnPaste, btnStart, btnReset, btnAvanti, btnIndietro, btnSpeed, btnText, btnClear;

private static Timer timer;

Teleprompter() {

timer = new Timer(50, e -> scrollBar(spostamento));

taText = new JTextArea();
taText.setFont(new Font("Verdana", Font.BOLD, 70));
taText.setBackground(Color.BLACK);
taText.setForeground(Color.WHITE);
taText.setCaretColor(Color.GRAY);
taText.setLineWrap(true);
taText.setWrapStyleWord(true);

spTele = new JScrollPane(taText);
spTele.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
spTele.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

setLayout(new BorderLayout());

add(spTele, BorderLayout.CENTER);

// Controlli
pnlControlli = new JPanel();
pnlControlli.setLayout(new GridLayout(8, 1));

btnStart = new JButton(new ImageIcon(this.getClass().getResource("start.png")));
btnStart.addKeyListener(this);
btnStart.addActionListener(e -> {
toggleEdit();
togglePrompter();
});

btnReset = new JButton(new ImageIcon(this.getClass().getResource("restart.png")));
btnReset.addKeyListener(this);
btnReset.addActionListener(e -> resetPrompter());

btnAvanti = new JButton(new ImageIcon(this.getClass().getResource("doublearrowinv.png")));
btnAvanti.addActionListener(e -> {
scrollBar(-70);
});

btnIndietro = new JButton(new ImageIcon(this.getClass().getResource("doublearrow.png")));
btnIndietro.addActionListener(e -> {
scrollBar(70);
});

btnSpeed = new JButton(new ImageIcon(this.getClass().getResource("speed.png")));
btnSpeed.addActionListener(e -> {
JLabel lblNum = new JLabel(spostamento + "");
lblNum.setHorizontalAlignment(JLabel.CENTER);
lblNum.setFont(new Font("Verdana", Font.BOLD, 20));

JButton btnAdd = new JButton("+");
btnAdd.setFont(new Font("Verdana", Font.BOLD, 30));
btnAdd.addActionListener(e1 -> {
int num = Integer.parseInt(lblNum.getText());
num++;
lblNum.setText(num + "");
});

JButton btnRemove = new JButton("-");
btnRemove.setFont(new Font("Verdana", Font.BOLD, 30));
btnRemove.addActionListener(e1 -> {
int num = Integer.parseInt(lblNum.getText());
if (num > 1) {
num--;
lblNum.setText(num + "");
}
});

JPanel panel = new JPanel(new GridLayout(1, 3));

panel.add(btnRemove);
panel.add(lblNum);
panel.add(btnAdd);

int result = JOptionPane.showConfirmDialog(null, panel, "Velocità", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

if (result == JOptionPane.OK_OPTION) {
int num = Integer.parseInt(lblNum.getText());
if (num > 0) {
spostamento = num;
}
}
});

btnText = new JButton(new ImageIcon(this.getClass().getResource("text.png")));

btnPaste = new JButton(new ImageIcon(this.getClass().getResource("paste.png")));
btnPaste.addActionListener(e -> {
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this);
try {
if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
String text = (String)t.getTransferData(DataFlavor.stringFlavor);
taText.setText(text);
}
} catch (UnsupportedFlavorException | IOException ignored) {
}
});

btnClear = new JButton(new ImageIcon(this.getClass().getResource("rubber.png")));
btnClear.addActionListener(e -> taText.setText(""));

pnlControlli.add(btnStart);
pnlControlli.add(btnReset);
pnlControlli.add(btnAvanti);
pnlControlli.add(btnIndietro);
pnlControlli.add(btnSpeed);
pnlControlli.add(btnText);
pnlControlli.add(btnPaste);
pnlControlli.add(btnClear);

add(pnlControlli, BorderLayout.LINE_START);
}

private void resetPrompter() {
JScrollBar vertical = spTele.getVerticalScrollBar();
vertical.getModel().setValue(vertical.getMinimum());
}

private void scrollBar(int x) {
JScrollBar vertical = spTele.getVerticalScrollBar();
int posizione = vertical.getModel().getValue();
vertical.getModel().setValue(posizione + x);
}

private void toggleEdit() {
if (isEditing) {
taText.setEditable(false);
isEditing = false;
} else {
taText.setEditable(true);
isEditing = true;
}
}

private void togglePrompter() {
if (!isRunning) {
timer.start();
isRunning = true;
btnStart.setIcon(new ImageIcon(this.getClass().getResource("stop.png")));
} else {
timer.stop();
isRunning = false;
btnStart.setIcon(new ImageIcon(this.getClass().getResource("start.png")));
}
}

@Override
public void keyTyped(KeyEvent e) {

}

@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_S && !isEditing) {
togglePrompter();
}
}

@Override
public void keyReleased(KeyEvent e) {

}
}
Binary file added src/doublearrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/doublearrowinv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/paste.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/restart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/rubber.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/speed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/teleprompter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 78f368a

Please sign in to comment.