📄 swingraplablock.java
字号:
/*--------------------------------------------------------------------------*
| Copyright (C) 2006 Gereon Fassbender, Christopher Kohlhaas |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by the |
| Free Software Foundation. A copy of the license has been included with |
| these distribution in the COPYING file, if not go to www.fsf.org |
| |
| As a special exception, you are granted the permissions to link this |
| program with every library, which license fulfills the Open Source |
| Definition as published by the Open Source Initiative (OSI). |
*--------------------------------------------------------------------------*/
package org.rapla.plugin.abstractcalendar;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Paint;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.JComponent;
import javax.swing.event.MouseInputListener;
import org.rapla.components.calendarview.swing.SwingBlock;
import org.rapla.components.util.SmallIntMap;
import org.rapla.entities.Named;
import org.rapla.entities.domain.Allocatable;
import org.rapla.entities.domain.Repeating;
import org.rapla.framework.RaplaContextException;
import org.rapla.gui.InfoFactory;
import org.rapla.gui.toolkit.RaplaColorList;
class SwingRaplaBlock extends AbstractRaplaBlock implements SwingBlock
{
private static BufferedImage exceptionImage;
RaplaBlockView m_view = new RaplaBlockView();
private BufferedImage getExceptionImage()
{
if ( exceptionImage != null )
return exceptionImage;
Image image = getContext().getBuildContext().getExceptionBackgroundIcon().getImage();
MediaTracker m = new MediaTracker( m_view );
m.addImage( image, 0 );
try
{
m.waitForID( 0 );
}
catch ( InterruptedException ex )
{
}
exceptionImage = new BufferedImage( image.getWidth( null ), image.getHeight( null ),
BufferedImage.TYPE_INT_ARGB );
Graphics g = exceptionImage.getGraphics();
g.drawImage( image, 0, 0, null );
return exceptionImage;
}
public Component getView()
{
return m_view;
}
public boolean isException()
{
Repeating repeating = getAppointment().getRepeating();
return repeating != null && repeating.isException( getStart().getTime() );
}
static Color TRANS = new Color( 100, 100, 100, 100 );
public void paintDragging( Graphics g, int width, int height )
{
g.setColor( TRANS );
m_view.paint( g, width, height );
g.setColor( LINECOLOR_ACTIVE );
g.drawRoundRect( 0, 0, width, height, 5, 5 );
}
static Font FONT_TITLE = new Font( "SansSerif", Font.BOLD, 12 );
static Font FONT_SMALL_TITLE = new Font( "SansSerif", Font.PLAIN, 12 );
static Font FONT_INVISIBLE = new Font( "SansSerif", Font.PLAIN, 9 );
static Font FONT_RESOURCE = new Font( "SansSerif", Font.PLAIN, 12 );
static Font FONT_PERSON = new Font( "SansSerif", Font.ITALIC, 12 );
static String FOREGROUND_COLOR = RaplaColorList.getHexForColor( Color.black );
static SmallIntMap alphaMap = new SmallIntMap();
private static Color LINECOLOR_INACTIVE = Color.darkGray;
private static Color LINECOLOR_ACTIVE = new Color( 255, 90, 10 );
private static Color LINECOLOR_SAME_RESERVATION = new Color( 180, 20, 120 );
// The Linecolor is not static because it can be changed depending on the mouse move
private Color linecolor = LINECOLOR_INACTIVE;
class RaplaBlockView extends JComponent implements MouseInputListener
{
private static final long serialVersionUID = 1L;
RaplaBlockView()
{
javax.swing.ToolTipManager.sharedInstance().registerComponent( this );
addMouseListener( this );
}
public String getName( Named named )
{
return SwingRaplaBlock.this.getName( named );
}
public String getToolTipText( MouseEvent evt )
{
String text = "";
if ( getContext().isAnonymous() )
{
text = getI18n().getString( "not_visible.help" );
}
else if ( !getContext().isEventSelected() )
{
text = getI18n().getString( "not_selected.help" );
}
else
{
try
{
InfoFactory infoFactory = (InfoFactory) getBuildContext().getServiceManager()
.lookup( InfoFactory.ROLE );
text = infoFactory.getToolTip( getAppointment(), false );
}
catch ( RaplaContextException ex )
{
}
}
return "<html>" + text + "</html>";
}
private Color adjustColor( String org, int alpha )
{
Map colorMap = (Map) alphaMap.get( alpha );
if ( colorMap == null )
{
colorMap = new HashMap();
alphaMap.put( alpha, colorMap );
}
Color color = (Color) colorMap.get( org );
if ( color == null )
{
Color or;
try
{
or = RaplaColorList.getColorForHex( org );
}
catch ( NumberFormatException nf )
{
or = RaplaColorList.getColorForHex( "#FFFFFF" );
}
color = new Color( or.getRed(), or.getGreen(), or.getBlue(), alpha );
colorMap.put( org, color );
}
return color;
}
public void paint( Graphics g )
{
Dimension dim = getSize();
paint( g, dim.width, dim.height );
}
public void paint( Graphics g, int width, int height )
{
int alpha = g.getColor().getAlpha();
if ( !getContext().isEventSelected() )
{
alpha = 80;
paintBackground( g, width, height, alpha );
}
else
{
paintBackground( g, width, height, alpha );
}
//boolean isException = getAppointment().getRepeating().isException(getStart().getTime());
Color fg = adjustColor( FOREGROUND_COLOR, alpha ); //(isException() ? Color.white : Color.black);
g.setColor( fg );
if ( getAppointment().getRepeating() != null && getBuildContext().isRepeatingVisible() )
{
if ( !getContext().isAnonymous() && getContext().isEventSelected() && !isException() )
{
getBuildContext().getRepeatingIcon().paintIcon( this, g, width - 17, 0 );
}
/*
if ( getBuildContext().isTimeVisible() )
g.clipRect(0,0, width -17, height);
*/
}
// y will store the y-position of the carret
int y = -2;
// Draw the Reservationname
String timeString = getTimeString();
if ( timeString != null )
{
g.setFont( FONT_SMALL_TITLE );
y = drawString( g, timeString, y, 2, false ) - 1;
}
else
{
g.setFont( FONT_TITLE );
}
if ( getContext().isAnonymous() )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -