public class SendPressEnterListener implements KeyListener {
@Override
public void keyPressed(KeyEvent arg0) {
if (arg0.getKeyCode() == 16) {
shiftFLAG = 1;
}
if (shiftFLAG == 0) {
if (arg0.getKeyCode() == KeyEvent.VK_ENTER & writingFLAG == 1) {
sendTextMessage();
TAentered.setText("");
TAentered.setCaretPosition(0);
}
} else if (shiftFLAG == 1) {
if (arg0.getKeyCode() == KeyEvent.VK_ENTER & writingFLAG == 1) {
String s = TAentered.getText() + "\n";
TAentered.setText(s);
}
}
}
@Override
public void keyReleased(KeyEvent arg0) {
if (arg0.getKeyCode() == 16) {
shiftFLAG = 0;
}
}
@Override
public void keyTyped(KeyEvent arg0) {
}
}
public class textlistener implements ActionListener {
public GUI g;
public textlistener(GUI b) {
g = b;
}
@Override
public void actionPerformed(ActionEvent e) {
g.refreshButton();
}
}
public class GUIACTION implements Runnable {
@Override
public void run() {
while (refreshFLAG == 1) {
refreshButton();
testresize();
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
class Surface extends JPanel
implements ActionListener {
private Timer timer;
private int i;
private BufferedImage background;
private Graphics2D work;
private BufferedImage img;
private Image SP1;
private Image SP2;
public Surface() {
initSurface();
initTimer();
}
private void initSurface() {
setBackground(Color.black);
try {
background = ImageIO.read(GUI.class.getResource("/img/physik.jpg"));
img = ImageIO.read(GUI.class.getResource("/img/physik.jpg"));
} catch (Exception e) {
System.out.println("Datei nicht gefunden");
}
work = (Graphics2D) img.getGraphics();
work.drawImage(background, null, 0, 0);
work.setRenderingHint(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
RenderingHints rh
= new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
work.setRenderingHints(rh);
}
private void initTimer() {
timer = new Timer(30, this);
timer.setInitialDelay(190);
timer.start();
}
public void imgflash() {
work.drawImage(background, null, 0, 0);
}
public void render() {
imgflash();
renderConversation();
renderScroll();
}
public void renderScroll()
{
int XOffset =0;
double multi =scrollAlpha;
if(scrollAlpha < 0)
{
multi = (-1)*scrollAlpha;
}
int screenHeight =mPanel.getHeight()-95;
int scrollHeight=screenHeight;
if(lastBlockHeight > screenHeight)
{
double Ueberstand = lastBlockHeight-screenHeight;
double q = (lastBlockHeight /(double)screenHeight);
if (q <1)
{
q =1;
}
scrollHeight =(int) (screenHeight/q);
}
double alphad=multi*114+26;
int alpha = (int)alphad;
Color color = new Color(0,119,255,alpha);
double animatedX = multi*4.0;
int xPosition = (int)Math.round(mPanel.getWidth()-3-animatedX-XOffset);
double Spielraum = mPanel.getHeight()-95-scrollHeight;
double yPositiond = Spielraum*scrollPercent;
double inverty = Spielraum-yPositiond;
int yPosition = (int)inverty+3;
BufferedImage scrollIMG = new BufferedImage(40,screenHeight,BufferedImage.TYPE_INT_ARGB);
Graphics2D scrollG=(Graphics2D)scrollIMG.getGraphics();
scrollG.setColor(color);
scrollG.fillRoundRect(1, 1, 10, scrollHeight, 5, 5);
BufferedImage scrollBack = new BufferedImage(40,screenHeight,BufferedImage.TYPE_INT_ARGB);
Graphics2D BackG=(Graphics2D)scrollBack.getGraphics();
RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
qualityHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
qualityHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
BackG.setRenderingHints(qualityHints);
double alphaBackd = multi*80+20;
Color WhiteBack = new Color (0,119,255,60);
BackG.setColor(WhiteBack);
BackG.fillRoundRect(0, 0, 11, screenHeight, 10, 10);
work.drawImage(scrollBack, null, xPosition, 2);
work.drawImage(scrollIMG, null, xPosition, yPosition);
}
public void renderConversation() {
int Height = (int) (mPanel.getHeight() + scroll);
int ScreenHeight = mPanel.getHeight();
int Width = mPanel.getWidth();
size dim = new size(Width, Height);
int Anzahl = Conversation.getLength();
int x = 0;
int MaximalElements = 100 * MessageBlockID;
int start = 0;
if (Anzahl >= MaximalElements) {
start = Anzahl - MaximalElements+1;
}
int MessageBlockStop = Anzahl;
int fifty = 1;
for (int j = start; j < Anzahl; j++) {
if (Conversation.findID(j).islast()) {
MessageBlockStop = j;
}
if (fifty == MaximalElements) {
MessageBlockStop = j;
}
fifty++;
}
int MaxHeight = 0;
for (int i = start; i < MessageBlockStop; i++) {
MaxHeight = MaxHeight + Conversation.findID(i).getGuiE().getHeight(dim);
}
lastBlockHeight=MaxHeight;
maxScroll=MaxHeight-ScreenHeight+100;
int notvisible = MaxHeight - Height;
if (Height > MaxHeight) {
notvisible = 0;
}
int MessageScreen = ScreenHeight -120;
if(MaxHeight > MessageScreen)
{
scrollLock =0;
}
else
{
scrollLock =1;
}
scrollPercent = scroll/maxScroll;
int startID = 0;
int effektivHeight = 0;
int iterationHeight = 0;
int Plus = 0;
for (int i = start; i < Anzahl; i++) {
Plus = Conversation.findID(i).getGuiE().getHeight(dim);
if (iterationHeight + Plus > notvisible) {
startID = i;
effektivHeight = MaxHeight - iterationHeight;
break;
}
iterationHeight = iterationHeight + Plus;
}
lastStartID = startID;
int inStopID =Anzahl;
int inStopfound=0;
int stopID = Anzahl;
int renderAnzahl;
int off = effektivHeight-Height;
int toFILL = off + ScreenHeight ;
int toFillScreen = toFILL +80;
int screenfilled = 0;
for (int k = startID; k < Anzahl; k++) {
Plus = Conversation.findID(k).getGuiE().getHeight(dim);
screenfilled = screenfilled + Plus;
if (screenfilled > toFILL) {
if(inStopfound==0)
{
inStopID = k;
inStopfound =1;
}
}
if(screenfilled > toFillScreen)
{
stopID = k;
break;
}
}
renderAnzahl = stopID-startID;
lastinStopID=inStopID;
lastStopID = stopID;
int renderheight = effektivHeight;
int startheight = Height - renderheight;
iterationHeight = startheight;
int offset = 120;
iterationHeight = iterationHeight - offset;
String thisuser = username.getText();
BufferedImage ChatImg = new BufferedImage(mPanel.getWidth(),ScreenHeight-offset+35,BufferedImage.TYPE_INT_ARGB);
Graphics2D ChatG = (Graphics2D)ChatImg.getGraphics();
for (int i = startID; i < stopID; i++)
{
Element e = Conversation.findID(i);
GuiElement GuiE = e.getGuiE();
BufferedImage iterationImage = GuiE.getImage(0, 0);
String MessageUsername = GuiE.getUsername();
int Modus = GuiE.getModus();
if (Modus == 1)
{
double multi = scrollAlpha;
int leftoffset =(int) (40-8);
int Startpoint = Width - GuiE.getWidth(dim) - leftoffset;
ChatG.drawImage(iterationImage, null, Startpoint, iterationHeight);
iterationHeight = iterationHeight + Conversation.findID(i).getGuiE().getHeight(dim);
} else {
ChatG.drawImage(iterationImage, null, 0, iterationHeight);
iterationHeight = iterationHeight + Conversation.findID(i).getGuiE().getHeight(dim);
}
}
work.drawImage(ChatImg, null, 0, 0);
}
private void doDrawing(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Dimension size = getSize();
render();
g2.drawImage(img, null, 0, 0);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}
@Override
public void actionPerformed(ActionEvent e) {
repaint();
}
}
}