Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Simulator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
letsgoING
ArduBlock Source
Simulator
Commits
fa1c1ae5
Commit
fa1c1ae5
authored
Apr 13, 2021
by
Anian Bühler
Browse files
Options
Downloads
Patches
Plain Diff
added "click & lock"-Buttons to modul "button"
parent
32ad8b40
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tec/letsgoing/ardublock/simulator/view/modules/Button.java
+129
-13
129 additions, 13 deletions
...ec/letsgoing/ardublock/simulator/view/modules/Button.java
src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java
+3
-0
3 additions, 0 deletions
src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java
with
132 additions
and
13 deletions
src/tec/letsgoing/ardublock/simulator/view/modules/Button.java
+
129
−
13
View file @
fa1c1ae5
...
@@ -8,15 +8,17 @@ import java.awt.Image;
...
@@ -8,15 +8,17 @@ import java.awt.Image;
import
java.awt.Point
;
import
java.awt.Point
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.awt.event.ActionListener
;
import
java.awt.event.MouseEvent
;
import
java.awt.event.MouseListener
;
import
java.util.Vector
;
import
java.util.Vector
;
import
javax.swing.ImageIcon
;
import
javax.swing.ImageIcon
;
import
javax.swing.JButton
;
import
javax.swing.JLabel
;
import
javax.swing.JLabel
;
import
javax.swing.JToggleButton
;
import
javax.swing.JToggleButton
;
import
tec.letsgoing.ardublock.simulator.arduino.Arduino
;
import
tec.letsgoing.ardublock.simulator.arduino.Arduino
;
import
tec.letsgoing.ardublock.simulator.arduino.Pin
;
import
tec.letsgoing.ardublock.simulator.arduino.Pin
;
import
tec.letsgoing.ardublock.simulator.view.GUI
;
/**
/**
* Modul mit 3 Toogle Buttons
* Modul mit 3 Toogle Buttons
...
@@ -24,14 +26,75 @@ import tec.letsgoing.ardublock.simulator.view.GUI;
...
@@ -24,14 +26,75 @@ import tec.letsgoing.ardublock.simulator.view.GUI;
* @author Lucas
* @author Lucas
*
*
*/
*/
public
class
Button
extends
Modul
implements
ActionListener
{
public
class
Button
extends
Modul
implements
ActionListener
,
MouseListener
{
private
int
[]
lastState
=
{
0
,
0
,
0
};
private
int
[]
lastState
=
{
0
,
0
,
0
};
private
ImageIcon
iconOff
,
iconOn
,
chipIcon
,
chipIcon_temp
,
iconOff_temp
,
iconOn_temp
;
private
ImageIcon
iconOff
,
iconOn
,
chipIcon
,
chipIcon_temp
,
iconOff_temp
,
iconOn_temp
;
private
JToggleButton
but1
,
but2
,
but3
;
//
private JToggleButton but1, but2, but3;
private
JLabel
chiplabel
,
label1
,
label2
,
label3
;
private
JLabel
chiplabel
,
label1
,
label2
,
label3
;
private
LockButton
but1
,
but2
,
but3
;
private
int
xscale
;
private
int
xscale
;
private
int
yscale
;
private
int
yscale
;
private
class
LockButton
extends
JButton
{
private
static
final
long
serialVersionUID
=
1L
;
private
boolean
clicked
=
false
;
private
boolean
locked
=
false
;
private
int
pin
;
private
int
value
=
0
;
private
static
final
String
BTN_TOOLTIP
=
"Linksklick -> Taster | Rechtsklick -> Schalter"
;
LockButton
(
int
_pin
){
//ImageIcon _iconOn, ImageIcon _iconOff){
pin
=
_pin
;
this
.
setBorderPainted
(
false
);
this
.
setToolTipText
(
BTN_TOOLTIP
);
}
public
boolean
isClicked
()
{
return
clicked
;
}
public
void
setClicked
(
boolean
clicked
)
{
this
.
clicked
=
clicked
;
}
public
boolean
isLocked
()
{
return
locked
;
}
public
void
setLocked
(
boolean
locked
)
{
this
.
locked
=
locked
;
}
@SuppressWarnings
(
"unused"
)
public
int
getValue
()
{
return
value
;
}
public
void
setValue
(
int
value
)
{
this
.
value
=
value
;
lastState
[
pin
]
=
value
;
//TODO: remove when updateModule is updated
pins
.
get
(
pin
).
setValue
(
value
);
pins
.
get
(
pin
).
getValue
();
}
@Override
public
void
setSize
(
int
width
,
int
height
)
{
super
.
setSize
(
width
,
height
);
}
public
void
update
(){
if
(
isClicked
()
||
isLocked
())
{
setIcon
(
iconOn_temp
);
setValue
(
1023
);
}
else
{
setIcon
(
iconOff_temp
);
setValue
(
0
);
}
}
}
public
Button
(
ImageIcon
_icon
,
ImageIcon
_icon1
,
ImageIcon
_icon2
,
int
_xscale
,
int
_yscale
)
{
public
Button
(
ImageIcon
_icon
,
ImageIcon
_icon1
,
ImageIcon
_icon2
,
int
_xscale
,
int
_yscale
)
{
this
.
xscale
=
_xscale
;
this
.
xscale
=
_xscale
;
...
@@ -42,17 +105,20 @@ public class Button extends Modul implements ActionListener {
...
@@ -42,17 +105,20 @@ public class Button extends Modul implements ActionListener {
iconOff_temp
=
iconOff
;
iconOff_temp
=
iconOff
;
iconOn_temp
=
iconOn
;
iconOn_temp
=
iconOn
;
chiplabel
=
new
JLabel
();
chiplabel
=
new
JLabel
();
but1
=
new
JToggleButton
();
but1
=
new
LockButton
(
0
);
//JToggleButton();
but1
.
setActionCommand
(
"0"
);
//but1.setActionCommand("0");
but1
.
addActionListener
(
this
);
//but1.addActionListener(this);
but1
.
addMouseListener
(
this
);
but2
=
new
JToggleButton
();
but2
=
new
LockButton
(
1
);
//JToggleButton();
but2
.
setActionCommand
(
"1"
);
//but2.setActionCommand("1");
but2
.
addActionListener
(
this
);
//but2.addActionListener(this);
but2
.
addMouseListener
(
this
);
but3
=
new
JToggleButton
();
but3
=
new
LockButton
(
2
);
//JToggleButton();
but3
.
setActionCommand
(
"2"
);
//but3.setActionCommand("2");
but3
.
addActionListener
(
this
);
//but3.addActionListener(this);
but3
.
addMouseListener
(
this
);
label1
=
new
JLabel
();
label1
=
new
JLabel
();
label2
=
new
JLabel
();
label2
=
new
JLabel
();
...
@@ -92,7 +158,7 @@ public class Button extends Modul implements ActionListener {
...
@@ -92,7 +158,7 @@ public class Button extends Modul implements ActionListener {
iconOff_temp
.
setImage
(
iconOff
.
getImage
().
getScaledInstance
(((
int
)(
0.0723
*
xscale
)),
((
int
)(
0.0724
*
yscale
)),
Image
.
SCALE_SMOOTH
));
iconOff_temp
.
setImage
(
iconOff
.
getImage
().
getScaledInstance
(((
int
)(
0.0723
*
xscale
)),
((
int
)(
0.0724
*
yscale
)),
Image
.
SCALE_SMOOTH
));
iconOn_temp
.
setImage
(
iconOn
.
getImage
().
getScaledInstance
(((
int
)(
0.0723
*
xscale
)),
((
int
)(
0.0724
*
yscale
)),
Image
.
SCALE_SMOOTH
));
iconOn_temp
.
setImage
(
iconOn
.
getImage
().
getScaledInstance
(((
int
)(
0.0723
*
xscale
)),
((
int
)(
0.0724
*
yscale
)),
Image
.
SCALE_SMOOTH
));
//Abfrage ob der jeweilige Button im moment gedrckt wurde oder nicht und dementsprechend wird das gas gezoomte icon gesetzt
//Abfrage ob der jeweilige Button im moment gedr
�
ckt wurde oder nicht und dementsprechend wird das gas gezoomte icon gesetzt
// if(!but1.isSelected())
// if(!but1.isSelected())
// but1.setIcon(iconOff_temp);
// but1.setIcon(iconOff_temp);
// else
// else
...
@@ -193,4 +259,54 @@ public class Button extends Modul implements ActionListener {
...
@@ -193,4 +259,54 @@ public class Button extends Modul implements ActionListener {
this
.
setPinPos
(
pins
);
this
.
setPinPos
(
pins
);
}
}
@Override
public
void
mouseClicked
(
MouseEvent
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
mouseEntered
(
MouseEvent
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
mouseExited
(
MouseEvent
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
mousePressed
(
MouseEvent
arg0
)
{
if
(!(
arg0
.
getSource
()
instanceof
LockButton
))
{
return
;
}
LockButton
button
=
(
LockButton
)
arg0
.
getSource
();
if
(
arg0
.
getButton
()
==
MouseEvent
.
BUTTON2
||
arg0
.
getButton
()
==
MouseEvent
.
BUTTON3
)
{
//to activate double-Click add arg0.getClickCount()==2 ||
button
.
setLocked
(!
button
.
isLocked
());
button
.
setClicked
(
false
);
}
else
{
//to activate lock with double-Click add: if(arg0.getClickCount()==1) {
if
(!
button
.
isLocked
())
{
button
.
setClicked
(
true
);
}
}
button
.
update
();
}
@Override
public
void
mouseReleased
(
MouseEvent
arg0
)
{
if
(!(
arg0
.
getSource
()
instanceof
LockButton
))
{
return
;
}
LockButton
button
=
(
LockButton
)
arg0
.
getSource
();
button
.
setClicked
(
false
);
button
.
update
();
}
}
}
This diff is collapsed.
Click to expand it.
src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java
+
3
−
0
View file @
fa1c1ae5
...
@@ -39,6 +39,8 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener {
...
@@ -39,6 +39,8 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener {
private
int
xscale
;
private
int
xscale
;
private
int
yscale
;
private
int
yscale
;
private
static
final
String
POTI_TOOLTIP
=
"Slider ziehen oder mit Mausrad verstellen"
;
public
Poti
(
ImageIcon
_icon
,
int
_xscale
,
int
_yscale
)
{
public
Poti
(
ImageIcon
_icon
,
int
_xscale
,
int
_yscale
)
{
this
.
xscale
=
_xscale
;
this
.
xscale
=
_xscale
;
this
.
yscale
=
_yscale
;
this
.
yscale
=
_yscale
;
...
@@ -62,6 +64,7 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener {
...
@@ -62,6 +64,7 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener {
slider
.
setOpaque
(
false
);
slider
.
setOpaque
(
false
);
slider
.
addChangeListener
(
this
);
slider
.
addChangeListener
(
this
);
slider
.
addMouseWheelListener
(
this
);
slider
.
addMouseWheelListener
(
this
);
slider
.
setToolTipText
(
POTI_TOOLTIP
);
sliderPanel
=
new
JPanel
();
sliderPanel
=
new
JPanel
();
sliderPanel
.
add
(
slider
);
sliderPanel
.
add
(
slider
);
sliderPanel
.
setOpaque
(
false
);
sliderPanel
.
setOpaque
(
false
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment