adding events to random buttons of the keyboard - random

Hello guys i really need your help . I want to make some program in javafx so i need to add listener to random generated button on the keyboard. For example :
i don't want to add some action if user type enter but i want to add action to some random button and nobody would know which is that button . so the user need to click every single button on the keyboard to find out which is that button.How would he knows that this is the correct button ? - > well the program will be executed , when he click on the wrong button -> nothing will happen.

Try something like this:
private void handleKeyPress(KeyEvent ke) {
String text = ke.getText();
KeyCode code = ke.getCode();
if ( ke.isControlDown() || ke.isMetaDown() ) {
//DO something for example
}
}

Related

How could I go about disabling the enter key whilst inside th tags for ckeditor 4?

Whenever a user creates a table in ckeditor 4 and presses the enter key whilst inside a table header (th) it creates a new paragraph. A paragraph inside a th is invalid HTML. Ideally I'd like to disable the enter key whenever the cursor is inside a th.
I'm aware of the enterMode config (changing it to a br or a div instead of a paragraph when enter is pressed) but that doesn't really solve the problem.
I guess I need to hook into the keypress event and then check which element type is the parent of the element in which the cursor is residing? But I'm not sure how to do that.
There is a similar question here but I'm specifically looking to disable the enter key in a particular scenario not just entirely. ckeditor turn off enter key
Any help appreciated, thanks.
I've figured this out, seems to work as I desired:
CKEDITOR.instances.editor1.on('key', function(event) {
var enterKeyPressed = event.data.keyCode === 13;
var isTH = CKEDITOR.instances.editor1.getSelection().getStartElement().$.nodeName === 'TH';
var parentisTH = CKEDITOR.instances.editor1.getSelection().getStartElement().$.parentNode.nodeName === 'TH';
if(enterKeyPressed && isTH || enterKeyPressed && parentisTH) {
event.cancel();
}
});

RadioButton isChecked control state android

Here is the case : i have 4 radioButtons that are not members of a radioGroup. Thats because RadioGroup places children in vertical order by default and cannot place them relative to each other.Right now , i am check all the radioButtons. What i want to achieve is to control their checked state , so that when one is checked(true) the others checked state is set automatically to false. There widgets are independent layout elements , so i guess i have to find a way to group them all together. I tried it by coding 4 RadioButton variables with a simple if..else if function using isChecked and setChecked built-in methods. Then i tried grouping them in an Radiobutton[] array and looping to the array.length with a switch-case loop. Nothing works.
Stack for 2 days now. Any help appreciated.
Thanks for reply , i explain further. I have 4 imageViews and 4 radioButtons exactly below each one , in a RelativeLayout parent , so that the user can make a choise which image he prefers. The imageViews are not vertically placed , so are the radioButtons. Thats why i dont want to use radioGroup. I could use LinearLayout and place imageViews in vertical orientation and have the radioButtons in a group just aside them. Every radioButton checked state is false by default and when i check it , becomes true. The problem is that i can check all of the radioButtons . What i want is when i select one RadioButton , the others are automatically unchecked , so that only one may be checked at any time.
Here is the snippet:
private RadioButton rbtnWater;
private RadioButton rbtnRoad;
private RadioButton rbtnBoy;
private RadioButton rbtnLeft;
rbtnWater = (RadioButton) findViewById(R.id.rbtnWater);
rbtnRoad = (RadioButton) findViewById(R.id.rbtnRoad);
rbtnBoy = (RadioButton)findViewById(R.id.rbtnBoy);
rbtnLeft = (RadioButton) findViewById(R.id.rbtnLeft)
//method called at onClick attribute (XML)
public void checkState(View v) {
if (rbtnWater.isChecked()) {
rbtnLeft.setChecked(false);
rbtnBoy.setChecked(false);
rbtnRoad.setChecked(false);
}
else if (rbtnLeft.isChecked()) {
rbtnBoy.setChecked(false);
rbtnWater.setChecked(false);
rbtnRoad.setChecked(false);
}
else if (rbtnBoy.isChecked()) {
rbtnWater.setChecked(false);
rbtnRoad.setChecked(false);
rbtnLeft.setChecked(false);
}
else if (rbtnRoad.isChecked()) {
rbtnWater.setChecked(false);
rbtnBoy.setChecked(false);
rbtnLeft.setChecked(false);
}
}
It not really clear what is not working, please add details
That being said I suggest you change the technique and use a RadioGroup anyway, just extend it and modify to what you need or take it's source code from AOSP and instead of having it extend a LinearLayout you can extend something else you would rather work with

Outlook 2013 Addin: Change Ribbon Button Image on click of button using c#

