forked from henrikerola/ExpandingTextArea
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Organization and package name for release purposes
- Loading branch information
ilgun
committed
Sep 13, 2017
1 parent
a04a408
commit 31e508c
Showing
12 changed files
with
159 additions
and
159 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
.../expandingtextarea/ExpandingTextArea.java → .../expandingtextarea/ExpandingTextArea.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...client/ui/ExpandingTextAreaConnector.java → ...client/ui/ExpandingTextAreaConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...client/ui/ExpandingTextAreaServerRpc.java → ...client/ui/ExpandingTextAreaServerRpc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...set/client/ui/ExpandingTextAreaState.java → ...set/client/ui/ExpandingTextAreaState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
280 changes: 140 additions & 140 deletions
280
...dgetset/client/ui/VExpandingTextArea.java → ...dgetset/client/ui/VExpandingTextArea.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1,140 @@ | ||
package org.vaadin.hene.expandingtextarea.widgetset.client.ui; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.google.gwt.user.client.Element; | ||
import com.google.gwt.user.client.Event; | ||
import com.google.gwt.user.client.Timer; | ||
import com.vaadin.v7.client.ui.VTextArea; | ||
|
||
/** | ||
* Client side widget which communicates with the server. Messages from the | ||
* server are shown as HTML and mouse clicks are sent to the server. | ||
*/ | ||
public class VExpandingTextArea extends VTextArea { | ||
|
||
/** Set the CSS class name to allow styling. */ | ||
public static final String CLASSNAME = "v-expandingtextarea"; | ||
|
||
private static int REPEAT_INTERVAL = 400; | ||
|
||
private Integer maxRows = null; | ||
|
||
private final HeightObserver heightObserver; | ||
|
||
private boolean appendExtraRow = false; | ||
|
||
public VExpandingTextArea() { | ||
setStyleName(CLASSNAME); | ||
sinkEvents(Event.ONFOCUS | Event.ONFOCUS); | ||
|
||
heightObserver = new HeightObserver(); | ||
} | ||
|
||
@Override | ||
public void onBrowserEvent(Event event) { | ||
super.onBrowserEvent(event); | ||
if (event.getTypeInt() == Event.ONFOCUS) { | ||
heightObserver.scheduleRepeating(REPEAT_INTERVAL); | ||
getElement().addClassName(CLASSNAME + "-focus"); | ||
} else if (event.getTypeInt() == Event.ONBLUR) { | ||
heightObserver.cancel(); | ||
getElement().removeClassName(CLASSNAME + "-focus"); | ||
} | ||
} | ||
|
||
public void checkHeight() { | ||
int origRows = getRows(getElement()); | ||
|
||
// Check if we have to increase textarea's height | ||
int rows = origRows; | ||
rows++; | ||
while ((maxRows == null || rows <= maxRows) | ||
&& getElement().getScrollHeight() > getOffsetHeight()) { | ||
setRows(rows++); | ||
} | ||
|
||
// Check if we can reduce textarea's height | ||
rows = getRows(getElement()); | ||
while (rows > 1) { | ||
setRows(rows - 1); | ||
if (!(getElement().getScrollHeight() > getOffsetHeight())) { | ||
rows -= 1; | ||
continue; | ||
} else { | ||
setRows(rows); | ||
break; | ||
} | ||
} | ||
|
||
int extraRow = appendExtraRow ? 1 : 0; | ||
int updatedRowCount = getRows(getElement()) + extraRow; | ||
// Add stylename if we have reached maximum row number, so we can show a | ||
// scroll bar | ||
if (maxRows != null && updatedRowCount > maxRows) { | ||
addStyleName("max"); | ||
updatedRowCount = updatedRowCount > maxRows ? maxRows | ||
: updatedRowCount; | ||
} else { | ||
removeStyleName("max"); | ||
} | ||
|
||
setRows(updatedRowCount); | ||
|
||
if (origRows != getRows(getElement())) { | ||
for (HeightChangedListener listener : heightChangedListeners) { | ||
listener.heightChanged(getRows(getElement())); | ||
} | ||
} | ||
} | ||
|
||
public void setMaxRows(Integer maxRows) { | ||
this.maxRows = maxRows; | ||
} | ||
|
||
public void setAppendExtraRow(boolean appendExtraRow) { | ||
this.appendExtraRow = appendExtraRow; | ||
} | ||
|
||
public int getRows() { | ||
return getRows(getElement()); | ||
} | ||
|
||
private native int getRows(Element e) | ||
/*-{ | ||
try { | ||
return e.rows; | ||
} catch (e) { | ||
return -1; | ||
} | ||
}-*/; | ||
|
||
private class HeightObserver extends Timer { | ||
|
||
@Override | ||
public void run() { | ||
checkHeight(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onDetach() { | ||
heightObserver.cancel(); | ||
super.onDetach(); | ||
} | ||
|
||
List<HeightChangedListener> heightChangedListeners = new ArrayList<VExpandingTextArea.HeightChangedListener>(); | ||
|
||
public interface HeightChangedListener { | ||
void heightChanged(int newHeight); | ||
} | ||
|
||
public void addHeightChangedListener(HeightChangedListener listener) { | ||
heightChangedListeners.add(listener); | ||
} | ||
|
||
public void removeHeightChangedListener(HeightChangedListener listener) { | ||
heightChangedListeners.remove(listener); | ||
} | ||
} | ||
package org.vaadin.ilgun.expandingtextarea.widgetset.client.ui; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.google.gwt.user.client.Element; | ||
import com.google.gwt.user.client.Event; | ||
import com.google.gwt.user.client.Timer; | ||
import com.vaadin.v7.client.ui.VTextArea; | ||
|
||
/** | ||
* Client side widget which communicates with the server. Messages from the | ||
* server are shown as HTML and mouse clicks are sent to the server. | ||
*/ | ||
public class VExpandingTextArea extends VTextArea { | ||
|
||
/** Set the CSS class name to allow styling. */ | ||
public static final String CLASSNAME = "v-expandingtextarea"; | ||
|
||
private static int REPEAT_INTERVAL = 400; | ||
|
||
private Integer maxRows = null; | ||
|
||
private final HeightObserver heightObserver; | ||
|
||
private boolean appendExtraRow = false; | ||
|
||
public VExpandingTextArea() { | ||
setStyleName(CLASSNAME); | ||
sinkEvents(Event.ONFOCUS | Event.ONFOCUS); | ||
|
||
heightObserver = new HeightObserver(); | ||
} | ||
|
||
@Override | ||
public void onBrowserEvent(Event event) { | ||
super.onBrowserEvent(event); | ||
if (event.getTypeInt() == Event.ONFOCUS) { | ||
heightObserver.scheduleRepeating(REPEAT_INTERVAL); | ||
getElement().addClassName(CLASSNAME + "-focus"); | ||
} else if (event.getTypeInt() == Event.ONBLUR) { | ||
heightObserver.cancel(); | ||
getElement().removeClassName(CLASSNAME + "-focus"); | ||
} | ||
} | ||
|
||
public void checkHeight() { | ||
int origRows = getRows(getElement()); | ||
|
||
// Check if we have to increase textarea's height | ||
int rows = origRows; | ||
rows++; | ||
while ((maxRows == null || rows <= maxRows) | ||
&& getElement().getScrollHeight() > getOffsetHeight()) { | ||
setRows(rows++); | ||
} | ||
|
||
// Check if we can reduce textarea's height | ||
rows = getRows(getElement()); | ||
while (rows > 1) { | ||
setRows(rows - 1); | ||
if (!(getElement().getScrollHeight() > getOffsetHeight())) { | ||
rows -= 1; | ||
continue; | ||
} else { | ||
setRows(rows); | ||
break; | ||
} | ||
} | ||
|
||
int extraRow = appendExtraRow ? 1 : 0; | ||
int updatedRowCount = getRows(getElement()) + extraRow; | ||
// Add stylename if we have reached maximum row number, so we can show a | ||
// scroll bar | ||
if (maxRows != null && updatedRowCount > maxRows) { | ||
addStyleName("max"); | ||
updatedRowCount = updatedRowCount > maxRows ? maxRows | ||
: updatedRowCount; | ||
} else { | ||
removeStyleName("max"); | ||
} | ||
|
||
setRows(updatedRowCount); | ||
|
||
if (origRows != getRows(getElement())) { | ||
for (HeightChangedListener listener : heightChangedListeners) { | ||
listener.heightChanged(getRows(getElement())); | ||
} | ||
} | ||
} | ||
|
||
public void setMaxRows(Integer maxRows) { | ||
this.maxRows = maxRows; | ||
} | ||
|
||
public void setAppendExtraRow(boolean appendExtraRow) { | ||
this.appendExtraRow = appendExtraRow; | ||
} | ||
|
||
public int getRows() { | ||
return getRows(getElement()); | ||
} | ||
|
||
private native int getRows(Element e) | ||
/*-{ | ||
try { | ||
return e.rows; | ||
} catch (e) { | ||
return -1; | ||
} | ||
}-*/; | ||
|
||
private class HeightObserver extends Timer { | ||
|
||
@Override | ||
public void run() { | ||
checkHeight(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onDetach() { | ||
heightObserver.cancel(); | ||
super.onDetach(); | ||
} | ||
|
||
List<HeightChangedListener> heightChangedListeners = new ArrayList<VExpandingTextArea.HeightChangedListener>(); | ||
|
||
public interface HeightChangedListener { | ||
void heightChanged(int newHeight); | ||
} | ||
|
||
public void addHeightChangedListener(HeightChangedListener listener) { | ||
heightChangedListeners.add(listener); | ||
} | ||
|
||
public void removeHeightChangedListener(HeightChangedListener listener) { | ||
heightChangedListeners.remove(listener); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...ingtextarea/demo/ExpandingTextAreaUI.java → ...ingtextarea/demo/ExpandingTextAreaUI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mo/ExpandingTextAreaDemoWidgetset.gwt.xml → ...mo/ExpandingTextAreaDemoWidgetset.gwt.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module> | ||
<inherits name="com.vaadin.DefaultWidgetSet" /> | ||
<inherits name="org.vaadin.hene.expandingtextarea.widgetset.ExpandingtextareaWidgetset" /> | ||
<inherits name="org.vaadin.ilgun.expandingtextarea.widgetset.ExpandingtextareaWidgetset" /> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters