Skip to content

Commit

Permalink
added APIs to change font size dynamically and an applet param to set…
Browse files Browse the repository at this point in the history
… font size.

      <applet code="com.jcraft.jcterm.JCTermApplet.class"
              width="1024" height="768">
        <param name="jcterm.font_size" value="20">
      </applet>
  • Loading branch information
ymnk committed Mar 22, 2012
1 parent 7b2c0b2 commit 4e409d1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/jcraft/jcterm/Frame.java
Expand Up @@ -30,5 +30,8 @@ interface Frame {
void openFrame(int mode);
void setTitle(String name);
void setVisible(boolean visible);
void setSize(int w, int h);
int getWidth();
int getHeight();
void dispose();
}
36 changes: 20 additions & 16 deletions src/main/java/com/jcraft/jcterm/JCTermApplet.java
Expand Up @@ -31,6 +31,8 @@
public class JCTermApplet extends JApplet {
JDesktopPane desktop=new JDesktopPane();

private int font_size = 14;

public void init(){
JCTermSwingFrame.resetCounter();
String s;
Expand All @@ -40,6 +42,16 @@ public void init(){
JCTermSwingFrame.setDestinations(s);
}

s = getParameter("jcterm.font_size");
if(s!=null){
try{
font_size = Integer.parseInt(s);
}
catch(NumberFormatException e){
System.err.println("jcterm.font_size: "+s);
}
}

setVisible(true);

if(Toolkit.getDefaultToolkit()
Expand Down Expand Up @@ -90,22 +102,6 @@ public void openFrame(int mode){

desktop.add(frame);

term.setVisible(true);
frame.setVisible(true);

frame.setResizable(true);
{
int foo=term.getTermWidth();
int bar=term.getTermHeight();
foo+=(frame.getWidth()-frame.getContentPane().getWidth());
bar+=(frame.getHeight()-frame.getContentPane().getHeight());
frame.setSize(foo, bar);
}
frame.setResizable(false);

frame.setLocation((getWidth()-frame.getWidth())/2,
(getHeight()-frame.getHeight())/2);

ComponentAdapter l = new ComponentAdapter(){
public void componentResized(ComponentEvent e){
Component c = e.getComponent();
Expand All @@ -122,9 +118,17 @@ public void componentResized(ComponentEvent e){
frame.addComponentListener(l);
addKeyListener(term);

term.setVisible(true);
frame.setVisible(true);

frame.setResizable(true);
frame.setMaximizable(true);

jctermsf.setFontSize(font_size);

frame.setLocation((getWidth()-frame.getWidth())/2,
(getHeight()-frame.getHeight())/2);

jctermsf.openSession();
}

Expand Down
22 changes: 12 additions & 10 deletions src/main/java/com/jcraft/jcterm/JCTermSwing.java
Expand Up @@ -80,15 +80,6 @@ public JCTermSwing(){

setFont("Monospaced-14");

background=new BufferedImage(char_width, char_height,
BufferedImage.TYPE_INT_RGB);
{
Graphics2D foog=(Graphics2D)(background.getGraphics());
foog.setColor(getBackGround());
foog.fillRect(0, 0, char_width, char_height);
foog.dispose();
}

setSize(getTermWidth(), getTermHeight());

if(splash!=null)
Expand All @@ -108,7 +99,7 @@ public JCTermSwing(){
// setOpaque(true);
}

private void setFont(String fname){
void setFont(String fname){
font=java.awt.Font.decode(fname);
BufferedImage img=new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics=(Graphics2D)(img.getGraphics());
Expand All @@ -130,8 +121,18 @@ private void setFont(String fname){
char_height=(int)(fo.getHeight())+(line_space*2);
descent+=line_space;
}

img.flush();
graphics.dispose();

background=new BufferedImage(char_width, char_height,
BufferedImage.TYPE_INT_RGB);
{
Graphics2D foog=(Graphics2D)(background.getGraphics());
foog.setColor(getBackGround());
foog.fillRect(0, 0, char_width, char_height);
foog.dispose();
}
}

public void setSize(int w, int h){
Expand All @@ -154,6 +155,7 @@ public void setSize(int w, int h){
graphics.setFont(font);

clear_area(0, 0, w, h);
redraw(0, 0, w, h);

if(imgOrg!=null){
Shape clip=graphics.getClip();
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/jcraft/jcterm/JCTermSwingFrame.java
Expand Up @@ -75,6 +75,8 @@ static synchronized void setDestinations(String _destinations){

private Frame frame = this;

private int font_size = 14;

public boolean getCloseOnExit(){
return close_on_exit;
}
Expand Down Expand Up @@ -120,6 +122,8 @@ public void componentResized(ComponentEvent e){
};
addComponentListener(l);

setFontSize(font_size);

openSession();
}

Expand Down Expand Up @@ -461,6 +465,14 @@ public void setCompression(int compression){
}
}

public void setFontSize(int size){
this.font_size = size;
int mwidth = frame.getWidth()-term.getTermWidth();
int mheight = frame.getHeight()-term.getTermHeight();
term.setFont("Monospaced-"+size);
frame.setSize(mwidth+term.getTermWidth(), mheight+term.getTermHeight());
}

public int getCompression(){
return this.compression;
}
Expand Down

0 comments on commit 4e409d1

Please sign in to comment.