I have created Ribbon button for Outlook 2013 using c#.
And i have also set image for the ribbon.
Now on click of Ribbon button i want to change Ribbon Image.
Is it possible to achieve this using c#.?
Not sure how exactly you want it to work, but this could do the trick.
bool callback {get;set}
public Bitmap GetImage(IRibbonControl control)
{
switch (control.Id)
{
case "FooButtonId":
{
if(callback== true){
callback = false;
return new Bitmap(Properties.Resources.someimage1);
}else
callback =true;
return new Bitmap(Properties.Resources.someimage2);
}
}
}
}
This question is 3 yo but helped me to go further and I want to share this with you.
First, I accomplished this in VB.net so my code will be in VB.net. There are some online tools to convert the code into C#.
Second, I used a Toggle button instead of a Simple button.
Third, I used OnOff as a project setting in order to save the state of the Toggle button.
Step 1: Ribbon.xml file, code to place the toggle button on the ribbon.
Assuming you already have set up the tab and group tags in the file.
<toggleButton id="onoffTBTN" label="ON/OFF" showImage="true" onAction="OnOffToggle" getImage="OnOffImage"/>
Step 2: Ribbon.vb file, code to change the OnOff setting based on the Toggle button status(pressed or not) and forces to invalidate the custom control
Public Sub OnOffToggle(ByVal control As Office.IRibbonControl, ByVal pressed As Boolean)
My.Settings.OnOff = pressed
My.Settings.Save()
myRibbon.InvalidateControl("onoffTBTN")
End Sub
Step 3: Ribbon.vb file, reads the OnOff setting and changes the image accordingly. Have in mind that your images must have been added to your project resources in order to use them at My.Resources.*. I used png files that support transparent pixels. This function is called in two occasions, first when the Outlook starts and second when the toggle button is pressed and specifically with the command myRibbon.InvalidateControl("onoffTBTN").
Public Function OnOffImage(ByVal control As Office.IRibbonControl) As Drawing.Bitmap
Dim onoff As Boolean = My.Settings.OnOff
Select Case control.Id
Case "onoffTBTN"
If onoff = True Then
Return New Drawing.Bitmap(My.Resources._on)
Else
Return New Drawing.Bitmap(My.Resources.off)
End If
End Select
End Function
The only weird behaviour is when the OnOff setting has been set to TRUE. The correct image is displayed but the Toggle button looks unpressed. You have to click twice in order to set the OnOff setting to False.

Programmatically select and clear selection on an ADF DVT piegraph

I am using a pieGraph and doing some page interactions based on clicking on the pie-graph. These work just fine.
<dvt:pieGraph id="graph1" tabularData="#{dc.bean.tabularData}" dataSelection="single"
selectionListener="#{dc.bean.transfersGraphSelectionListener}"/>
However I am not able to support the following use cases
Clicking outside the graph(or clicking a selected data set again) should cause the pie-graph to lose its selection.
Having a clear button on the page which forces the graph to lose its current selection.
Programmatically select one of the data sets in the graph
I checked the UIGraph API but couldn't find much information.
Any hints would be really helpful.
please add the right code to your original post. this is what your code look like
transfersGraphSelectionListener(SelectionEvent selectionEvent){
Set<GraphSelection> selectionSet = selectionEvent.getGraphSelection();
for (GraphSelection selection : selectionSet) {
if (selection instanceof DataSelection) {
DataSelection ds = (DataSelection) selection;
Set seriesKeySet = ds.getSeriesKey().keySet();
for (Object key : seriesKeySet) {
Object selectedKey = ds.getSeriesKey().get((String) key))
}
Looks like something is missing!

GUI update issue in J2ME

Let's say I have two forms: form1 and form2.
After pressing a NEXT_COMMAND in form1, I need to change the value of the gauge in form2 and then show form2. Thus:
public void commandAction(Command command, Displayable displayable) {
....
else if (displayable == form1) {
if (command == NEXT_COMMAND) {
form2_gauge.setValue(value);
display.setCurrent(form2);
}
....
}
....
However, this doesn't work as I expected it to. It doesn't change a thing at first. On the other hand, if I go back from form2 to form1 and then again from form1 to form2 it would work.
I can't figure it out myself. I'd be enormously grateful of any possible help.
Thanks!
It seems to me that form2.gauge isn't correct here. You have to save the Gauge object like this:
Gauge form2_gauge([...]);
form2.append(form2_gauge);
Then your code would be:
[...]
form2_gauge.setValue(value);
display.setCurrent(form2);
[...]
Have you tried another sequence? Like this:
display.setCurrent(form2);
form2_gauge.setValue(value);
I don't think it would change anything, but may make it work.

Resources